renderer = $renderer; $this->auth = $auth; $this->router = $router; $this->session = $session; $this->userTable = $userTable; } public function __invoke(ServerRequestInterface $request) { $params = $request->getParsedBody(); $user = $this->auth->login($params['username'], $params['password']); if ($user) { if(!isset($_SESSION)) { session_start(); } $_SESSION['role'] = $this->userTable->findRole($params['username']); $_SESSION['user'] = $params['username']; $path = $this->session->get('auth.redirect') ?: $this->router->generateUri('gmarche.index'); $this->session->delete('auth.redirect'); return new RedirectResponse($path); } else { (new FlashService($this->session))->error('Identifiant ou mot de passe incorrect'); return $this->redirect('auth.login'); } } }