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]);
|
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
|
* Finds user by password reset token
|
||||||
*
|
*
|
||||||
|
@ -11,7 +11,7 @@ use yii\base\Model;
|
|||||||
*/
|
*/
|
||||||
class LoginForm extends Model
|
class LoginForm extends Model
|
||||||
{
|
{
|
||||||
public $username;
|
public $email;
|
||||||
public $password;
|
public $password;
|
||||||
public $rememberMe = true;
|
public $rememberMe = true;
|
||||||
|
|
||||||
@ -25,8 +25,8 @@ class LoginForm extends Model
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
// username and password are both required
|
// email and password are both required
|
||||||
[['username', 'password'], 'required'],
|
[['email', 'password'], 'required'],
|
||||||
// rememberMe must be a boolean value
|
// rememberMe must be a boolean value
|
||||||
['rememberMe', 'boolean'],
|
['rememberMe', 'boolean'],
|
||||||
// password is validated by validatePassword()
|
// password is validated by validatePassword()
|
||||||
@ -39,7 +39,7 @@ class LoginForm extends Model
|
|||||||
if (!$this->hasErrors()) {
|
if (!$this->hasErrors()) {
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
if (!$user || !$user->validatePassword($this->password)) {
|
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
|
public function getUser(): ?User
|
||||||
{
|
{
|
||||||
if ($this->_user === null) {
|
if ($this->_user === null) {
|
||||||
$this->_user = User::findByUsername($this->username);
|
$this->_user = User::findByEmail($this->email);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_user;
|
return $this->_user;
|
||||||
|
Loading…
Reference in New Issue
Block a user