Пример #1
0
 public function filterUserInfo($filterChain)
 {
     $productId = Yii::app()->user->getState('product');
     if (true != Yii::app()->user->isGuest && empty($productId)) {
         LoginService::setUserInfo();
     }
     $filterChain->run();
 }
Пример #2
0
 public static function login($params)
 {
     $resultInfo = array();
     $model = new LoginForm();
     $model->attributes = $params;
     $model->username = trim($model->username);
     if ($model->validate()) {
         $setInfoResult = LoginService::setUserInfo();
         if (!empty($setInfoResult)) {
             $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
             $resultInfo['detail']['username'] = $setInfoResult;
         } else {
             $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
         }
     } else {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $model->getErrors();
     }
     return $resultInfo;
 }
Пример #3
0
 public function actionIndex()
 {
     $setUserInfoResult = LoginService::setUserInfo();
     if (!empty($setUserInfoResult)) {
         $this->redirect(Yii::app()->homeUrl);
     }
     //if the url like ../bugfree
     if (empty($_GET)) {
         $this->redirect(array('info/index', 'type' => 'bug', 'product_id' => Yii::app()->user->getState('product')));
     } else {
         //for the history url link use
         if (isset($_GET['r'])) {
             //url like ..bugfree/index.php?r=info/edit&type=bug&id=132046
             if ('info/edit' == $_GET['r'] && isset($_GET['type']) && isset($_GET['id'])) {
                 $this->redirect(Yii::app()->createUrl('info/edit', array('type' => $_GET['type'], 'id' => $_GET['id'])));
             } else {
                 if ('info/index' == $_GET['r'] && isset($_GET['type']) && isset($_GET['product_id'])) {
                     $this->redirect(Yii::app()->createUrl('info/index', array('type' => $_GET['type'], 'product_id' => $_GET['product_id'])));
                 }
             }
         }
     }
 }
Пример #4
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);
 }