Beispiel #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 '';
 }
 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 '';
 }
Beispiel #3
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;
 }
Beispiel #4
0
 public function __construct()
 {
     $this->counterConfig = IoC::get('config')->CounterRank;
 }
Beispiel #5
0
 public function __construct()
 {
     $this->elasticsearch = new \Elasticsearch\Client(array('hosts' => IoC::get('config')->EvaSearch->elasticsearch->servers->toArray()));
 }
Beispiel #6
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);
 }
Beispiel #7
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();
 }
Beispiel #8
0
 function eva_domain($domainName)
 {
     $config = IoC::get('config');
     return @$config->domains->{$domainName}->domain;
 }