Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * LoginForm class.
- * LoginForm is the data structure for keeping
- * user login form data. It is used by the 'login' action of 'SiteController'.
- */
- class LoginForm extends CFormModel
- {
- public $leraarCode;
- public $password;
- /**
- * Declares the validation rules.
- * The rules state that username and password are required,
- * and password needs to be authenticated.
- */
- public function rules()
- {
- return array(
- array('leraarCode, password', 'required'),
- array('leraarCode','leraarCode'),
- array('password', 'authenticate'),
- );
- }
- /**
- * Declares attribute labels.
- */
- public function attributeLabels()
- {
- return array(
- 'leraarCode'=>'leraarCode',
- );
- }
- /**
- * Authenticates the password.
- * This is the 'authenticate' validator as declared in rules().
- */
- public function authenticate($attribute,$params)
- {
- if(!$this->hasErrors()) // we only want to authenticate when no input errors
- {
- $identity=new UserIdentity($this->leraarCode,$this->password);
- $identity->authenticate();
- switch($identity->errorCode)
- {
- case UserIdentity::ERROR_NONE:
- Yii::app()->user->login($identity);
- break;
- case UserIdentity::ERROR_USERNAME_INVALID:
- $this->addError('leraarCode','leraarCode is incorrect.');
- break;
- default: // UserIdentity::ERROR_PASSWORD_INVALID
- $this->addError('password','Password is incorrect.');
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement