The errorMessage constant is always empty and not showing any value while errorCode is set at some non-zero value.
The errorMessage constant is always empty and not showing any value while errorCode is set at some non-zero value.
Please check the posting guidelines - http://www.yiiframework.com/forum/index.php/topic/19451-guidelines-for-posting-this-forum/
If you want proper help you need to explain your problem better.
I believe you are thinking on this property - http://www.yiiframework.com/doc/api/1.1/CBaseUserIdentity#errorMessage-detail
If so, that property gets populated by the validation. So you need to check your validation rules.
With the help of Authentication and Authorization guide I have changed my code as below…
Controller…
class AuthController extends CController {
public function actionAjaxLogin() {
if(Yii::app()->request->isAjaxRequest) {
$username = $_POST['username'];
$userpass = $_POST['userpass'];
$identity = new UserIdentity($username, $userpass);
//var_dump($identity->authenticate());
if($identity->authenticate()) {
Yii::app()->user->login($identity);
}
else {
echo $identity->errorMessage;
}
}
else {
echo "No access";
}
}
}
Authentication method of UserIdentity class is changed like this…
public function authenticate() {
$record = GblUserList::model()->findByAttributes(array('username'=>$this->username));
if($record===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if($record->password!==md5($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else {
$this->_id=$record->id;
$this->setState('title', $record->title);
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
Problem is $identity->errorMessage is not printing error message in my controller while there is certain error code.
Problem is $identity->errorMessage is not printing error message
It defaults to empty, you should set it in authenticate() like you do with errorCode.
Guide probably has an error.