/**
  * @return string
  */
 public function actionLogin()
 {
     // 已经登录,直接跳到首页面
     if (!\Yii::$app->user->isGuest) {
         $this->goHome();
     }
     // 初始化登录表单
     $model = new LoginForm();
     // 用户点击登录按钮,提交数据
     if ($model->load($_POST)) {
         if ($model->inActive()) {
             // 先判断是否是未激活
             $this->setLoginAttempts($this->getLoginAttempts() + 1);
             Yii::$app->getSession()->setFlash('inactive', Yii::t('auth.user', 'This user is not inactive, please check your email for the activing user link.'));
         } else {
             if ($model->login()) {
                 // 校验成功
                 $this->setLoginAttempts(0);
                 // 登录成功,清除登录失败次数
                 return $this->goBack();
                 // 返回用户之前的链接
             } else {
                 // 如果登录失败,则失败次数+1
                 $this->setLoginAttempts($this->getLoginAttempts() + 1);
             }
         }
     }
     // 如果登录次数过多,则出现验证码
     if ($this->getLoginAttempts() >= $this->module->attemptsBeforeCaptcha) {
         $model->scenario = 'withCaptcha';
     }
     // 显示登录页面
     return $this->render('login', ['model' => $model]);
 }
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         $this->goHome();
     }
     $model = new LoginForm();
     //make the captcha required if the unsuccessful attempts are more of thee
     if ($this->getLoginAttempts() >= $this->module->attemptsBeforeCaptcha) {
         $model->scenario = 'withCaptcha';
     }
     if ($model->load($_POST) and $model->login()) {
         $this->setLoginAttempts(0);
         //if login is successful, reset the attempts
         return $this->goBack();
     }
     //if login is not successful, increase the attempts
     $this->setLoginAttempts($this->getLoginAttempts() + 1);
     return $this->render('login', ['model' => $model]);
 }