class_EmailValidatorFilter.php

Go to the documentation of this file.
00001 <?php
00027 class EmailValidatorFilter extends BaseFilter implements Filterable {
00033         protected function __construct () {
00034                 // Call parent constructor
00035                 parent::__construct(__CLASS__);
00036         }
00037 
00043         public final static function createEmailValidatorFilter () {
00044                 // Get a new instance
00045                 $filterInstance = new EmailValidatorFilter();
00046 
00047                 // Return the instance
00048                 return $filterInstance;
00049         }
00050 
00058         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
00059                 // Get Email from request
00060                 $email = $requestInstance->getRequestElement('email');
00061 
00062                 // Is the Email set?
00063                 if ((is_null($email)) || ($this->getConfigInstance()->readConfig('register_email_unique') === "Y")) {
00064                         // Try it again
00065                         $email1 = $requestInstance->getRequestElement('email1');
00066                         $email2 = $requestInstance->getRequestElement('email2');
00067 
00068                         // Is the email still not set?
00069                         if ((is_null($email1)) || (is_null($email2))) {
00070                                 // Not found in form so stop the filtering process
00071                                 $requestInstance->requestIsValid(false);
00072 
00073                                 // Add a message to the response
00074                                 $responseInstance->addFatalMessage('email_unset');
00075 
00076                                 // Abort here
00077                                 return false;
00078                         } elseif ((empty($email1)) || (empty($email2))) {
00079                                 // Email is empty
00080                                 $requestInstance->requestIsValid(false);
00081 
00082                                 // Is the email empty?
00083                                 if (empty($email1)) {
00084                                         // Add a message to the response
00085                                         $responseInstance->addFatalMessage('email1_empty');
00086                                 } // END - if
00087 
00088                                 // Is the confirmation empty?
00089                                 if (empty($email2)) {
00090                                         // Add a message to the response
00091                                         $responseInstance->addFatalMessage('email2_empty');
00092                                 } // END - if
00093 
00094                                 // Abort here
00095                                 return false;
00096                         } elseif ($this->ifEmailIsTaken($email1)) {
00097                                 // Email is already taken
00098                                 $requestInstance->requestIsValid(false);
00099 
00100                                 // Add a message to the response
00101                                 $responseInstance->addFatalMessage('email_taken');
00102 
00103                                 // Abort here
00104                                 return false;
00105                         } elseif ($email1 != $email2) {
00106                                 // Emails didn't match
00107                                 $requestInstance->requestIsValid(false);
00108 
00109                                 // Add a message to the response
00110                                 $responseInstance->addFatalMessage('emails_mismatch');
00111 
00112                                 // Abort here
00113                                 return false;
00114                         } // END - elseif
00115                 } elseif (empty($email)) {
00116                         // Empty field!
00117                         $requestInstance->requestIsValid(false);
00118 
00119                         // Add a message to the response
00120                         $responseInstance->addFatalMessage('email_empty');
00121 
00122                         // Abort here
00123                         return false;
00124                 } // END - elseif
00125         }
00126 
00133         private function ifEmailIsTaken ($email) {
00134                 // Default is already taken
00135                 $alreadyTaken = true;
00136 
00137                 // Initialize instance
00138                 $userInstance = null;
00139 
00140                 // Get a registry instance
00141                 $registry = Registry::getRegistry();
00142 
00143                 // Is the user already there?
00144                 if ($registry->instanceExists('user')) {
00145                         // Use the instance for checking for the email
00146                         $userInstance = $registry->getInstance('user');
00147                         $userInstance->setEmailAddress($email);
00148                 } else {
00149                         // If this instance is created then the username *does* exist
00150                         $userInstance = call_user_func_array(array($this->getConfigInstance()->readConfig('user_class'), 'createMemberByEmail'), array($email));
00151 
00152                         // Remember this user instance in our registry for later usage
00153                         $registry->addInstance('user', $userInstance);
00154                 }
00155 
00156                 // Does the email exist?
00157                 if ($userInstance->ifEmailAddressExists() === false) {
00158                         // This email has not being used yet
00159                         $alreadyTaken = false;
00160                 }
00161 
00162                 // Return the result
00163                 return $alreadyTaken;
00164         }
00165 }
00166 
00167 // [EOF]
00168 ?>

Generated on Mon Dec 8 01:06:45 2008 for Ship-Simulator by  doxygen 1.5.6