Ejemplo n.º 1
0
 /**
  * This is login function
  * 
  * @param string $sessionId
  * @param string $username
  * @param string $auth
  * @return array
  */
 public function login($sessionId, $username, $auth)
 {
     $timeout = time();
     $session = Yii::app()->getSession();
     $session->close();
     $session->setSessionID($sessionId);
     $session->open();
     $code = API::ERROR_USER_AUTH_FAILED;
     $info = Yii::t('API', 'user authenticate failed error info');
     $rand = $session->get(API::API_RAND_KEY);
     $user = TestUser::model()->findByAttributes(array('username' => $username));
     if (null !== $user) {
         if ($auth == $this->encrypt($username, $user->password, $rand)) {
             $code = API::ERROR_NONE;
             $info = '';
             $identity = new UserIdentity($username, $user->password);
             $identity->errorCode = UserIdentity::ERROR_NONE;
             $identity->setState('id', $user->id);
             $identity->setState('username', $username);
             Yii::app()->user->login($identity, 0);
             $timeout += $session->getTimeout();
             LoginService::setUserInfo();
             /*
              * CWebUser::login() function will call sesssion_regenrate_id() function
              * I dont konw why to do that right now and store the data to old session
              */
             $data = $_SESSION;
             $session->close();
             $session->setSessionID($sessionId);
             $session->open();
             foreach ($data as $key => $val) {
                 $_SESSION[$key] = $val;
             }
         }
     }
     return array($code, $info, $timeout);
 }
Ejemplo n.º 2
0
 public function login()
 {
     $identity = new UserIdentity($this->login, $this->ls_id, $this->gs_id);
     $identity->authenticate();
     switch ($identity->errorCode) {
         case UserIdentity::ERROR_USERNAME_INVALID:
             $this->addError('status', Yii::t('main', 'Неправильный Логин или Пароль.'));
             break;
         case UserIdentity::ERROR_STATUS_INACTIVE:
             $this->addError('status', Yii::t('main', 'Аккаунт не активирован.'));
             break;
         case UserIdentity::ERROR_STATUS_BANNED:
             $this->addError('status', Yii::t('main', 'Аккаунт заблокирован.'));
             break;
         case UserIdentity::ERROR_STATUS_IP_NO_ACCESS:
             $this->addError('status', Yii::t('main', 'С Вашего IP нельзя зайти на аккаунт.'));
             break;
         case UserIdentity::ERROR_NONE:
             $identity->setState('gs_id', $this->gs_id);
             $this->clearBadAttempt();
             $duration = 3600 * 24 * 7;
             // 7 days
             user()->login($identity, $duration);
             return TRUE;
     }
     return FALSE;
 }