class_EmailChangeFilter.php

Go to the documentation of this file.
00001 <?php
00024 class EmailChangeFilter extends BaseFilter implements Filterable {
00030         protected function __construct () {
00031                 // Call parent constructor
00032                 parent::__construct(__CLASS__);
00033         }
00034 
00040         public final static function createEmailChangeFilter () {
00041                 // Get a new instance
00042                 $filterInstance = new EmailChangeFilter();
00043 
00044                 // Return the instance
00045                 return $filterInstance;
00046         }
00047 
00056         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
00057                 // Get both emails
00058                 $email1 = $requestInstance->getRequestElement('email1');
00059                 $email2 = $requestInstance->getRequestElement('email2');
00060 
00061                 // Is only first email set?
00062                 if ((!empty($email1)) && (empty($email2))) {
00063                         // Request is invalid!
00064                         $requestInstance->requestIsValid(false);
00065 
00066                         // Email 2 is empty
00067                         $responseInstance->addFatalMessage('email2_empty');
00068 
00069                         // Stop processing here
00070                         return false;
00071                 } // END - if
00072 
00073                 // Is only second email set?
00074                 if ((empty($email1)) && (!empty($email2))) {
00075                         // Request is invalid!
00076                         $requestInstance->requestIsValid(false);
00077 
00078                         // Email 1 is empty
00079                         $responseInstance->addFatalMessage('email1_empty');
00080 
00081                         // Stop processing here
00082                         return false;
00083                 } // END - if
00084 
00085                 // Do both match?
00086                 if ($email1 != $email2) {
00087                         // Request is invalid!
00088                         $requestInstance->requestIsValid(false);
00089 
00090                         // Emails are mismatching
00091                         $responseInstance->addFatalMessage('emails_mismatch');
00092 
00093                         // Stop processing here
00094                         return false;
00095                 } // END - if
00096 
00097                 // Are email and confirmation empty?
00098                 if ((empty($email1)) && (empty($email2))) {
00099                         // No email change required!
00100                         return true;
00101                 } // END - if
00102 
00103                 // Now, get a user instance for comparison
00104                 $userInstance = Registry::getRegistry()->getInstance('user');
00105 
00106                 // Get the email field
00107                 $userEmail = $userInstance->getField('email');
00108 
00109                 // Are they different?
00110                 if ($userEmail == $email1) {
00111                         // Nothing has been changed is fine...
00112                         return true;
00113                 } // END - if
00114 
00115                 // Update the "new_email" field
00116                 $this->partialStub("Unfinished part.");
00117         }
00118 }
00119 
00120 // [EOF]
00121 ?>

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