Пример #1
0
 /**
  * 401
  *
  * @html errors/accessdenied
  *
  * @param AccessDeniedException $event
  * @param Context $ctx
  * @return Response\Redirect
  */
 public function accessDenied(AccessDeniedException $event, Context $ctx)
 {
     // not logged in
     if (!$ctx->user) {
         $path = $ctx->request->uri->path;
         $from = ($path and $path != '/') ? '?from=' . $path : null;
         return Response::redirect('/login' . $from);
     }
 }
Пример #2
0
 /**
  * Send response
  *
  * @return string
  */
 public function send()
 {
     $this->content = file_get_contents($this->filename);
     parent::send();
     exit;
 }
Пример #3
0
 /**
  * Download album as .zip
  *
  * @param int $year
  * @param int $month
  * @param int $day
  * @param string $flatname
  * @return Response\Download
  *
  * @throws HttpException
  * @throws NotFoundException
  */
 public function download($year, $month, $day, $flatname)
 {
     $year = (int) $year;
     $month = (int) $month;
     $day = (int) $day;
     // get album
     $album = Album::one($year, $month, $day, $flatname);
     if (!$album) {
         throw new NotFoundException();
     }
     try {
         // create zip file
         $zipname = $album->zip();
         $ctx->logger->info($ctx->user->username . ' downloads "' . $album->fullname . '"');
         return Response::download($zipname)->header('Content-Type', 'application/zip');
     } catch (\Exception $e) {
         throw new HttpException();
     }
 }
Пример #4
0
 /**
  * Terminate context
  *
  * @return string
  */
 public function end()
 {
     return $this->response->send();
 }
Пример #5
0
 /**
  * Log out user
  *
  * @param Context $ctx
  * @return Response\Redirect
  */
 public function logout(Context $ctx)
 {
     Auth::logout();
     $ctx->logger->info($ctx->user->username . ' logs out');
     return Response::redirect('/login');
 }
Пример #6
0
 /**
  * Send response
  *
  * @return string
  */
 public function send()
 {
     $this->header('Location', $this->uri);
     parent::send();
     exit;
 }
Пример #7
0
 /**
  * New JSON Response
  *
  * @param string $content
  * @param int $code
  * @param array $headers
  */
 public function __construct($content = null, $code = 200, array $headers = [])
 {
     $content = json_encode($content, JSON_PRETTY_PRINT);
     parent::__construct($content, $code, $headers);
 }
Пример #8
0
 /**
  * New Template Response
  *
  * @param string $template
  * @param array $vars
  * @param int $code
  * @param array $headers
  */
 public function __construct($template, array $vars = [], $code = 200, array $headers = [])
 {
     parent::__construct(null, $code, $headers);
     $this->template = $template;
     $this->vars = $vars;
 }