api-login change creds
This commit is contained in:
parent
932ea915de
commit
ecd32b6529
@ -120,6 +120,17 @@ class User extends ActiveRecord implements IdentityInterface, UserRbacInterface
|
||||
return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds user by email
|
||||
*
|
||||
* @param string $email
|
||||
* @return static|null
|
||||
*/
|
||||
public static function findByEmail($email)
|
||||
{
|
||||
return static::findOne(['username' => $email, 'status' => self::STATUS_ACTIVE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds user by password reset token
|
||||
*
|
||||
|
@ -11,7 +11,7 @@ use yii\base\Model;
|
||||
*/
|
||||
class LoginForm extends Model
|
||||
{
|
||||
public $username;
|
||||
public $email;
|
||||
public $password;
|
||||
public $rememberMe = true;
|
||||
|
||||
@ -25,8 +25,8 @@ class LoginForm extends Model
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
// username and password are both required
|
||||
[['username', 'password'], 'required'],
|
||||
// email and password are both required
|
||||
[['email', 'password'], 'required'],
|
||||
// rememberMe must be a boolean value
|
||||
['rememberMe', 'boolean'],
|
||||
// password is validated by validatePassword()
|
||||
@ -39,7 +39,7 @@ class LoginForm extends Model
|
||||
if (!$this->hasErrors()) {
|
||||
$user = $this->getUser();
|
||||
if (!$user || !$user->validatePassword($this->password)) {
|
||||
$this->addError($attribute, 'Incorrect username or password.');
|
||||
$this->addError($attribute, 'Incorrect e-mail or password.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -61,7 +61,7 @@ class LoginForm extends Model
|
||||
public function getUser(): ?User
|
||||
{
|
||||
if ($this->_user === null) {
|
||||
$this->_user = User::findByUsername($this->username);
|
||||
$this->_user = User::findByEmail($this->email);
|
||||
}
|
||||
|
||||
return $this->_user;
|
||||
|
Loading…
Reference in New Issue
Block a user