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("/"); }
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]; }