php yii unable to login using useridentity component -
here authentication controller
class authcontroller extends controller { public function actionlogin() { $model = new loginform; $post = yii::app()->request->getpost('loginform'); // if form submitted if($post) { $identity = new useridentity($post['username'], $post['password']); if($identity->authenticate()) { // loop enters not id echo yii::app()->user->id; echo yii::app()->user->getid(); } else { echo 'failed'; } //exit; } $this->render('login', array('model' => $model)); } } here useridentity.php
class useridentity extends cuseridentity { private $_id; public function authenticate() { $user = schlogins::model()->findbyattributes(array('username' => $this->username)); if(is_null($user)) { $this->errorcode=self::error_username_invalid; } else if($user->password != $this->password) { $this->errorcode=self::error_password_invalid; } else { $this->_id = $user->id; $this->errorcode=self::error_none; } return !$this->errorcode; } public function getid() { return $this->_id; } } in above code having problem in getting user id (i.e) yii::app()->user->getid(); returns nothing , wrong did above code
you creating loginform instance $model never use login. if using standard loginform model interacts useridentity class. should this:
if($post) { $model->attributes = $_post['loginform']; if ($model->validate() && $model->login()) { // loop enters not id echo yii::app()->user->id; echo yii::app()->user->getid(); } else { echo 'failed'; } //exit; } if @ login() function of loginform see calls yii::app()->user->login($this->_identity,$duration); sets yii::app()->user method being skipped.
Comments
Post a Comment