Commit a687e6f5 by Alexander Makarov

Validate login data only of there are no other errors

parent 46ca87a4
...@@ -23,10 +23,10 @@ class LoginForm extends Model ...@@ -23,10 +23,10 @@ class LoginForm extends Model
return [ return [
// username and password are both required // username and password are both required
[['username', 'password'], 'required'], [['username', 'password'], 'required'],
// password is validated by validatePassword()
['password', 'validatePassword'],
// rememberMe must be a boolean value // rememberMe must be a boolean value
['rememberMe', 'boolean'], ['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
]; ];
} }
...@@ -36,9 +36,11 @@ class LoginForm extends Model ...@@ -36,9 +36,11 @@ class LoginForm extends Model
*/ */
public function validatePassword() public function validatePassword()
{ {
$user = $this->getUser(); if (!$this->hasErrors()) {
if (!$user || !$user->validatePassword($this->password)) { $user = $this->getUser();
$this->addError('password', 'Incorrect username or password.'); if (!$user || !$user->validatePassword($this->password)) {
$this->addError('password', 'Incorrect username or password.');
}
} }
} }
......
...@@ -24,10 +24,10 @@ class LoginForm extends Model ...@@ -24,10 +24,10 @@ class LoginForm extends Model
return [ return [
// username and password are both required // username and password are both required
[['username', 'password'], 'required'], [['username', 'password'], 'required'],
// password is validated by validatePassword()
['password', 'validatePassword'],
// rememberMe must be a boolean value // rememberMe must be a boolean value
['rememberMe', 'boolean'], ['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
]; ];
} }
...@@ -37,10 +37,12 @@ class LoginForm extends Model ...@@ -37,10 +37,12 @@ class LoginForm extends Model
*/ */
public function validatePassword() public function validatePassword()
{ {
$user = $this->getUser(); if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) { if (!$user || !$user->validatePassword($this->password)) {
$this->addError('password', 'Incorrect username or password.'); $this->addError('password', 'Incorrect username or password.');
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment