/**
  * Checking user authentication.
  *
  * @param  int $id
  * @return int | bool
  */
 private function checkAuth($id)
 {
     if (!Auth::guest()) {
         return Votes::where('image_id', $id)->where('user_id', Auth::user()->id)->count();
     } else {
         return false;
     }
 }
예제 #2
0
 /**
  * Voting on current image with Ajax.
  *
  * @param  string $imageId
  * @param  int $voteChoice
  * @return json Response json with success - true or false, and message.
  */
 public function vote($imageId, $voteChoice)
 {
     if (Auth::guest()) {
         return Response::json(array('success' => false, 'message' => 'You must be logged in to vote!'));
     } else {
         $vote = Votes::where('image_id', $imageId)->where('user_id', Auth::user()->id)->count();
         if ((int) $vote !== 0) {
             return Response::json(array('success' => false, 'message' => 'You already voted!'));
         } else {
             Votes::insertVote($imageId, $voteChoice);
             return Response::json(array('success' => true, 'message' => 'Thank you for voting!'));
         }
     }
 }
예제 #3
0
| response will be issued if they are, which you may freely change.
|
*/
Route::filter('guest', function () {
    if (Auth::check()) {
        return Redirect::to('/');
    }
});
/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function () {
    if (Session::token() != Input::get('_token')) {
        throw new Illuminate\Session\TokenMismatchException();
    }
});
/**
 * Composer views
 */
View::composer('layouts.master', function ($view) {
    if (!Auth::guest()) {
        $view->with('notifications', Votes::where('user_id', '<>', Auth::user()->id)->where('notification', 1)->get());
    }
});
예제 #4
0
 /**
  * Notification query.
  *
  * @param  int $type
  * @return mixed
  */
 private function notification($type)
 {
     return Votes::where('user_id', '<>', Auth::user()->id)->where('notification', $type)->get();
 }