Validate login data only of there are no other errors

This commit is contained in:
Alexander Makarov
2014-02-21 00:57:29 +04:00
parent 46ca87a41a
commit a687e6f58c
2 changed files with 14 additions and 10 deletions

View File

@ -23,10 +23,10 @@ class LoginForm extends Model
return [
// username and password are both required
[['username', 'password'], 'required'],
// password is validated by validatePassword()
['password', 'validatePassword'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
@ -36,9 +36,11 @@ class LoginForm extends Model
*/
public function validatePassword()
{
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError('password', 'Incorrect username or password.');
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError('password', 'Incorrect username or password.');
}
}
}

View File

@ -24,10 +24,10 @@ class LoginForm extends Model
return [
// username and password are both required
[['username', 'password'], 'required'],
// password is validated by validatePassword()
['password', 'validatePassword'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
@ -37,10 +37,12 @@ class LoginForm extends Model
*/
public function validatePassword()
{
$user = $this->getUser();
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError('password', 'Incorrect username or password.');
if (!$user || !$user->validatePassword($this->password)) {
$this->addError('password', 'Incorrect username or password.');
}
}
}