示例#1
0
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate()
 {
     if (!$this->hasErrors()) {
         $user = new User();
         $identity = $user->authenticate($this->username, $this->password);
         switch ($identity->errorCode) {
             case User::ERROR_NONE:
                 $duration = $this->rememberMe ? Module::getInstance()->rememberMeTime : 0;
                 Yii::$app->user->login($identity, $duration);
                 break;
             case User::ERROR_EMAIL_INVALID:
                 $this->addError("username", Module::t("Email is incorrect."));
                 break;
             case User::ERROR_USERNAME_INVALID:
                 $this->addError("username", Module::t("Username is incorrect."));
                 break;
             case User::ERROR_STATUS_NOTACTIV:
                 $this->addError("status", Module::t("Your account is not activated."));
                 break;
             case User::ERROR_STATUS_BAN:
                 $this->addError("status", Module::t("Your account is blocked."));
                 break;
             case User::ERROR_PASSWORD_INVALID:
                 $this->addError("password", Module::t("Password is incorrect."));
                 break;
         }
     }
 }