/** * 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); } }
/** * Send response * * @return string */ public function send() { $this->content = file_get_contents($this->filename); parent::send(); exit; }
/** * 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(); } }
/** * Terminate context * * @return string */ public function end() { return $this->response->send(); }
/** * 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'); }
/** * Send response * * @return string */ public function send() { $this->header('Location', $this->uri); parent::send(); exit; }
/** * 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); }
/** * 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; }