public function getToken(Request $request) { if (isset($this->session->token)) { return true; } elseif (strlen($this->session->state) > 0 and $this->session->state == $request->getQuery('state') and strlen($request->getQuery('code')) > 5) { $client = $this->getHttpClient(); $client->setUri($this->options->getTokenUri()); $client->setMethod(Request::METHOD_POST); $client->setParameterPost(array('code' => $request->getQuery('code'), 'client_id' => $this->options->getClientId(), 'client_secret' => $this->options->getClientSecret(), 'redirect_uri' => $this->options->getRedirectUri(), 'grant_type' => 'authorization_code')); $resBody = $client->send()->getBody(); try { $response = JsonDecoder::decode($resBody, Json::TYPE_ARRAY); if (is_array($response) and isset($response['access_token']) and !isset($response['expires']) || $response['expires'] > 0) { $this->session->token = (object) $response; return true; } else { $this->error = array('internal-error' => 'Instagram settings error.', 'message' => $response->error_message, 'type' => $response->error_type, 'code' => $response->code); return false; } } catch (\Zend\Json\Exception\RuntimeException $e) { $this->error = array('internal-error' => 'Parse error.', 'message' => $e->getMessage(), 'code' => $e->getCode()); return false; } } else { $this->error = array('internal-error' => 'State error, request variables do not match the session variables.', 'session-state' => $this->session->state, 'request-state' => $request->getQuery('state'), 'code' => $request->getQuery('code')); return false; } }
public function getToken(Request $request) { if (isset($this->session->token)) { return true; } elseif (strlen($this->session->state) > 0 and $this->session->state == $request->getQuery('state') and strlen($request->getQuery('code')) > 5) { $client = $this->getHttpClient(); $client->setUri($this->options->getTokenUri()); $client->setMethod(Request::METHOD_POST); $client->setParameterPost(array('code' => $request->getQuery('code'), 'client_id' => $this->options->getClientId(), 'client_secret' => $this->options->getClientSecret(), 'redirect_uri' => $this->options->getRedirectUri())); $retVal = $client->send()->getContent(); parse_str($retVal, $token); if (is_array($token) and isset($token['access_token']) and $token['expires'] > 0) { $this->session->token = (object) $token; return true; } else { try { $error = \Zend\Json\Decoder::decode($retVal); $this->error = array('internal-error' => 'Facebook settings error.', 'message' => $error->error->message, 'type' => $error->error->type, 'code' => $error->error->code); } catch (\Zend\Json\Exception\RuntimeException $e) { $this->error = $token; $this->error['internal-error'] = 'Unknown error.'; } return false; } } else { $this->error = array('internal-error' => 'State error, request variables do not match the session variables.', 'session-state' => $this->session->state, 'request-state' => $request->getQuery('state'), 'code' => $request->getQuery('code')); return false; } }
public function getToken(Request $request) { if (isset($this->session->token)) { return true; } elseif (strlen($this->session->state) > 0 and $this->session->state == $request->getQuery('state') and strlen($request->getQuery('code')) > 5) { $client = $this->getHttpClient(); $client->setUri($this->options->getTokenUri()); $client->setMethod(Request::METHOD_POST); $client->setParameterPost(array('code' => $request->getQuery('code'), 'client_id' => $this->options->getClientId(), 'client_secret' => $this->options->getClientSecret(), 'redirect_uri' => $this->options->getRedirectUri(), 'grant_type' => 'authorization_code')); $retVal = $client->send()->getBody(); try { $token = \Zend\Json\Decoder::decode($retVal); if (isset($token->access_token) and $token->expires_in > 0) { $this->session->token = $token; return true; } else { $this->error = array('internal-error' => 'Google settings error.', 'error' => $token->error, 'token' => $token); return false; } } catch (\Zend\Json\Exception\RuntimeException $e) { $this->error['internal-error'] = 'Unknown error.'; $this->error['token'] = $retVal; return false; } } else { $this->error = array('internal-error' => 'State error, request variables do not match the session variables.', 'session-state' => $this->session->state, 'request-state' => $request->getQuery('state'), 'code' => $request->getQuery('code')); return false; } }
/** * @param array $search * @param array $orderBy * @param array $parameters * * @return \Zend\Paginator\Paginator */ public function getList($search = [], $orderBy = [], $parameters = []) { $query = $this->mainRepository->getAdminPage($search, $orderBy, $parameters); $paginator = $this->paginatorFactory->getQueryPaginator($query); $paginator->setCurrentPageNumber($this->request->getQuery(self::PAGE, 0)); $paginator->setItemCountPerPage(5); return $paginator; }
/** * @dataProvider getListActionProvider */ public function testListAction($page, $limit) { $query = $this->request->getQuery(); $query->set('page', $page); $query->set('limit', $limit); $this->docs->expects($this->once())->method('getList')->with($page, $limit); $this->routeMatch->setParam('action', 'list'); $result = $this->object->dispatch($this->request, $this->response); $this->assertInternalType('array', $result); $this->assertArrayHasKey('dataSet', $result); }
private function checkURL() { $url = parent::getUri()->getPath(); $get = parent::getQuery()->toArray(); $explodeUrl = explode('/', $url); array_shift($explodeUrl); array_shift($explodeUrl); if (empty($explodeUrl[0])) { throw new \Exception('Empty Resource'); } $this->resourse = $explodeUrl[0]; array_shift($explodeUrl); $max = count($explodeUrl); for ($i = 0; $i < $max; $i += 2) { $name = $explodeUrl[$i]; if (empty($name)) { continue; } if (!$this->checkParamName($name)) { throw new \Exception('Invalid Parameter Name (' . $name . ')'); } $value = isset($explodeUrl[$i + 1]) ? $explodeUrl[$i + 1] : null; $this->urlParameters[$name] = urldecode($value); } foreach ($get as $name => $value) { if (!$this->checkParamName($name)) { throw new \Exception('Invalid Parameter Name (' . $name . ')'); } } $this->urlParameters = array_merge($this->urlParameters, $get); }
/** * @param Request $request * @param Di $di */ public function __construct(Request $request, Di $di) { $inputFilter = $this->getFactory()->createInputFilter(['width' => ['name' => 'width', 'required' => false, 'validators' => [['name' => 'digits'], ['name' => 'between', 'options' => ['min' => 150, 'max' => 19200]]]], 'height' => ['name' => 'height', 'required' => false, 'validators' => [['name' => 'digits'], ['name' => 'between', 'options' => ['min' => 150, 'max' => 19200]]]], 'username' => ['name' => 'username', 'required' => false, 'validators' => [['name' => 'not_empty'], ['name' => 'regex', 'options' => ['pattern' => '/^[a-zA-Z0-9._]+$/']]]], 'limit' => ['name' => 'limit', 'required' => false, 'validators' => [['name' => 'digits'], ['name' => 'between', 'options' => ['min' => 5, 'max' => 100]]]], 'hex' => ['name' => 'hex', 'required' => false, 'validators' => [['name' => 'hex']], 'filters' => [['name' => 'callback', 'options' => ['callback' => function ($value) { return ltrim($value, '#'); }]]]], 'source' => ['name' => 'source', 'required' => true, 'validators' => [['name' => 'inarray', 'options' => ['haystack' => [SourceNameInterface::SOURCE_USER, SourceNameInterface::SOURCE_FEED]]]]], 'quality' => ['name' => 'quality', 'required' => false, 'validators' => [['name' => 'inarray', 'options' => ['haystack' => [QualityInterface::QUALITY_THUMBNAIL, QualityInterface::QUALITY_LOW_RES, QualityInterface::QUALITY_STANDARD_RES]]]]]]); $this->merge($inputFilter); $this->setData($this->initDefaults($request->getQuery())); }
public function wordsListAction(Request $request, Finder $finder, Filter $filterForm, ViewModel $view) { $limit = $request->getQuery('limit', 20); $page = $request->getQuery('page', 1); $view->setFilter($filterForm); $filterForm->setData($request->getQuery()); if (!$filterForm->isValid()) { return $view; } $collection = $finder->findByFilter($this->buildCriteria($filterForm->getData()), $limit, $page); $count = $finder->count($this->buildCriteria($filterForm->getData())); $view->setCollection($collection); $pageParams = $request->getQuery()->toArray(); $pageParams['countObject'] = $count; $pageParams['page'] = $page; $pageParams['limit'] = $limit; $view->setPageParams($pageParams); return $view; }
/** * @param \Zend\Http\PhpEnvironment\Request $request * @return string|null */ protected function getSessionIdFromRequest($request) { $ssid = $request->getPost(static::SESSION_ID_ALIAS); if (!$ssid) { $ssid = $request->getQuery(static::SESSION_ID_ALIAS); } if (!$ssid) { return null; } return $ssid; }
public static function createFromRequest(BaseRequest $request) { $new = static::fromString($request->toString()); $new->setQuery($request->getQuery()); $new->setPost($request->getPost()); $new->setCookies($request->getCookie()); $new->setFiles($request->getFiles()); $new->setServer($request->getServer()); $new->setContent($request->getContent()); $new->setEnv($request->getEnv()); $headers = $request->getHeaders(); $new->setHeaders($headers); return $new; }
public function getToken(Request $request) { if (isset($this->session->token)) { return true; } elseif (strlen($this->session->state) > 0 and $this->session->state == $request->getQuery('state') and strlen($request->getQuery('code')) > 5) { $client = $this->getHttpClient(); $client->setUri($this->options->getTokenUri()); $client->setMethod(Request::METHOD_POST); $client->setParameterPost(array('code' => $request->getQuery('code'), 'client_id' => $this->options->getClientId(), 'client_secret' => $this->options->getClientSecret(), 'redirect_uri' => $this->options->getRedirectUri(), 'state' => $this->getState())); $retVal = $client->send()->getContent(); parse_str($retVal, $token); if (is_array($token) and isset($token['access_token'])) { $this->session->token = (object) $token; return true; } else { $this->error = array('error' => $retVal, 'internal-error' => 'Unknown error.'); return false; } } else { $this->error = array('internal-error' => 'State error, request variables do not match the session variables.', 'session-state' => $this->session->state, 'request-state' => $request->getQuery('state'), 'code' => $request->getQuery('code')); return false; } }
/** * * {@inheritDoc} */ public function selectSite(Request $request, Response $response) { if (!$request->isGet()) { return false; } $siteId = $request->getQuery('siteId', self::ENGLISH_SITE_ID); $site = $this->siteService->find($siteId); if (!$site) { $siteId = self::ENGLISH_SITE_ID; } // Just in case $this->siteId = $siteId; $cookie = new SetCookie(self::SITE_ID_COOKIE, $siteId, time() + 30 * 24 * 60 * 60); // now + 1 month $response->getHeaders()->addHeader($cookie); return true; }
/** * Test an illegal auth method * * @return void * * @expectedException \Exception * @expectedExceptionMessage Illegal setting: foo */ public function testIllegalMethod() { $request = new Request(); $request->getQuery()->set('auth_method', 'foo'); $ca = $this->getChoiceAuth(); $ca->updatePassword($request); }
/** * Set the active strategy based on the auth_method value in the request, * if found. * * @param Request $request Request object to check. * * @return void */ protected function setStrategyFromRequest($request) { // Set new strategy; fall back to old one if there is a problem: $defaultStrategy = $this->strategy; $this->strategy = trim($request->getPost()->get('auth_method')); if (empty($this->strategy)) { $this->strategy = trim($request->getQuery()->get('auth_method')); } if (empty($this->strategy)) { $this->strategy = $defaultStrategy; if (empty($this->strategy)) { throw new AuthException('authentication_error_technical'); } } }
public function deleteAction(Request $request, Params $params, Delete $deleteService, Redirect $redirect) { $deleteService->delete((int) $params('id')); return $redirect->toRoute('admin-translate-words', [], ['query' => $request->getQuery()->toArray()]); }
/** * Attempt to authenticate the current user. Throws exception if login fails. * * @param \Zend\Http\PhpEnvironment\Request $request Request object containing * account credentials. * * @throws AuthException * @return \VuFind\Db\Row\User Object representing logged-in user. */ public function authenticate($request) { $code = $request->getQuery()->get('code'); if (empty($code)) { throw new AuthException('authentication_error_admin'); } $accessToken = $this->getAccessTokenFromCode($code); if (empty($accessToken)) { throw new AuthException('authentication_error_admin'); } $details = $this->getDetailsFromAccessToken($accessToken); if (empty($details->id)) { throw new AuthException('authentication_error_admin'); } // If we made it this far, we should log in the user! $user = $this->getUserTable()->getByUsername($details->id); if (isset($details->first_name)) { $user->firstname = $details->first_name; } if (isset($details->last_name)) { $user->lastname = $details->last_name; } if (isset($details->email)) { $user->email = $details->email; } // Save and return the user object: $user->save(); return $user; }
public function prepareParams(\Zend\Http\PhpEnvironment\Request $params, $method = 'GET') { $_params = array(); switch ($method) { case 'PUT': case 'DELETE': parse_str(file_get_contents('php://input'), $_params); array_merge($_params, $params->getPost()->toArray()); break; case 'POST': $_params = $params->getPost()->toArray(); break; default: $_params = $params->getQuery()->toArray(); break; } return $_params; }
/** * QueryStringをパースし、$_GETに上書き * @return void */ public static function parseArguments() { global $cookie, $get, $post, $method; global $defaultpage; $request = new Request(); // GET, POST, COOKIE $get = $request->getQuery(); $post = $request->getPost(); $cookie = $request->getCookie(); $method = $request->getMethod(); $vars = array(); if (strlen($get->toString()) > self::MAX_QUERY_STRING_LENGTH) { // Something nasty attack? self::dump('suspicious'); self::dieMessage(_('Query string is too long.')); } if (count($get) === 0) { // Queryがない場合 $get->set('page', $defaultpage); } else { if (count($get) === 1 && empty(array_values((array) $get)[0])) { // 配列の長さが1で最初の配列に値が存在しない場合はキーをページ名とする。 $k = trim(array_keys((array) $get)[0]); $get->set('page', rawurldecode($_SERVER['QUERY_STRING'])); unset($get[$k]); } } // 外部からの変数を$vars配列にマージする if (empty($post)) { $vars = (array) $get; // Major pattern: Read-only access via GET } else { if (empty($get)) { $vars = (array) $post; // Minor pattern: Write access via POST etc. } else { $vars = array_merge((array) $get, (array) $post); // Considered reliable than $_REQUEST } } // var_dump($vars); // die; if (!isset($vars['cmd'])) { $vars['cmd'] = 'read'; } if (isset($vars['page']) && is_string($vars['page']) && preg_match(Wiki::INVALIED_PAGENAME_PATTERN, $vars['page']) === false) { // ページ名チェック self::dump('suspicious'); die('Invalid page name.'); } if (is_string($vars['cmd']) && preg_match(PluginRenderer::PLUGIN_NAME_PATTERN, $vars['cmd']) === false) { // 入力チェック: cmdの文字列は英数字以外ありえない self::dump('suspicious'); die(sprintf('Plugin name %s is invalied or too long! (less than 64 chars)', $vars['cmd'])); } // 文字コード変換 // <form> で送信された文字 (ブラウザがエンコードしたデータ) のコードを変換 // POST method は常に form 経由なので、必ず変換する if (isset($vars['encode_hint']) && !empty($vars['encode_hint'])) { // do_plugin_xxx() の中で、<form> に encode_hint を仕込んでいるので、 // encode_hint を用いてコード検出する。 // 全体を見てコード検出すると、機種依存文字や、妙なバイナリ // コードが混入した場合に、コード検出に失敗する恐れがある。 $encode = mb_detect_encoding($vars['encode_hint']); mb_convert_variables(SOURCE_ENCODING, $encode, $vars); } else { // 全部まとめて、自動検出/変換 mb_convert_variables(SOURCE_ENCODING, 'auto', $vars); } // 環境変数のチェック self::checkEnv($request->getEnv()); switch ($method) { case Request::METHOD_POST: self::spamCheck($vars['cmd']); break; case Request::METHOD_OPTIONS: case Request::METHOD_PROPFIND: case Request::METHOD_DELETE: case 'MOVE': case 'COPY': case 'PROPPATCH': case 'MKCOL': case 'LOCK': case 'UNLOCK': // WebDAV $matches = array(); foreach (self::$ua_dav as $pattern) { if (preg_match('/' . $pattern . '/', $log_ua, $matches)) { PluginRenderer::executePluginAction('dav'); exit; } } break; } return $vars; }
/** * @return array */ public function getAllQueryParameters() { return $this->httpRequest->getQuery()->toString(); }
public function testRetrievingASingleValueForParameters() { $request = new Request(); $p = new \Zend\Stdlib\Parameters(array('foo' => 'bar')); $request->setQuery($p); $request->setPost($p); $request->setFiles($p); $request->setServer($p); $request->setEnv($p); $this->assertSame('bar', $request->getQuery('foo')); $this->assertSame('bar', $request->getPost('foo')); $this->assertSame('bar', $request->getFiles('foo')); $this->assertSame('bar', $request->getServer('foo')); $this->assertSame('bar', $request->getEnv('foo')); $headers = new Headers(); $h = new GenericHeader('foo', 'bar'); $headers->addHeader($h); $request->setHeaders($headers); $this->assertSame($headers, $request->getHeaders()); $this->assertSame($h, $request->getHeaders()->get('foo')); $this->assertSame($h, $request->getHeader('foo')); }
<?php use Zend\Http\PhpEnvironment\Request; use Zend\Http\PhpEnvironment\Response; defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'development'); chdir(dirname(__DIR__)); // Wczytujemy wcześniej zdefiniowany plik ustawień require 'phpsettings.php'; require 'vendor/autoload.php'; // Na wszelki wypadek przechwytujemy wszystkie potencjalne wyjątki try { /* @var $container Zend\ServiceManager\ServiceManager */ $container = (require 'config/container.php'); $request = new Request(); $paramPage = $request->getQuery('page'); switch ($paramPage) { case 'login': /* @var $form \Aura\Input\Form */ $form = $container->get(App\Form\LoginForm::class); if ($request->isGet()) { require 'views/login.php'; } elseif ($request->isPost()) { $data = $request->getPost()->toArray(); $form->fill($data); if ($form->filter()) { $userGateway = $container->get(App\Db\UserTableGateway::class); $result = $userGateway->fetchByEmail($request->getPost('email')); if (password_verify($request->getPost('password'), $result['password'])) { echo 'Użytkownik zalogowany prawidłowo.'; } else { echo 'Nie udało się zalogować użytkownika.';