示例#1
0
 public function indexAction(ServerRequestInterface $Request, ResponseInterface $Response, callable $Next = null)
 {
     $data = [];
     $path = $Request->getOriginalRequest()->getUri()->getPath();
     $pagdata = $this->getPaginationDataFromRequest($Request);
     $entities = $this->storage->fetchAll('users');
     $cnt = count($entities);
     // If the requested page is later than the last, redirect to the last
     /*if ($cnt && $pagdata['page'] > $cnt) {
           return $Response
               ->withStatus(302)
               ->withHeader('Location', sprintf('%s?page-categories=%d', $path, $cnt));
       }*/
     $entities->setItemCountPerPage($pagdata['size']);
     $entities->setCurrentPageNumber($pagdata['page']);
     // $data['pages'] = iterator_to_array($pages->getItemsByPage($page));
     $data['users'] = iterator_to_array($entities->getCurrentItems());
     // pagination data
     $data['pagination'] = [];
     $data['pagination']['page'] = $pagdata['page'];
     $data['pagination']['size'] = $pagdata['size'];
     $data['pagination']['count'] = $cnt;
     // return new JsonResponse($data);
     return new HtmlResponse($this->template->render('user::list', $data));
     // return new HtmlResponse($this->template->render('page::category-list', $data));
 }
示例#2
0
 public function __invoke(Request $request, Response $response, callable $next) : Response
 {
     $parent = $request->getOriginalRequest();
     $parentUrl = str_replace('/thank-you', '', (string) $parent->getUri());
     if (!$request->hasHeader('Referer') || !preg_match('#^' . $parentUrl . '#', $request->getHeaderLine('Referer'))) {
         return $response->withStatus(302)->withHeader('Location', $parentUrl);
     }
     return new HtmlResponse($this->template->render('contact::thankyou', []));
 }
 public function __invoke(Request $req, Response $res, callable $next) : Response
 {
     $tag = str_replace(['+', '%20'], ' ', $req->getAttribute('tag', ''));
     $path = $req->getOriginalRequest()->getUri()->getPath();
     $page = $this->getPageFromRequest($req);
     $posts = $tag ? $this->mapper->fetchAllByTag($tag) : $this->mapper->fetchAll();
     $posts->setItemCountPerPage(10);
     // If the requested page is later than the last, redirect to the last
     if (count($posts) && $page > count($posts)) {
         return $res->withStatus(302)->withHeader('Location', sprintf('%s?page=%d', $path, count($posts)));
     }
     $posts->setCurrentPageNumber($page);
     $pagination = $this->preparePagination($path, $page, $posts->getPages());
     $entries = $this->prepareEntries($page, $posts);
     return new HtmlResponse($this->template->render('blog::list', $this->prepareView($tag, $entries, $pagination)));
 }
 /**
  * @param Request $request
  * @return \Psr\Http\Message\ResponseInterface|RedirectResponse
  */
 public function handle(Request $request)
 {
     $redirectUri = $request->getOriginalRequest()->getUri()->withQuery('');
     $session = $request->getAttribute('session');
     $queryParams = $request->getQueryParams();
     $oidSig = array_get($queryParams, 'openid_sig');
     if (!$oidSig) {
         return new RedirectResponse((string) (new Uri(SteamAuthController::LOGIN_URL))->withQuery(http_build_query(['openid.ns' => 'http://specs.openid.net/auth/2.0', 'openid.mode' => 'checkid_setup', 'openid.identity' => 'http://specs.openid.net/auth/2.0/identifier_select', 'openid.claimed_id' => 'http://specs.openid.net/auth/2.0/identifier_select', 'openid.return_to' => (string) $redirectUri, 'openid.realm' => (string) $redirectUri->withPath('')])));
     }
     $query = ['openid.ns' => 'http://specs.openid.net/auth/2.0', 'openid.sig' => array_get($queryParams, 'openid_sig')];
     foreach (explode(',', array_get($queryParams, 'openid_signed')) as $param) {
         $query['openid.' . $param] = array_get($queryParams, 'openid_' . $param);
     }
     // do not let overwrite this one via openid_signed
     $query['openid.mode'] = 'check_authentication';
     $client = new Client();
     try {
         $res = $client->request('POST', SteamAuthController::LOGIN_URL, ['form_params' => $query]);
     } catch (Exception $e) {
         return new Response("Can't Verify OpenID", 500);
     }
     if ($res->getStatusCode() === 200 and preg_match("/^is_valid:true+\$/im", (string) $res->getBody()) === 1) {
         if ($steam_id = array_get($queryParams, 'openid_claimed_id') and $steam_id = basename($steam_id) and is_numeric($steam_id)) {
             try {
                 $res = $client->request('GET', SteamAuthController::API_URL, ['query' => ['key' => $this->settings->get('sijad-auth-steam.api_key'), 'steamids' => $steam_id]]);
             } catch (Exception $e) {
                 return new Response("Can't Get User Info", 500);
             }
             if ($info = json_decode((string) $res->getBody(), true)) {
                 $identification = ['steam_id' => $steam_id];
                 $suggestions = ['username' => $info['response']['players'][0]['personaname'], 'avatarUrl' => $info['response']['players'][0]['avatarfull']];
                 return $this->authResponse->make($request, $identification, $suggestions);
             }
         }
     }
     return new Response("Can't Get User Info", 500);
 }
示例#5
0
 public function __invoke(Request $request, Response $response, callable $next) : Response
 {
     $basePath = $request->getOriginalRequest()->getUri()->getPath();
     $view = array_merge($this->config, ['action' => rtrim($basePath, '/') . '/process', 'csrf' => $this->session->getCsrfToken()->getValue()]);
     return new HtmlResponse($this->template->render('contact::landing', $view));
 }
示例#6
0
 private function redirect(Request $request, Response $response) : Response
 {
     $originalUri = $request->getOriginalRequest()->getUri();
     $redirectUri = $originalUri->withPath('/');
     return $response->withStatus(302)->withHeader('Location', (string) $redirectUri);
 }
示例#7
0
 private function redisplayForm(array $error, CsrfToken $csrfToken, Request $request) : Response
 {
     $csrfToken->regenerateValue();
     $view = array_merge($this->config, ['error' => ['message' => json_encode($error)], 'action' => (string) $request->getOriginalRequest()->getUri(), 'csrf' => $csrfToken->getValue()]);
     return new HtmlResponse($this->template->render('contact.landing', $view));
 }