Plz look at below code. This always shows "invalid username" instead of "invalid username/password" even when username is invalid. How do i make it show error as "invalid username".
I am specifically looking at how yii is displaying this as error i.e This thing shows up equivalent to a model error just below the field
sitecontroller
public function actionLogin()
{
$model=new LoginForm;
// collect user input data
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login()){
// loggedin
}
}
// display the login form
$this->render('login',array('model'=>$model));
}
User Identity.php
public function authenticate()
{
$record = User::model()->with('UserType')->findByAttributes(array('username'=>$this->username));
if($record===null){
$this->errorCode = self::ERROR_USERNAME_INVALID;
}
else if($record->password!==sha1($this->password)){
$this->errorCode = self::ERROR_PASSWORD_INVALID;
}
else
{
$this->_id=$record->id;
$this->setState('role', $record->UserType->name);
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
LoginForm.php
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->username,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
return false;
}
This is more or less the default code that yii provides