/** * Login handler * * @param Request $request * @param Response $response * @param array $args * * @return Response */ public function processLogin(Request $request, Response $response, array $args) { $subject = ['username' => $request->request->get('username'), 'password' => $request->request->get('password')]; $this->sessionAuth->login($subject); $returnUri = $request->query->get('uri', $request->attributes->get('stack.url_map.prefix', '/')); return new RedirectResponse($returnUri); }
/** * {@inheritdoc} */ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) { $route = $request->getPathInfo(); // We have an active login if ($this->sessionAuth->check()) { switch ($route) { case '/login': $returnUri = $request->query->get('uri', $request->attributes->get('stack.url_map.prefix', '/')); return new RedirectResponse($returnUri); break; case '/logout': $this->sessionAuth->logout(); return new RedirectResponse($request->attributes->get('stack.url_map.prefix', '/')); break; default: $caller = $this->sessionAuth->getCurrentCaller(); $request->attributes->set('stack.authn.token', $caller->getLoginToken()); if ($this->options['delegateCaller']) { $request->attributes->set('stack.authn.caller', $caller); } break; } } elseif ($route !== '/login') { $routePrefix = $request->attributes->get('stack.url_map.prefix', ''); $fullRoute = $request->server->get('PATH_INFO', '/'); return new RedirectResponse(sprintf('%s/login?uri=%s', $routePrefix, $fullRoute)); } return $this->app->handle($request, $type, $catch); }