Guest User

Untitled

a guest
Jan 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.21 KB | None | 0 0
  1. <?php
  2.  
  3. class ResendActivationForm extends CFormModel {
  4.  
  5.     public $username;
  6.  
  7.     /**
  8.      * Declares the validation rules.
  9.      * The rules state that username and password are required,
  10.      * and password needs to be authenticated.
  11.      */
  12.     public function rules() {
  13.         return array(
  14.             // username and password are required
  15.             array('username', 'required'),
  16.             array('username', 'length', 'min' => 6, 'max' => 32),
  17.             //user alpha numeric
  18.             array('username', 'match', 'pattern' => '/^[a-z]+([a-z0-9])+$/'),
  19.             //username must exist
  20.             array('username', 'exist', 'className' => 'User', 'attributeName' => 'username'),
  21.             array('username', 'checkActive'),
  22.            
  23.         );
  24.     }
  25.  
  26.     public function checkActive($attribute, $params) {
  27.         if (!$this->hasErrors()) {  
  28.             $user = User::model()->findByAttributes(array('username' => $this->username));
  29.  
  30.             if ($user->status == 1)
  31.                 $this->addError("username", "Your account is already active.");
  32.         }
  33.     }
  34.  
  35. }
  36.  
  37. ?>
  38.  
  39.  
  40. <?php
  41. class ForgotPasswordForm extends CFormModel {
  42.  
  43.     public $username;
  44.  
  45.     /**
  46.      * Declares the validation rules.
  47.      * The rules state that username and password are required,
  48.      * and password needs to be authenticated.
  49.      */
  50.     public function rules() {
  51.         return array(
  52.             // username and password are required
  53.             array('username', 'required'),
  54.             array('username', 'length', 'min' => 6, 'max' => 32),
  55.             //user alpha numeric
  56.             array('username', 'match', 'pattern' => '/^[a-z]+([a-z0-9])+$/'),
  57.             //username must exist
  58.             array('username', 'exist', 'className' => 'User', 'attributeName' => 'username'),
  59.             array('username', 'checkActive'),
  60.         );
  61.     }
  62.  
  63.     public function checkActive($attribute, $params) {
  64.         if (!$this->hasErrors()) {  
  65.             $user = User::model()->findByAttributes(array('username' => $this->username));
  66.  
  67.             if ($user->status !== 1)
  68.                 $this->addError("username", "Your account is not activate. Please activate first.");
  69.         }
  70.     }
  71.  
  72. }
  73. ?>
Add Comment
Please, Sign In to add comment