]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/filter/validator/class_EmailValidatorFilter.php
NullFilter class added, partial filter for accepting rules added
[shipsimu.git] / inc / classes / main / filter / validator / class_EmailValidatorFilter.php
index 4b982b04b9b0b5aa30f0e429bb672875b33782da..6c4f74bb689497db9e0366c015ba6dbde4972c04 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /**
  * A concrete filter for validating the email address. This filter may intercept
- * the filter chain if no email address is given or if the supplied username has
- * an invalid form. It could also intercept the filter chain if the email
- * address is already used by some one if configuration requires this.
+ * the filter chain if no email address is given or if the supplied email has an
+ * invalid form. It could also intercept the filter chain if the email address
+ * is already used by some one if configuration requires this.
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
@@ -26,7 +26,7 @@
  */
 class EmailValidatorFilter extends BaseFrameworkSystem implements Filterable {
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
@@ -110,6 +110,15 @@ class EmailValidatorFilter extends BaseFrameworkSystem implements Filterable {
                                // Add a message to the response
                                $responseInstance->addFatalMessage('email_taken');
 
+                               // Abort here
+                               return false;
+                       } elseif ($email1 != $email2) {
+                               // Emails didn't match
+                               $requestInstance->requestIsValid(false);
+
+                               // Add a message to the response
+                               $responseInstance->addFatalMessage('emails_mismatch');
+
                                // Abort here
                                return false;
                        } // END - elseif
@@ -128,13 +137,37 @@ 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));
+
+               // Initialize instance
+               $userInstance = null;
+
+               // Get a registry instance
+               $registry = Registry::getRegistry();
+
+               // Is the user already there?
+               if ($registry->instanceExists('user')) {
+                       // Use the instance for checking for the email
+                       $userInstance = $registry->getInstance('user');
+                       $userInstance->setEmailAddress($email);
+               } else {
+                       // If this instance is created then the username *does* exist
+                       $userInstance = User::createUserByEmail($email);
+
+                       // Remember this user instance in our registry for later usage
+                       $registry->addInstance('user', $userInstance);
+               }
+
+               // Does the email exist?
+               if (!$userInstance->ifEmailAddressExists()) {
+                       // This email has not being used yet
+                       $alreadyTaken = false;
+               }
 
                // Return the result
                return $alreadyTaken;