hasErrors()) { $user = $this->getUser(); if (!$user || !$user->validatePassword($this->password)) { $this->addError($attribute, 'Incorrect e-mail or password.'); } } } public function login() { if ($this->validate()) { if ($this->getUser()) { $access_token = $this->_user->generateAccessToken(); $this->_user->access_token_expired_at = date('Y-m-d', time() + static::EXPIRE_TIME); $this->_user->save(); Yii::$app->user->login($this->_user, static::EXPIRE_TIME); return $access_token; } } return false; } public function getUser(): ?User { if ($this->_user === null) { $this->_user = User::findByEmail($this->email); } return $this->_user; } }