diff options
| author | Patrick Seeger <pseeger@ccwn.org> | 2012-04-13 23:11:05 +0200 |
|---|---|---|
| committer | Patrick Seeger <pseeger@ccwn.org> | 2012-04-13 23:11:05 +0200 |
| commit | 341cc4dd9c53ffbfb863e026dd58549c1082c7a7 (patch) | |
| tree | 1bbbed20313bafb9b063b6b4d894fe580d8b000f /framework/gii/models/LoginForm.php | |
Diffstat (limited to 'framework/gii/models/LoginForm.php')
| -rw-r--r-- | framework/gii/models/LoginForm.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/framework/gii/models/LoginForm.php b/framework/gii/models/LoginForm.php new file mode 100644 index 0000000..f4b838c --- /dev/null +++ b/framework/gii/models/LoginForm.php @@ -0,0 +1,49 @@ +<?php + +Yii::import('gii.components.UserIdentity'); + +class LoginForm extends CFormModel +{ + public $password; + + private $_identity; + + public function rules() + { + return array( + array('password', 'required'), + array('password', 'authenticate'), + ); + } + + /** + * Authenticates the password. + * This is the 'authenticate' validator as declared in rules(). + */ + public function authenticate($attribute,$params) + { + $this->_identity=new UserIdentity('yiier',$this->password); + if(!$this->_identity->authenticate()) + $this->addError('password','Incorrect password.'); + } + + /** + * Logs in the user using the given password in the model. + * @return boolean whether login is successful + */ + public function login() + { + if($this->_identity===null) + { + $this->_identity=new UserIdentity('yiier',$this->password); + $this->_identity->authenticate(); + } + if($this->_identity->errorCode===UserIdentity::ERROR_NONE) + { + Yii::app()->user->login($this->_identity); + return true; + } + else + return false; + } +} |
