Example #1
0
 /**
  * Login form
  *
  * @html users/login
  *
  * @param Context $ctx
  * @return array
  */
 public function login(Context $ctx)
 {
     // already logged in
     if ($ctx->user) {
         return Response::redirect('/');
     }
     // keep previous location
     $referer = $ctx->request->uri->param('from');
     return ['redirect' => $referer ?: $ctx->url('/')];
 }
Example #2
0
 /**
  * Edit album details
  *
  * @access 5
  * @json
  *
  * @param int $year
  * @param int $month
  * @param int $day
  * @param string $flatname
  * @param Context $ctx
  * @return array
  * @throws NotFoundException
  */
 public function edit($year, $month, $day, $flatname, Context $ctx)
 {
     $year = (int) $year;
     $month = (int) $month;
     $day = (int) $day;
     // get album
     $album = Album::one($year, $month, $day, $flatname);
     if (!$album) {
         throw new NotFoundException();
     }
     try {
         // get form data
         list($name, $date, $meta) = $ctx->post('name', 'date', 'meta');
         list($day, $month, $year) = explode('/', $date);
         $newauthors = $ctx->post('authors');
         // update author list
         if ($newauthors and $ctx->user->isAdmin()) {
             $authors = $album->authors();
             foreach ($newauthors as $oldname => $newname) {
                 if ($oldname != $newname and isset($authors[$oldname])) {
                     $authors[$oldname]->rename($newname);
                 }
             }
         }
         // update meta
         $album->edit($meta);
         // attempt update
         $year = (int) $year;
         $month = (int) $month;
         $day = (int) $day;
         if ($name != $album->name or $year != $album->year or $month != $album->month or $day != $album->day) {
             $oldalbum = $album->fullname;
             $album->rename($year, $month, $day, $name);
             $ctx->logger->info($ctx->user->username . ' edits album "' . $oldalbum . '" to "' . $album->fullname . '"', $_POST);
         }
         return ['state' => true, 'redirect' => (string) $ctx->url($album->url)];
     } catch (AuthorAlreadyExists $e) {
         return ['state' => false, 'message' => text('logic.author.already-exists')];
     } catch (AlbumAlreadyExists $e) {
         return ['state' => false, 'message' => text('logic.album.already-exists')];
     } catch (InvalidAlbumDate $e) {
         return ['state' => false, 'message' => text('logic.album.invalid-date')];
     } catch (InvalidAlbumName $e) {
         return ['state' => false, 'message' => text('logic.album.invalid-name')];
     } catch (\Exception $e) {
         return ['state' => false, 'message' => text('logic.album.cannot-edit')];
     }
 }