Example #1
0
 /**
  * Find token from http request, token may be in http header or url query
  * If find both, use http header priority
  * @param RequestInterface $request
  * @return string
  */
 public static function discoverToken(RequestInterface $request, $useCookie = true)
 {
     if ($token = $request->getQuery(TokenStorage::AUTH_QUERY_KEY, 'string')) {
         return $token;
     }
     //For apache
     if (function_exists('getallheaders')) {
         $headers = getallheaders();
         if (!isset($headers[TokenStorage::AUTH_HEADER_KEY])) {
             return '';
         }
         $token = trim($headers[TokenStorage::AUTH_HEADER_KEY]);
         $token = explode(' ', $token);
         return isset($token[1]) ? $token[1] : '';
     }
     //For nginx
     if ($token = $request->getHeader(strtoupper(TokenStorage::AUTH_HEADER_KEY))) {
         $token = trim($token);
         $token = explode(' ', $token);
         return isset($token[1]) ? $token[1] : '';
     }
     //For cookie
     $cookies = IoC::get('cookies');
     if ($cookies->has('api_key') && $useCookie) {
         $token = $cookies->get('api_key')->getValue();
         return $token;
     }
     return '';
 }
Example #2
0
 protected function generateId()
 {
     $sso_ticket_name = IoC::get('config')->session->sso_ticket_name;
     if (!empty($_COOKIE[$sso_ticket_name])) {
         return $_COOKIE[$sso_ticket_name];
     }
     return '';
 }
Example #3
0
 public static function checkLoginSourceOfUser($target)
 {
     $loginSource = 'DEFAULT';
     $config = IoC::getDI()->getConfig();
     $sourceConfig = $config->user->source;
     foreach ($sourceConfig as $key => $source) {
         if (strstr($target, $key)) {
             $loginSource = $source;
         }
     }
     return $loginSource;
 }
Example #4
0
 /**
  * 格式化参数
  * @param array $params
  * @return string
  */
 private function formatParam($queryType, $params)
 {
     $supportClass = IoC::get('config')->validateConfig->supportClass;
     if (empty($supportClass[$queryType])) {
         return -1;
     }
     $keys = array();
     $values = array();
     foreach ($params as $key => $value) {
         $keys[] = $key;
         $values[] = $value;
     }
     $param = str_replace($keys, $values, $supportClass[$queryType]);
     return $param;
 }
Example #5
0
 public function __construct()
 {
     $this->counterConfig = IoC::get('config')->CounterRank;
 }
Example #6
0
 /**
  * Configuration application default DI
  *
  * @return FactoryDefault| CLI
  */
 public function getDI()
 {
     if ($this->di) {
         return $this->di;
     }
     if ($this->appMode == 'cli') {
         $di = new FactoryDefault\CLI();
     } else {
         $di = new FactoryDefault();
     }
     //PHP5.3 not support $this in closure
     $self = $this;
     /**********************************
      * DI initialize for MVC core
      ***********************************/
     //$di->set('application', $this);
     //call loadmodules will overwrite this
     $di->set('moduleManager', function () use($di) {
         $moduleManager = new ModuleManager();
         $moduleManager->setEventsManager($di->getEventsManager());
         return $moduleManager;
     }, true);
     //System global events manager
     $di->set('eventsManager', function () use($di) {
         $eventsManager = new EventsManager();
         $eventsManager->enablePriorities(true);
         // dispatch caching event handler
         $eventsManager->attach("dispatch", new DispatchInterceptor(), -1);
         $eventsManager->enablePriorities(true);
         return $eventsManager;
     }, true);
     $di->set('config', function () use($self) {
         return $self->diConfig();
     }, true);
     $di->set('router', function () use($self) {
         return $self->diRouter();
     }, true);
     $di->set('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setEventsManager($di->getEventsManager());
         return $dispatcher;
     }, true);
     $di->set('modelsMetadata', function () use($self) {
         return $self->diModelsMetadata();
     }, true);
     $di->set('modelsManager', function () use($di) {
         $config = $di->getConfig();
         ModelManager::setDefaultPrefix($config->dbAdapter->prefix);
         //for solving db master/slave under static find method
         $modelsManager = new ModelManager();
         return $modelsManager;
     });
     $di->set('view', function () use($di) {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setEventsManager($di->getEventsManager());
         return $view;
     });
     $di->set('session', function () use($self) {
         return $self->diSession();
     });
     $di->set('tokenStorage', function () use($self) {
         return $self->diTokenStorage();
     }, true);
     /**********************************
      * DI initialize for database
      ***********************************/
     $di->set('dbMaster', function () use($self) {
         return $self->diDbMaster();
     }, true);
     $di->set('dbSlave', function () use($self) {
         return $self->diDbSlave();
     }, true);
     $di->set('transactions', function () use($di) {
         $transactions = new \Phalcon\Mvc\Model\Transaction\Manager();
         $transactions->setDbService('dbMaster');
         return $transactions;
     }, true);
     /**********************************
      * DI initialize for cache
      ***********************************/
     $di->set('globalCache', function () use($self) {
         return $self->diGlobalCache();
     }, true);
     $di->set('viewCache', function () use($self) {
         return $self->diViewCache();
     }, true);
     $di->set('modelsCache', function () use($self) {
         return $self->diModelsCache();
     }, true);
     $di->set('apiCache', function () use($self) {
         return $self->diApiCache();
     }, true);
     $di->set('fastCache', function () use($self) {
         return $self->diFastCache();
     }, true);
     /**********************************
      * DI initialize for queue
      ***********************************/
     $di->set('queue', function () use($di) {
         $config = $di->getConfig();
         $client = new \GearmanClient();
         $client->setTimeout(1000);
         foreach ($config->queue->servers as $key => $server) {
             $client->addServer($server->host, $server->port);
         }
         return $client;
     }, true);
     $di->set('worker', function () use($di) {
         $config = $di->getConfig();
         $worker = new \GearmanWorker();
         foreach ($config->queue->servers as $key => $server) {
             $worker->addServer($server->host, $server->port);
         }
         return $worker;
     }, true);
     /**********************************
      * DI initialize for email
      ***********************************/
     $di->set('mailer', function () use($self) {
         return $self->diMailer();
     }, true);
     $di->set('mailMessage', 'Eva\\EvaEngine\\MailMessage');
     $di->set('smsSender', function () use($self) {
         return $self->diSmsSender();
     }, true);
     /**********************************
      * DI initialize for helpers
      ***********************************/
     $di->set('url', function () use($di) {
         $config = $di->getConfig();
         $url = new UrlResolver();
         $url->setVersionFile($config->staticBaseUriVersionFile);
         $url->setBaseUri($config->baseUri);
         $url->setStaticBaseUri($config->staticBaseUri);
         return $url;
     }, true);
     $di->set('escaper', 'Phalcon\\Escaper');
     $di->set('tag', function () use($di, $self) {
         Tag::setDi($di);
         $self->registerViewHelpers();
         return new Tag();
     });
     $di->set('flash', 'Phalcon\\Flash\\Session');
     $di->set('placeholder', 'Eva\\EvaEngine\\View\\Helper\\Placeholder');
     $di->set('cookies', function () {
         $cookies = new \Phalcon\Http\Response\Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
     $di->set('translate', function () use($self) {
         return $self->diTranslate();
     });
     $di->set('fileSystem', function () use($self) {
         return $self->diFileSystem();
     });
     $di->set('logException', function () use($di) {
         $config = $di->getConfig();
         return new FileLogger($config->logger->path . 'error.log');
     });
     if ($this->appMode == 'cli') {
         $this->cliDI($di);
     }
     IoC::setDI($di);
     return $this->di = $di;
 }
Example #7
0
 public function __construct()
 {
     $this->elasticsearch = new \Elasticsearch\Client(array('hosts' => IoC::get('config')->EvaSearch->elasticsearch->servers->toArray()));
 }
Example #8
0
 /**
  * 通过 Post 数组来生成 URL
  *
  * @param $post
  * @return mixed
  */
 public static function getUrlByPostArr($post)
 {
     return preg_replace_callback('/{{(.+?)}}/', function ($matches) use($post) {
         return empty($post[$matches[1]]) ? '' : $post[$matches[1]];
     }, IoC::get('config')->blog->postPath);
 }
Example #9
0
 public static function logout()
 {
     /** @var \Phalcon\HTTP\ResponseInterface $response */
     $response = IoC::get('response');
     $response->setHeader('P3P', 'CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR');
     $config = IoC::get('config');
     /** @var \Phalcon\Http\Response\Cookies $cookies */
     $cookies = IoC::get('cookies');
     $cookieDomain = $config->session->cookie_params->domain;
     $sso_ticket_name = $config->session->sso_ticket_name;
     $cookies->get(Login::LOGIN_COOKIE_KEY)->setDomain($cookieDomain)->delete();
     $cookies->get(Login::LOGIN_COOKIE_REMEMBER_KEY)->setDomain($cookieDomain)->delete();
     $cookies->get($sso_ticket_name)->setDomain($cookieDomain)->delete();
     Login::getAuthStorage()->remove(Login::AUTH_KEY_LOGIN);
     Login::getAuthStorage()->remove(Login::AUTH_KEY_TOKEN);
     Login::getAuthStorage()->remove(Login::AUTH_KEY_ROLES);
     Login::removeBadges();
 }
Example #10
0
 function eva_domain($domainName)
 {
     $config = IoC::get('config');
     return @$config->domains->{$domainName}->domain;
 }