コード例 #1
0
ファイル: OpenApi.php プロジェクト: bjtenao/tudu-web
 /**
  * (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;
         }
     }
 }
コード例 #2
0
ファイル: Abstract.php プロジェクト: bjtenao/tudu-web
 /**
  *
  */
 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);
     }
 }
コード例 #3
0
ファイル: Compose.php プロジェクト: bjtenao/tudu-web
 /**
  *
  * @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);
           }*/
     }
 }
コード例 #4
0
ファイル: Common.php プロジェクト: bjtenao/tudu-web
 /**
  *
  * Constructor
  */
 public function __construct(array $options = null)
 {
     if (!empty($options)) {
         $this->_options = $options;
     }
     $this->_user = Tudu_User::getInstance();
 }
コード例 #5
0
ファイル: Ansync.php プロジェクト: bjtenao/tudu-web
 /**
  *
  * Constructor
  */
 public function __construct(array $options = null)
 {
     $this->_user = Tudu_User::getInstance();
     if (!empty($options)) {
         $this->_options = array_merge($this->_options, $options);
     }
 }
コード例 #6
0
ファイル: Admin.php プロジェクト: bjtenao/tudu-web
 /**
  *
  * 初始化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;
 }
コード例 #7
0
ファイル: Bootstrap.php プロジェクト: bjtenao/tudu-web
 protected function _initApplication()
 {
     $defaultDb = $this->multidb->getDb();
     Oray_Dao_Abstract::setDefaultAdapter($defaultDb);
     Oray_Dao_Abstract::registerErrorHandler(array($this, 'daoErrorHandler'));
     Tudu_Dao_Manager::setDbs(array(Tudu_Dao_Manager::DB_MD => $this->multidb->getDb('md')));
     Tudu_User::setMemcache($this->getResource('memcache'));
     //set_error_handler(array($this, 'errorHandler'));
 }
コード例 #8
0
ファイル: IndexController.php プロジェクト: bjtenao/tudu-web
 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');
         }
     }
 }
コード例 #9
0
ファイル: Bootstrap.php プロジェクト: bjtenao/tudu-web
 /**
  *
  */
 protected function _initApplication()
 {
     //$defaultDb = $this->multidb->getDb();
     //Oray_Db_Helper::getInstance()->set('tudu-md', $defaultDb);
     Oray_Dao_Abstract::setDefaultAdapter($this->multidb->getDb());
     Oray_Dao_Abstract::registerErrorHandler(array($this, 'daoErrorHandler'));
     Tudu_Dao_Manager::setDbs(array(Tudu_Dao_Manager::DB_MD => $this->multidb->getDb('md')));
     Tudu_User::setMemcache($this->getResource('memcache'));
     $resourceManager = new Tudu_Model_ResourceManager_Registry();
     $resourceManager->setResource('config', $this->_options);
     Tudu_Model::setResourceManager($resourceManager);
     //set_error_handler(array($this, 'errorHandler'));
 }
コード例 #10
0
ファイル: Forward.php プロジェクト: bjtenao/tudu-web
 /**
  * (non-PHPdoc)
  * @see Model_Tudu_Compose_Abstract::send()
  */
 public function send(Model_Tudu_Tudu &$tudu)
 {
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     $user = Tudu_User::getInstance();
     // 发送图度
     if ($this->_fromTudu->type == 'task' && !$tudu->reviewer && !$tudu->isDraft) {
         // 移除当前执行人
         $daoTudu->removeAccepter($tudu->tuduId, $this->_user->uniqueId);
         $daoTudu->deleteLabel($tudu->tuduId, $this->_user->uniqueId, '^a');
     }
     $daoTudu->addLabel($tudu->tuduId, $this->_user->uniqueId, '^w');
 }
コード例 #11
0
ファイル: Review.php プロジェクト: bjtenao/tudu-web
 /**
  * (non-PHPdoc)
  * @see Model_Tudu_Compose_Abstract::send()
  */
 public function send(Model_Tudu_Tudu &$tudu)
 {
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     /* @var $daoTuduGroup Dao_Td_Tudu_Group */
     $daoTuduGroup = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Group', Tudu_Dao_Manager::DB_TS);
     $user = Tudu_User::getInstance();
     $daoTudu->deleteLabel($tudu->tuduId, $this->_user->uniqueId, '^e');
     $daoTudu->addLabel($tudu->tuduId, $this->_user->uniqueId, '^v');
     // 发送图度
     $to = $tudu->to;
     if ($tudu->type == 'task' && !$tudu->reviewer && !$tudu->isDraft) {
         // 移除原有执行人
         $accepters = $daoTudu->getAccepters($tudu->tuduId);
         foreach ($accepters as $item) {
             list($username, ) = explode(' ', $item['accepterinfo'], 2);
             // 修改用户关联记录为非执行人,移除“我执行”标签
             if (!empty($to) && !array_key_exists($username, $to) && $daoTuduGroup->getChildrenCount($tudu->tuduId, $item['uniqueid']) <= 0) {
                 $daoTudu->removeAccepter($tudu->tuduId, $item['uniqueid']);
                 $daoTudu->deleteLabel($tudu->tuduId, $item['uniqueid'], '^a');
             }
         }
     }
 }
コード例 #12
0
ファイル: Manage.php プロジェクト: bjtenao/tudu-web
 /**
  * 图度标签操作
  *
  * @param Model_Tudu_Tudu $tudu
  */
 public function label($tuduId, array $labels)
 {
     if (empty($labels)) {
         require_once 'Model/Tudu/Exception.php';
         throw new Model_Tudu_Exception('Missing or invalid value of parameter "labelid"', self::CODE_INVALID_LABELID);
     }
     $user = Tudu_User::getInstance();
     $uniqueId = $user->uniqueId;
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     $ret = false;
     foreach ($labels as $labelId => $action) {
         switch ($action) {
             case 'add':
                 $ret = $daoTudu->addLabel($tuduId, $uniqueId, $labelId);
                 break;
             case 'delete':
                 $ret = $daoTudu->deleteLabel($tuduId, $uniqueId, $labelId);
                 break;
         }
     }
     if (!$ret) {
         require_once 'Model/Tudu/Exception.php';
         throw new Model_Tudu_Exception('Label operation failed', self::LABEL_OPERATION_FAILED);
     }
 }
コード例 #13
0
ファイル: Send.php プロジェクト: bjtenao/tudu-web
 /**
  * (non-PHPdoc)
  * @see Model_Tudu_Compose_Abstract::send()
  */
 public function send(Model_Tudu_Tudu &$tudu)
 {
     /* @var $daoTudu Dao_Td_Tudu_Tudu */
     $daoTudu = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Tudu', Tudu_Dao_Manager::DB_TS);
     $user = Tudu_User::getInstance();
     // 添加到自己
     $daoTudu->addUser($tudu->tuduId, $this->_user->uniqueId, array('role' => 'from', 'accepterinfo' => $this->_user->userName . ' ' . $this->_user->trueName));
     // 移除草稿标签
     $r = $daoTudu->deleteLabel($tudu->tuduId, $this->_user->uniqueId, '^r');
     $daoTudu->addLabel($tudu->tuduId, $this->_user->uniqueId, '^all');
     if (!$tudu->parentId) {
         $daoTudu->addLabel($tudu->tuduId, $this->_user->uniqueId, '^i');
     }
     // 已发送
     if (!$this->_fromTudu || $this->_fromTudu->sender == $this->_user->userName) {
         $daoTudu->addLabel($tudu->tuduId, $this->_user->uniqueId, '^f');
     }
     if ($tudu->type == 'notice') {
         $daoTudu->addLabel($tudu->tuduId, $this->_user->uniqueId, '^n');
     }
     if ($tudu->type == 'discuss') {
         $daoTudu->addLabel($tudu->tuduId, $this->_user->uniqueId, '^d');
     }
     if ($tudu->type == 'meeting') {
         $daoTudu->addLabel($tudu->tuduId, $this->_user->uniqueId, '^m');
     }
     // 发送图度
     $to = $tudu->to;
     if ($tudu->type == 'task' && !$tudu->reviewer && !$tudu->isDraft) {
         // 移除原有执行人
         $accepters = $daoTudu->getAccepters($tudu->tuduId);
         $daoTuduGroup = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Group', Tudu_Dao_Manager::DB_TS);
         foreach ($accepters as $item) {
             list($username, ) = explode(' ', $item['accepterinfo'], 2);
             // 修改用户关联记录为非执行人,移除“我执行”标签
             if (!empty($to) && !array_key_exists($username, $to) && $daoTuduGroup->getChildrenCount($tudu->tuduId, $item['uniqueid']) <= 0) {
                 $daoTudu->removeAccepter($tudu->tuduId, $item['uniqueid']);
                 $daoTudu->deleteLabel($tudu->tuduId, $item['uniqueid'], '^a');
             }
         }
     }
 }
コード例 #14
0
ファイル: User.php プロジェクト: bjtenao/tudu-web
 /**
  *
  * @param Memcache $cache
  */
 public static function setMemcache(Memcache $cache)
 {
     self::$_memcache = $cache;
 }
コード例 #15
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']);
 }