protected function post(Request $request) { $application = $this->getApplication(); $params = $request->getDataParams(); if (!$params->has("username")) { return $application->httpError400("A username must be provided"); } if (!$params->has("password")) { return $application->httpError400("A password must be provided"); } $auth = $application->getServices()->get("auth"); try { $token = $auth->signIn($params->get("username"), $params->get("password")); } catch (\InvalidArgumentException $exception) { return $application->httpError401("Invalid username or password"); } return $application->redirect("/"); }
public function handle(Request $request) { $method = $request->getMethod(); $supportedMethods = [Request::METHOD_HEAD, Request::METHOD_GET, Request::METHOD_POST, Request::METHOD_PUT, Request::METHOD_DELETE]; if (!in_array($method, $supportedMethods)) { $logger = $this->getApplication()->getServices()->get("logger"); if (null !== $logger) { $logger->warn("Invalid request method: {$method}"); } $method = Request::METHOD_GET; } $handler = mb_strtolower($method); $response = $this->before($request); if ($response instanceof Response) { return $response; } $response = $this->{$handler}($request); $this->after($request, $response); return $response; }
protected function createRequestPanel(Request $request, HtmlResponse $response) { $sources = [["label" => "Query", "params" => $request->getQueryParams()], ["label" => "Data", "params" => $request->getDataParams()], ["label" => "Cookies", "params" => $request->getCookies()], ["label" => "Server", "params" => $request->getServerParams()]]; $counter = 0; $content = ' <table> '; foreach ($sources as $source) { $count = count($source["params"]); $counter += $count; $content .= ' <tr> <th colspan="2">' . $response->esc($source["label"]) . '</th> </tr> '; if ($count > 0) { foreach ($source["params"] as $key => $value) { $content .= ' <tr> <td class="panadas-text-right">' . $response->esc($key) . '</td> <td class="panadas-text-info" width="100%">' . $response->esc($value) . '</td> </tr> '; } } else { $content .= ' <tr> <td></td> <td class="panadas-text-muted">No parameters provided</td> </tr> '; } } $content .= ' </table> '; return ["label" => "Request", "counter" => $counter, "content" => $content]; }
public function authenticate(Request $request) { $token = $request->getHeaders()->get($this->getHeaderName(), $request->getCookies()->get($this->getCookieName())); if (null !== $token) { $handler = $this->getHandler(); $handler->gc(); if (null !== $handler->retrieve($token)) { $handler->update($token, new \DateTime()); $this->setToken($token); } else { $this->destroy(); } } return $this; }