Beispiel #1
0
 public function login()
 {
     $login = parent::getLogin();
     $password = parent::getPassword();
     $identity = new AdminIdentity($login, $password);
     $identity->authenticate();
     switch ($identity->errorCode) {
         case AdminIdentity::ERROR_USERNAME_INVALID:
         case AdminIdentity::ERROR_PASSWORD_INVALID:
             $this->addError('login', Yii::t('backend', 'Аккаунт не найден.'));
             break;
         case AdminIdentity::ERROR_STATUS_BANNED:
             $this->addError('login', Yii::t('backend', 'Аккаунт забанен.'));
             break;
         case AdminIdentity::ERROR_STATUS_INACTIVE:
             $this->addError('login', Yii::t('backend', 'Аккаунт не активирован.'));
             break;
         case AdminIdentity::ERROR_STATUS_IP_NO_ACCESS:
             $this->addError('login', Yii::t('backend', 'Доступ к аккаунту для вашего IP запрещён.'));
             break;
         default:
             $duration = 3600 * 24 * 7;
             // 7 days
             admin()->login($identity, $duration);
             return TRUE;
     }
     return FALSE;
 }
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate($attribute, $params)
 {
     if (!$this->hasErrors()) {
         // we only want to authenticate when no input errors
         $identity = new AdminIdentity($this->username, $this->password);
         $identity->authenticate();
         switch ($identity->errorCode) {
             case UserIdentity::ERROR_NONE:
                 $duration = $this->rememberMe ? 3600 * 24 * 30 : 0;
                 // 30 days
                 Yii::app()->user->login($identity, $duration);
                 break;
             case UserIdentity::ERROR_EMAIL_INVALID:
                 $this->addError("username", "Inputs are not matching with database info. Please re-type the info.");
                 break;
             case UserIdentity::ERROR_USERNAME_INVALID:
                 $this->addError("username", "Inputs are not matching with database info. Please re-type the info.");
                 break;
             case UserIdentity::ERROR_PASSWORD_INVALID:
                 $this->addError("username", "Inputs are not matching with database info. Please re-type the info.");
                 break;
             case UserIdentity::ERROR_STATUS_NOTACTIV:
                 $this->addError("status", "You account is not activated.");
                 break;
             case UserIdentity::ERROR_STATUS_BAN:
                 $this->addError("status", "You account is blocked.");
                 break;
             case UserIdentity::ERROR_STATUS_EXPIRE:
                 $this->addError("status", "You account is expired.");
                 break;
             case UserIdentity::ERROR_PASSWORD_INVALID:
                 $this->addError("password", "Inputs are not matching with database info. Please re-type the info.");
                 break;
         }
     }
 }