/**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param \Illuminate\Routing\Router $router
  */
 public function boot(Router $router)
 {
     $router->model('album', '\\CtrlV\\Models\\Album');
     $router->model('image', '\\CtrlV\\Models\\Image');
     $router->model('session', '\\CtrlV\\Models\\UserSession');
     $router->bind('user', function ($username) {
         return \CtrlV\Models\User::whereUsername($username)->first();
     });
     parent::boot($router);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  * @throws Exception
  */
 public function handle()
 {
     $user = User::findOrFail($this->argument('userId'));
     if ($this->option('regenerate')) {
         $albums = $user->albums;
     } else {
         $albums = $user->albums()->whereNull('thumbnailImageFileId')->get();
     }
     foreach ($albums as $album) {
         \Queue::connection('sync')->push(new MakeAlbumThumbnailJob($album));
     }
 }
 /**
  * @api            {post} /sessions Start a Session (Login)
  * @apiGroup       User Sessions
  * @apiDescription Validates login credentials and returns a new session if valid.
  * @apiParam {string} username Username to login as.
  * @apiParam {string} password The user's password.
  *
  * @param PasswordHasher $passwordHasher
  *
  * @throws HttpException
  * @return \Response
  */
 public function store(PasswordHasher $passwordHasher)
 {
     $this->validate($this->request, ['username' => 'required', 'password' => 'required']);
     $username = $this->request->input('username');
     $password = $this->request->input('password');
     /** @var User $user */
     $user = User::whereUsername($username)->first();
     if (!$user) {
         throw new InputException(404, ['username' => ["Couldn't find a user with that username."]]);
     }
     if ($passwordHasher->verify($password, $user, 'password')) {
         $this->auth->setUser($user);
         // Start a new session
         $session = new UserSession(['userId' => $user->userId, 'ip' => $this->request->getClientIp()]);
         $sessionKey = $session->generateKey($passwordHasher);
         $session->save();
         return $this->response(['session' => $session, 'sessionKey' => $sessionKey, 'success' => true]);
     } else {
         throw new InputException(401, ['password' => ["That password is not correct."]]);
     }
 }
 /**
  * @api            {get} /images/{imageId} Get Image Info
  * @apiGroup       Images
  * @apiDescription Get the stored metadata for an image.
  *     <br/>If an image is anonymous the `userId` value will set to `null` unless a valid `sessionKey`
  *     for the owner of the image is given.
  * @apiUse         RequiresViewableImage
  * @apiSuccessExample {json} Success Response
  *     {
  *       "image": {
  *         "annotation": null,
  *         "batchId": null,
  *         "createdAt": "2010-05-03T07:22:35+01:00",
  *         "expiresAt": null,
  *         "image": {
  *           "createdAt": "2010-05-03T07:22:35+01:00",
  *           "directory": "img",
  *           "fileId": 1,
  *           "filename": "4bdec00b43a39.jpg",
  *           "height": 1040,
  *           "optimized": null,
  *           "size": 181,
  *           "updatedAt": null,
  *           "url": "http://img.ctrlv.in/img/4bdec00b43a39.jpg",
  *           "width": 1920
  *         },
  *         "imageId": 1,
  *         "isCropped": false,
  *         "privacy": 0,
  *         "thumbnail": {
  *           "createdAt": null,
  *           "directory": "thumb",
  *           "fileId": 663542,
  *           "filename": "4bdec00b43a39.jpg",
  *           "height": null,
  *           "optimized": false,
  *           "size": null,
  *           "updatedAt": null,
  *           "url": "http://img.ctrlv.in/thumb/4bdec00b43a39.jpg",
  *           "width": null
  *         },
  *         "title": "It's improved since this I promise",
  *         "updatedAt": null,
  *         "url": "http://ctrlv.in/1",
  *         "userId": null,
  *         "views": 1238
  *       }
  *     }
  *
  * @param Image $image
  *
  * @return Response
  */
 public function show(Image $image)
 {
     $this->requireViewableModel($image);
     $imageArray = $image->toArray();
     if ($imageArray['albumId']) {
         $imageArray['album'] = Album::find($imageArray['albumId']);
     }
     if ($imageArray['userId']) {
         $imageArray['user'] = User::find($imageArray['userId']);
     }
     return $this->response(['image' => $imageArray]);
 }
Beispiel #5
0
 /**
  * @api            {get} /users/{username}/images Get User's Images
  * @apiGroup       Users
  * @apiDescription Gets images uploaded by a user. The results are paginated with 15 results per page.
  * @apiParam {string} [sessionKey] A session key belonging to this user. Unless this is given anonymous
  *     and passworded images will be omitted.
  * @apiParam {int} [page=1] Results page number.
  * @apiUse         PaginatedImageResponse
  *
  * @param User $user
  *
  * @return Response
  */
 public function indexImages(User $user)
 {
     $this->validate($this->request, ['page' => 'int|min:1']);
     $results = $user->images()->with('imageFile')->with('thumbnailImageFile');
     if (!$this->isCurrentUser($user->getId())) {
         $results->where('anonymous', 0)->whereNull('password');
     }
     $results->orderBy('imageId', 'DESC');
     $paginator = $results->paginate($this->getResultsPerPage());
     return $this->response($this->paginatorToArray($paginator, 'images'));
 }