Registry introduces, comments fixed ;)
[shipsimu.git] / inc / classes / main / filter / validator / class_EmailValidatorFilter.php
index 4b982b04b9b0b5aa30f0e429bb672875b33782da..a2f5628efc46c863d3d7f0c990cbd82728245ede 100644 (file)
@@ -26,7 +26,7 @@
  */
 class EmailValidatorFilter extends BaseFrameworkSystem implements Filterable {
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
@@ -128,13 +128,34 @@ class EmailValidatorFilter extends BaseFrameworkSystem implements Filterable {
        /**
         * Check wether the email as already been taken
         *
-        * @param       $email          Email to check for existence
+        * @param       $email                  Email to check for existence
         * @return      $alreadyTaken   Wether the email has been taken
         */
        private function ifEmailIsTaken ($email) {
                // Default is already taken
                $alreadyTaken = true;
-               $this->partialStub(sprintf("Email: %s", $email));
+
+               // Get a registry instance
+               $registry = Registry::getInstance();
+
+               // Is the user already there?
+               if ($registry->keyExists('userInstance')) {
+                       // Use the instance for checking for the email
+                       $userInstance = $registry->getInstance('userInstance');
+                       $userInstance->setEmailAddress($email);
+               } else {
+                       // If this instance is created then the username *does* exist
+                       $userInstance = User::createUserByEmail($userName);
+
+                       // Remember this user instance in our registry for later usage
+                       $registry->addInstance('userInstance', $userInstance);
+               }
+
+               // Does the email exist?
+               if (!$userInstance->ifEmailAddressExists()) {
+                       // This email has not being used yet
+                       $alreadyTaken = false;
+               }
 
                // Return the result
                return $alreadyTaken;