Ejemplo n.º 1
0
 /**
  * User logout
  *
  * @param Request $request
  * @param Response $response
  * @return Response
  */
 public function logout(Request $request = null, Response $response = null)
 {
     $app = $this->app($request);
     $user = new UserSession($app);
     $user->logout($app);
     return $app->http->redirectBase('/login');
 }
Ejemplo n.º 2
0
 /**
  * Check user session login
  *
  * @param Request $request
  * @param Response $response
  * @return bool|Response
  */
 public static function check(Request $request, Response $response, $action, $callback)
 {
     /* @var $app AppContainer */
     $app = $request->getAttribute(\App\Middleware\AppMiddleware::ATTRIBUTE);
     if (!static::isAuthRequired($app, $action)) {
         return true;
     }
     $userSession = new UserSession($app);
     if ($userSession->isValid()) {
         return true;
     } else {
         $http = new \App\Util\Http($request, $response);
         if ($http->isJsonRpc()) {
             $json = new \App\Util\JsonServer($request, $response);
             $jsonContent = $json->getResponseByError('Unauthorized', 0, 0, 401);
             return $jsonContent;
         } else {
             $uri = $app->http->getBaseUrl('/login');
             return new RedirectResponse($uri);
             // alternative would be
             // new HtmlResponse('401 Unauthorized', 401);
         }
     }
     return true;
 }