当前位置: 首页>>代码示例>>PHP>>正文


PHP EventInterface::getUserLookup方法代码示例

本文整理汇总了PHP中Imbo\EventManager\EventInterface::getUserLookup方法的典型用法代码示例。如果您正苦于以下问题:PHP EventInterface::getUserLookup方法的具体用法?PHP EventInterface::getUserLookup怎么用?PHP EventInterface::getUserLookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Imbo\EventManager\EventInterface的用法示例。


在下文中一共展示了EventInterface::getUserLookup方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: checkAccessToken

 /**
  * {@inheritdoc}
  */
 public function checkAccessToken(EventInterface $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $query = $request->query;
     $eventName = $event->getName();
     if (($eventName === 'image.get' || $eventName === 'image.head') && $this->isWhitelisted($request)) {
         // All transformations in the request are whitelisted. Skip the access token check
         return;
     }
     // If the response has a short URL header, we can skip the access token check
     if ($response->headers->has('X-Imbo-ShortUrl')) {
         return;
     }
     if (!$query->has('accessToken')) {
         throw new RuntimeException('Missing access token', 400);
     }
     $token = $query->get('accessToken');
     // First the the raw un-encoded URI, then the URI as is
     $uris = array($request->getRawUri(), $request->getUriAsIs());
     $privateKeys = $event->getUserLookup()->getPrivateKeys($request->getPublicKey()) ?: [];
     foreach ($uris as $uri) {
         // Remove the access token from the query string as it's not used to generate the HMAC
         $uri = rtrim(preg_replace('/(?<=(\\?|&))accessToken=[^&]+&?/', '', $uri), '&?');
         foreach ($privateKeys as $privateKey) {
             $correctToken = hash_hmac('sha256', $uri, $privateKey);
             if ($correctToken === $token) {
                 return;
             }
         }
     }
     throw new RuntimeException('Incorrect access token', 400);
 }
开发者ID:ASP96,项目名称:imbo,代码行数:36,代码来源:AccessToken.php

示例2: loadStats

 /**
  * Load stats
  *
  * @param EventInterface $event An event instance
  */
 public function loadStats(EventInterface $event)
 {
     $response = $event->getResponse();
     $database = $event->getDatabase();
     $userLookup = $event->getUserLookup();
     $publicKeys = $userLookup->getPublicKeys();
     $users = array();
     foreach ($publicKeys as $key) {
         $users[$key] = array('numImages' => $database->getNumImages($key), 'numBytes' => $database->getNumBytes($key));
     }
     $statsModel = new Model\Stats();
     $statsModel->setUsers($users);
     $response->setModel($statsModel);
 }
开发者ID:ASP96,项目名称:imbo,代码行数:19,代码来源:DatabaseOperations.php

示例3: authenticate

 /**
  * {@inheritdoc}
  */
 public function authenticate(EventInterface $event)
 {
     $response = $event->getResponse();
     $request = $event->getRequest();
     // Whether or not the authentication info is in the request headers
     $fromHeaders = $request->headers->has('x-imbo-authenticate-timestamp') && $request->headers->has('x-imbo-authenticate-signature');
     // Fetch timestamp header, fallback to query param
     $timestamp = $request->headers->get('x-imbo-authenticate-timestamp', $request->query->get('timestamp'));
     if (!$timestamp) {
         $exception = new RuntimeException('Missing authentication timestamp', 400);
         $exception->setImboErrorCode(Exception::AUTH_MISSING_PARAM);
     } else {
         if (!$this->timestampIsValid($timestamp)) {
             $exception = new RuntimeException('Invalid timestamp: ' . $timestamp, 400);
             $exception->setImboErrorCode(Exception::AUTH_INVALID_TIMESTAMP);
         } else {
             if ($this->timestampHasExpired($timestamp)) {
                 $exception = new RuntimeException('Timestamp has expired: ' . $timestamp, 400);
                 $exception->setImboErrorCode(Exception::AUTH_TIMESTAMP_EXPIRED);
             }
         }
     }
     if (isset($exception)) {
         throw $exception;
     }
     // Fetch signature header, fallback to query param
     $signature = $request->headers->get('x-imbo-authenticate-signature', $request->query->get('signature'));
     if (!$signature) {
         $exception = new RuntimeException('Missing authentication signature', 400);
         $exception->setImboErrorCode(Exception::AUTH_MISSING_PARAM);
     }
     if (isset($exception)) {
         throw $exception;
     }
     $publicKey = $request->getPublicKey();
     $privateKeys = $event->getUserLookup()->getPrivateKeys($publicKey, UserLookupInterface::MODE_READ_WRITE) ?: [];
     $url = $request->getRawUri();
     if (!$fromHeaders) {
         // Remove the signature and timestamp from the query parameters as they are not used
         // when generating the HMAC
         $url = rtrim(preg_replace('/(?<=(\\?|&))(signature|timestamp)=[^&]+&?/', '', $url), '&?');
     }
     // Add the URL used for auth to the response headers
     $response->headers->set('X-Imbo-AuthUrl', $url);
     if (!$this->signatureIsValid($request->getMethod(), $url, $publicKey, $privateKeys, $timestamp, $signature)) {
         $exception = new RuntimeException('Signature mismatch', 400);
         $exception->setImboErrorCode(Exception::AUTH_SIGNATURE_MISMATCH);
         throw $exception;
     }
 }
开发者ID:sgulseth,项目名称:imbo,代码行数:53,代码来源:Authenticate.php


注:本文中的Imbo\EventManager\EventInterface::getUserLookup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。