Advertisement
Guest User

loginform.php

a guest
Dec 19th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.44 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * LoginForm class.
  5.  * LoginForm is the data structure for keeping
  6.  * user login form data. It is used by the 'login' action of 'SiteController'.
  7.  */
  8. class LoginForm extends CFormModel
  9. {
  10.     public $leraarCode;
  11.     public $password;
  12.  
  13.     /**
  14.      * Declares the validation rules.
  15.      * The rules state that username and password are required,
  16.      * and password needs to be authenticated.
  17.      */
  18. public function rules()
  19. {
  20.     return array(
  21.         array('leraarCode, password', 'required'),
  22.         array('leraarCode','leraarCode'),
  23.         array('password', 'authenticate'),
  24.     );
  25. }
  26.  
  27.     /**
  28.      * Declares attribute labels.
  29.      */
  30.     public function attributeLabels()
  31.     {
  32.         return array(
  33.             'leraarCode'=>'leraarCode',
  34.         );
  35.     }
  36.  
  37.     /**
  38.      * Authenticates the password.
  39.      * This is the 'authenticate' validator as declared in rules().
  40.      */
  41.     public function authenticate($attribute,$params)
  42.     {
  43.         if(!$this->hasErrors())  // we only want to authenticate when no input errors
  44.         {
  45.             $identity=new UserIdentity($this->leraarCode,$this->password);
  46.             $identity->authenticate();
  47.             switch($identity->errorCode)
  48.             {
  49.                 case UserIdentity::ERROR_NONE:
  50.                     Yii::app()->user->login($identity);
  51.                     break;
  52.                 case UserIdentity::ERROR_USERNAME_INVALID:
  53.                     $this->addError('leraarCode','leraarCode is incorrect.');
  54.                     break;
  55.                 default: // UserIdentity::ERROR_PASSWORD_INVALID
  56.                     $this->addError('password','Password is incorrect.');
  57.                     break;
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement