/** * (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; } } }
/** * */ public function __construct() { $this->_time = time(); /* @var $user Tudu_User */ $this->_user = Tudu_User::getInstance(); // 缺少身份认证的用户 if (!$this->_user->isLogined()) { require_once 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Invalid user to execute current operation', Model_Tudu_Exception::INVALID_USER); } }
/** * * @param Model_Tudu_Post $post * @throws Model_Tudu_Exception */ public function filter(Model_Tudu_Post &$post) { // 缺少图度ID if (!$post->tuduId) { require 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Tudu not exists', Model_Tudu_Exception::TUDU_NOTEXISTS); } $this->_user = Tudu_User::getInstance(); // 没有权限 if (!$this->_user->isLogined() || !$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_CREATE_POST)) { require 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Denied to do current action', Model_Tudu_Exception::PERMISSION_DENIED); } /* @var $daoTudu Dao_Td_Tudu_Tudu */ $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS); $this->_tudu = $daoTudu->getTuduById($this->_user->uniqueId, $post->tuduId); if (null === $this->_tudu || $this->_tudu->orgId != $this->_user->orgId) { require 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Tudu not exists', Model_Tudu_Exception::TUDU_NOTEXISTS); } if ($this->_tudu->isDone) { require 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Denied to do current action', Model_Tudu_Exception::TUDU_IS_DONE); } $isReceiver = $this->_user->uniqueId == $this->_tudu->uniqueId && count($this->_tudu->labels); $isAccepter = in_array($this->_user->userName, $this->_tudu->accepter, true); $isSender = in_array($this->_tudu->sender, array($this->_user->userName, $this->_user->account)); // 编辑已存在回复 if ($post->postId) { /* @var $daoPost Dao_Td_Tudu_Post */ $daoPost = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Post', Tudu_Dao_Manager::DB_TS); $this->_fromPost = $daoPost->getPost(array('tuduid' => $post->tuduId, 'postid' => $post->postId)); if (null === $this->_fromPost) { require 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Post not exists', Model_Tudu_Exception::POST_NOTEXISTS); } // 编辑回复权限 if ($this->_fromPost->uniqueId != $this->_user->uniqueId) { $boards = $this->_getBoards(); $board = $boards[$this->_tudu->boardId]; if (!array_key_exists($this->_user->userId, $board['moderators'])) { require 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Denied to do current action', Model_Tudu_Exception::PERMISSION_DENIED); } } } else { /*if (!$isReceiver) { require 'Model/Tudu/Exception.php'; throw new Model_Tudu_Exception('Denied to do current action', Model_Tudu_Exception::PERMISSION_DENIED); }*/ } }
/** * * 初始化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; }
public function indexAction() { $error = $this->_request->getQuery('error'); $redirect = $this->_request->getQuery('redirect'); $lang = Tudu_Lang::getInstance()->load('login'); $orgInfo = array(); // 使用SSL登陆 if ('http:' == PROTOCOL && strpos($this->options['sites']['www'], 'https:') === 0) { if (preg_replace('/^https:\\/\\//', '', $this->options['sites']['www']) == $this->_host) { $this->_redirect($this->options['sites']['www'] . $this->_request->getServer('REQUEST_URI')); } else { $this->_redirect('https://' . $this->_host . $this->_request->getServer('REQUEST_URI')); } } $memcache = $this->getInvokeArg('bootstrap')->getResource('memcache'); $orgInfo = $memcache->get('TUDU-HOST-' . $this->_host); if (!empty($this->session->auth['appinvoker'])) { return; } if (!$orgInfo) { /* @var $daoOrg Dao_Md_Org_Org */ $daoOrg = Oray_Dao::factory('Dao_Md_Org_Org', $this->bootstrap->getResource('multidb')->getDefaultDb()); $orgInfo = $daoOrg->getOrgByHost($this->_host); $flag = null; $memcache->set('TUDU-HOST-' . $this->_host, $orgInfo, $flag, 3600); } if ($this->_user && $this->_user->isLogined() && $this->_user->orgId == $orgInfo->orgId) { return $this->_redirect(PROTOCOL . '//' . $this->_request->getServer('HTTP_HOST') . '/frame'); } if ($orgInfo instanceof Dao_Md_Org_Record_Org) { $orgInfo = $orgInfo->toArray(); if (!empty($this->options['tudu']['customdomain'])) { $this->options['sites']['tudu'] = PROTOCOL . '//' . $orgInfo['orgid'] . '.' . $this->options['tudu']['domain']; } } if (in_array($error, array('params', 'failure', 'locked', 'unsupport', 'timeout', 'notexist', 'seccode', 'forbid')) && array_key_exists($error, $lang)) { $this->view->error = $error; } if ($error == 'admin') { $this->view->fromadmin = true; } $this->view->org = $orgInfo; $this->view->lang = $lang; $this->view->redirect = $redirect; $this->view->options = array('sites' => $this->options['sites'], 'tudu' => $this->options['tudu']); // 选择登陆模板 if (!empty($orgInfo) && !empty($orgInfo['loginskin'])) { $loginSkin = $orgInfo['loginskin']; if (!empty($loginSkin['selected']) && !empty($loginSkin['selected']['value']) && $loginSkin['selected']['value'] != 'SYS:default') { $this->view->loginskin = $orgInfo['loginskin']; $this->render('custom'); } } }
/** * 初始化 */ 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']); }