示例#1
0
 public function init()
 {
     $this->bootstrap = $this->getInvokeArg('bootstrap');
     $this->options = $this->bootstrap->getOptions();
     $this->_host = $this->_request->getServer('HTTP_HOST');
     if (Zend_Session::sessionExists()) {
         if (!$this->session) {
             $singleton = !empty($this->options['unittest']) ? false : true;
             $this->session = new Zend_Session_Namespace(self::SESSION_NAMESPACE, $singleton);
         }
         $this->_sessionId = Zend_Session::getId();
         do {
             // 登陆信息验证
             $names = $this->options['cookies'];
             if (!isset($this->session->auth) || !$this->_request->getCookie($names['username'])) {
                 break;
             }
             //var_dump($this->_request->getCookie($names['email']));exit();
             if ($this->session->auth['username'] != $this->_request->getCookie($names['username'])) {
                 break;
             }
             $this->session->auth['lasttime'] = time();
             $this->_user = Tudu_User::getInstance();
             $this->_user->init($this->session->auth);
         } while (false);
     } else {
         $authId = $this->_request->getCookie($this->options['cookies']['auth']);
         if (!empty($authId)) {
             $referer = PROTOCOL . '//' . $this->_request->getServer('HTTP_HOST') . '/frame';
             return $this->_redirect($this->options['sites']['www'] . '/login/auto?referer=' . urlencode($referer));
         }
     }
 }
示例#2
0
 /**
  * (non-PHPdoc)
  * @see Zend_Controller_Action::init()
  */
 public function init()
 {
     parent::init();
     $this->_bootstrap = $this->getInvokeArg('bootstrap');
     $accessToken = $this->_request->getParam('access_token', $this->_request->getHeader('OAuth-AccessToken'));
     $memcache = $this->_bootstrap->getResource('memcache');
     Tudu_User::setMemcache($memcache);
     $this->_user = Tudu_User::getInstance();
     // 提供访问令牌
     if (!empty($accessToken)) {
         $storage = new TuduX_OAuth_Storage_Session();
         $storage->setMemcache($memcache);
         $oauth = new OpenApi_OAuth_OAuth(array(OpenApi_OAuth_OAuth::STORAGE => $storage));
         $scope = $this->_request->getParam('client_id', $this->_request->getHeader('OAuth-Scope'));
         try {
             $token = $oauth->verifyAccessToken($accessToken, $scope);
             $this->_user->init($token['auth']);
             // 用户被禁用或已被退出登录
             if (!$this->_user->isLogined()) {
                 $oauth->destroyAccessToken($accessToken);
                 throw new OpenApi_OAuth_Exception("Invalid access token provided", OpenApi_OAuth_OAuth::ERROR_INVALID_ACCESSTOKEN);
             }
             // ts服务器
             $tsServer = 'ts' . $this->_user->tsId;
             Tudu_Dao_Manager::setDbs(array(Tudu_Dao_Manager::DB_TS => $this->_bootstrap->multidb->getDb($tsServer)));
             $this->_clientId = $token[OpenApi_OAuth_OAuth::PARAM_CLIENT_ID];
             $this->_accessToken = $accessToken;
             $this->_token = $token;
             // 验证失败
         } catch (OpenApi_OAuth_Exception $e) {
             throw $e;
         }
     }
 }
示例#3
0
 /**
  *
  * 初始化Session
  */
 public function initUser()
 {
     if (null === $this->_session) {
         $this->_session = new Zend_Session_Namespace(self::SESSION_NAMESPACE, true);
     }
     // 登陆信息验证
     $names = $this->_options['cookies'];
     if (!isset($this->_session->auth) || !$this->_request->getCookie($names['username'])) {
         $this->destroySession();
         return;
     }
     if (isset($this->_session->auth['referer'])) {
         $this->_refererUrl = $this->_session->auth['referer'];
     }
     //var_dump($this->_request->getCookie($names['email']));exit();
     if ($this->_session->auth['username'] != $this->_request->getCookie($names['username'])) {
         $this->destroySession();
         return;
     }
     $this->_session->auth['lasttime'] = $this->_timestamp;
     $this->_user->init($this->_session->auth);
     if (!$this->_user->isLogined()) {
         $this->destroySession();
     }
     if (isset($this->_session->admin)) {
         $this->_user->initAdmin($this->_session->admin);
     }
     if (!$this->_user->isAdminLogined()) {
         $this->destroySession();
     }
     $this->org = $this->getOrg($this->_user->orgId);
     $this->_user->setOptions(array('timezone' => !empty($this->org['timezone']) ? $this->org['timezone'] : 'Etc/GMT-8', 'dateformat' => !empty($this->org['dateformat']) ? $this->org['dateformat'] : '%Y-%m-%d %H:%M:%S', 'passwordlevel' => $this->org['passwordlevel'], 'skin' => $this->org['skin']));
     $this->_sessionId = Zend_Session::getId();
     $this->_orgId = $this->_user->orgId;
 }
示例#4
0
文件: Base.php 项目: bjtenao/tudu-web
 /**
  * 初始化
  */
 public function init()
 {
     $this->bootstrap = $this->getInvokeArg('bootstrap');
     $this->multidb = $this->bootstrap->getResource('multidb');
     $this->cache = $this->bootstrap->getResource('memcache');
     $this->options = $this->bootstrap->getOptions();
     $this->_user = Tudu_User::getInstance();
     $this->_timestamp = time();
     if (Zend_Session::sessionExists() || !empty($this->_sessionId)) {
         if (!$this->session) {
             $this->session = new Zend_Session_Namespace(self::SESSION_NAMESPACE, false);
         }
         $this->_sessionId = Zend_Session::getId();
         do {
             // 登陆信息验证
             $names = $this->options['cookies'];
             if (!isset($this->session->auth) || !$this->_request->getCookie($names['username'])) {
                 $this->_destroySession();
                 break;
             }
             if (isset($this->session->auth['referer'])) {
                 $this->_refererUrl = $this->session->auth['referer'];
             }
             if ($this->session->auth['username'] != $this->_request->getCookie($names['username'])) {
                 $this->_destroySession();
                 break;
             }
             $this->session->auth['lasttime'] = $this->_timestamp;
             $this->_user->init($this->session->auth);
             if (!$this->_user->isLogined()) {
                 $this->_destroySession();
             }
             // 体验帐号
             if (in_array($this->_user->orgId, array('win', 'tuduoffice'))) {
                 $this->session->isdemo = true;
             }
             if ($this->_user->orgId == 'online-app') {
                 header('P3P: CP=”CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR”');
             }
             $this->org = $this->getOrg($this->_user->orgId);
             $this->_user->setOptions(array('timezone' => !empty($this->org['timezone']) ? $this->org['timezone'] : 'Etc/GMT-8', 'dateformat' => !empty($this->org['dateformat']) ? $this->org['dateformat'] : '%Y-%m-%d %H:%M:%S', 'passwordlevel' => $this->org['passwordlevel'], 'skin' => $this->org['skin']));
             if (!empty($this->_user->option['language'])) {
                 Tudu_Lang::getInstance()->setLanguage($this->_user->option['language']);
             }
             // 禁止访问
             if (Dao_Md_Org_Org::STATUS_FORBID == $this->org['status']) {
                 $controllerName = $this->_request->getControllerName();
                 if ($controllerName != 'forbid') {
                     $this->jump('/forbid');
                 }
             }
             // 设置默认时区
             if (!empty($this->_user->option['timezone'])) {
                 date_default_timezone_set($this->_user->option['timezone']);
             }
             // 注册TS数据库
             Tudu_Dao_Manager::setDb(Tudu_Dao_Manager::DB_TS, $this->multidb->getDb('ts' . $this->org['tsid']), true);
         } while (false);
     } else {
         $authId = $this->_request->getCookie($this->options['cookies']['auth']);
         if (!empty($authId)) {
             $query = $this->_request->getServer('HTTP_QUERY_STRING');
             return $this->jump($this->options['sites']['www'] . '/login/auto?referer=%referer', array(), array('referer' => true));
         }
     }
     $this->view->version = self::TUDU_VERSION;
     $this->view->user = $this->_user->toArray();
     $this->view->options = array('sites' => $this->options['sites'], 'tudu' => $this->options['tudu']);
 }