Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Feb 9th, 2010 | Syntax: None | Size: 1.83 KB | Hits: 30 | Expires: Never
Copy text to clipboard
  1.                         <validator class="string" name="email_specification" provides="email_specification">
  2.                                 <arguments>
  3.                                         <argument>email</argument>
  4.                                 </arguments>
  5.                                 <errors>
  6.                                         <error for="required">You must provide your e-mail address.</error>
  7.                                         <error for="max">Your e-mail address may not exceed 255 characters in length.</error>
  8.                                 </errors>
  9.                                 <ae:parameters>
  10.                                         <ae:parameter name="min">1</ae:parameter>
  11.                                         <ae:parameter name="max">255</ae:parameter>
  12.                                         <ae:parameter name="trim">true</ae:parameter>
  13.                                         <ae:parameter name="export">email</ae:parameter>
  14.                                 </ae:parameters>
  15.                         </validator>
  16.  
  17.                         <validator class="email" name="email_validation" depends="email_specification">
  18.                                 <arguments>
  19.                                         <argument>email</argument>
  20.                                 </arguments>
  21.                                 <errors>
  22.                                         <error>You must provide a valid e-mail address.</error>
  23.                                 </errors>
  24.                         </validator>
  25.  
  26.                         <validator class="not" name="email_usage" depends="email_validation">
  27.                                 <validator class="UserAuthenticationEmailValidator">
  28.                                         <arguments>
  29.                                                 <argument>email</argument>
  30.                                         </arguments>
  31.                                 </validator>
  32.                                 <errors>
  33.                                         <error>That e-mail address is already in use.</error>
  34.                                 </errors>
  35.                         </validator>
  36.  
  37.  
  38.  
  39. <?php
  40.  
  41. /**
  42.  * Validates an account given an e-mail address.
  43.  */
  44. class UserAuthenticationEmailValidator extends AgaviValidator
  45. {
  46.         /**
  47.          * Performs the validation.
  48.          *
  49.          * @return     bool True if the validation succeeds; false otherwise.
  50.          */
  51.         public function validate()
  52.         {
  53.                 $email = $this->getData($this->getArgument());
  54.  
  55.                 $loginsys = $this->getContext()->getModel('LoginSystem', 'UserAuthentication');
  56.                 $account = null;
  57.  
  58.                 try {
  59.                         $account = $loginsys->retrieveAccountByEmail($email);
  60.                 }
  61.                 catch(AgaviException $pare) {
  62.                         $this->throwError();
  63.                         return false;
  64.                 }
  65.  
  66.                 $this->export($account);
  67.                 return true;
  68.         }
  69. }
  70.  
  71. ?>