Validate login data only of there are no other errors
This commit is contained in:
parent
1d58a83d8e
commit
dca062e4e2
@ -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,12 +37,14 @@ class LoginForm extends Model
|
|||||||
*/
|
*/
|
||||||
public function validatePassword()
|
public function validatePassword()
|
||||||
{
|
{
|
||||||
|
if (!$this->hasErrors()) {
|
||||||
$user = $this->getUser();
|
$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.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs in a user using the provided username and password.
|
* Logs in a user using the provided username and password.
|
||||||
|
Loading…
Reference in New Issue
Block a user