Exemple #1
0
 /**
  * Set user related info after login success
  * @param CFilterChain $filterChain the filter chain that the filter is on.
  * @return boolean whether the filtering process should continue and the action
  * should be executed.
  */
 public static function setUserInfo()
 {
     $userId = Yii::app()->user->id;
     $accessableProducts = TestUserService::getAccessableProduct($userId);
     if (empty($accessableProducts)) {
         Yii::app()->user->logout();
         return Yii::t('LoginForm', 'no accessable product');
     }
     $productCookieKey = $userId . "_product";
     $productIdArr = array();
     foreach ($accessableProducts as $productInfo) {
         $productOptions[$productInfo['id']] = $productInfo['name'];
         $productIdArr[] = $productInfo['id'];
     }
     $cookies = Yii::app()->request->getCookies();
     if (empty($cookies[$productCookieKey]) || !in_array($cookies[$productCookieKey]->value, $productIdArr)) {
         $cookie = new CHttpCookie($productCookieKey, $accessableProducts[0]['id']);
         $cookie->expire = time() + 60 * 60 * 24 * 30;
         //有限期30天
         Yii::app()->request->cookies[$productCookieKey] = $cookie;
     }
     Yii::app()->user->setState('product', $cookies[$productCookieKey]->value);
     Yii::app()->user->setState('visit_product_list', $productOptions);
     Yii::app()->user->setState('visit_product_id', $productIdArr);
     Yii::app()->user->setState('system_admin', TestUserService::isSystemAdmin(Yii::app()->user->id));
     Yii::app()->user->setState('system_manager', TestUserService::isManager(Yii::app()->user->id));
     Yii::app()->user->setState('my_query_div', 1);
 }
Exemple #2
0
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $identity = new UserIdentity($this->username, $this->password);
         if (0 == $this->isapi) {
             $identity->authenticate();
         } else {
             $identity->apiAuthenticate();
         }
         switch ($identity->errorCode) {
             case UserIdentity::ERROR_NONE:
                 $accessableProducts = TestUserService::getAccessableProduct($identity->getId());
                 if (empty($accessableProducts)) {
                     $this->addError('username', Yii::t('LoginForm', 'no accessable product'));
                 } else {
                     $duration = 0;
                     if ($this->rememberMe) {
                         // keep login state duration
                         $duration = LoginForm::DURATION;
                     }
                     Yii::app()->user->login($identity, $duration);
                     UserLogService::createUserLog(array('created_by' => Yii::app()->user->id, 'created_at' => date(CommonService::DATE_FORMAT), 'ip' => $_SERVER['REMOTE_ADDR']));
                     LoginService::setLanguageCookie($this->language);
                 }
                 break;
             case UserIdentity::ERROR_USERNAME_INVALID:
                 $this->addError('username', Yii::t('LoginForm', 'username is incorrect'));
                 break;
             case UserIdentity::ERROR_CONNECT:
                 $this->addError('username', Yii::t('LoginForm', 'ldap connect failed'));
                 break;
             case UserIdentity::ERROR_USER_DISABLED:
                 $this->addError('username', Yii::t('LoginForm', 'user disabled'));
                 break;
             case UserIdentity::ERROR_LDAP_MISS:
                 $this->addError('username', Yii::t('LoginForm', 'ldap module disabled'));
                 break;
             case UserIdentity::ERROR_USER_NOT_FOUND:
                 $this->addError('username', Yii::t('LoginForm', 'user not found') . '&nbsp;<a href="' . Yii::app()->createUrl('site/permission') . '">' . Yii::t('LoginForm', 'permission tips') . '</a>');
                 break;
             default:
                 // UserIdentity::ERROR_PASSWORD_INVALID {
                 $this->addError('password', Yii::t('LoginForm', 'password is incorrect'));
                 break;
         }
     }
 }
Exemple #3
0
 /**
  * find modules
  * 
  * @param type $productId
  * @param type $moduleId
  * @param type $moduleName
  * @return type 
  */
 public function findModules($productId, $moduleId, $moduleName)
 {
     $code = API::ERROR_NONE;
     $info = '';
     if (empty($productId)) {
         $code = API::ERROR_PRODUCT_EMPTY;
         $info = Yii::t('API', 'product id empty error info');
     } else {
         $accessProductIds = array();
         $accessProducts = TestUserService::getAccessableProduct(Yii::app()->user->id);
         foreach ($accessProducts as $accessProduct) {
             $accessProductIds[] = $accessProduct['id'];
         }
         $condition = new CDbCriteria();
         $condition->compare('id', $moduleId);
         $condition->compare('name', $moduleName, true);
         $condition->compare('product_id', $productId);
         $condition->addInCondition('product_id', $accessProductIds);
         $modules = ProductModule::model()->findAllByAttributes(array(), $condition);
         $list = array();
         foreach ($modules as $module) {
             $list[] = array('id' => $module->id, 'name' => $module->name, 'product_id' => $module->product_id, 'grade' => $module->grade, 'parent_id' => $module->parent_id, 'full_path_name' => $module->full_path_name);
         }
         $info['ModuleList'] = $list;
     }
     return array($code, $info);
 }