public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     $registration = $this->service->registrationPath();
     $logout = $this->service->logoutPath();
     $login = $this->service->loginPath();
     $base = $this->service->basePath();
     $uri = $request->getUri();
     $path = $uri->getPath();
     if ($path === $logout) {
         $this->service->clearIdentity();
         // including the user session
         return $this->redirectTo($uri->withPath($login));
     }
     // Disallow to render the view (by default) if not authenticated
     if (!$this->service->hasIdentity()) {
         switch ($path) {
             case $login:
                 return $next($request, $response);
             case $registration:
                 return $next($request, $response);
             default:
                 return $this->redirectTo($uri->withPath($login));
         }
     }
     switch ($path) {
         case $login:
             return $this->redirectTo($uri->withPath($base));
         case $registration:
             return $this->redirectTo($uri->withPath($base));
     }
     return $next($request, $response);
 }
 /**
  * 
  * @return Response
  */
 public function indexAction()
 {
     if (!is_null($this->identity())) {
         $this->authenticationService->clearIdentity();
     }
     return $this->redirect()->toRoute($this->loginRoute);
 }
Example #3
0
 public function __invoke(ServerRequestInterface $req, Response $res)
 {
     if ($this->authService->hasIdentity()) {
         $identity = $this->authService->getIdentity();
         $events = $this->events;
         $this->authService->clearIdentity();
         $events('trigger', 'logout', $identity, $this->redirectUrl);
     }
     return $res->withRedirect($this->redirectUrl);
 }
Example #4
0
 private function logoutAndRediret(Response $res, $message)
 {
     $this->authService->clearIdentity();
     $this->flash->addMessage('danger', $message);
     return $res->withRedirect($this->unitNotFoundRedirectUrl);
 }
Example #5
0
 public function logout()
 {
     $this->authenticationService->clearIdentity();
 }
Example #6
0
 /**
  * Logout and destroy user's session.
  */
 public function logout()
 {
     $this->authService->clearIdentity();
     session_regenerate_id();
     session_destroy();
 }