/** * Validates the password. * This method serves as the inline validation for password. * * @param string $attribute the attribute currently being validated * @param array $params the additional name-value pairs given in the rule */ public function validatePassword($attribute, $params) { if (!$this->hasErrors()) { $user = $this->getUser(); if (!$user || !$user->validatePassword($this->password)) { LoginError::addLog(null, $this->username); $this->addError($attribute, Yii::t('app', 'Incorrect username or password.')); } } }
/** * Logs in a user. * * @return mixed */ public function actionLogin() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $errorLogin = null; $model = new LoginForm(); $errorLogin = LoginError::getLog(); if ($errorLogin) { $model = new LoginForm(['scenario' => 'error']); } if ($model->load(Yii::$app->request->post()) && $model->login()) { LoginError::del(); return $this->goBack(); } else { $errorLogin = LoginError::getLog(); return $this->render('login', ['model' => $model, 'errorLogin' => $errorLogin]); } }