예제 #1
0
 /**
  * Get all users active in the last x minutes
  *
  * @param int    $minutes  The number of minutes which are considered as "online time"
  * @param string $orderBy
  * @param string $orderDir
  * @param int    $num      The number of users to return. Set to 0 to get all users
  *
  * @return mixed
  */
 public function online($minutes = 15, $orderBy = 'last_visit', $orderDir = 'desc', $num = 20)
 {
     // If the user visited the logout page as last he's not online anymore
     /** @var Builder $baseQuery */
     $baseQuery = $this->userModel->where('last_visit', '>=', new \DateTime("{$minutes} minutes ago"))->where('last_page', '!=', 'auth/logout')->orderBy('users.' . $orderBy, $orderDir);
     // No need to add anymore if the user has permission to view anyone
     if (!$this->permissionChecker->hasPermission('user', null, 'canViewAllOnline')) {
         // First get the id of our setting
         $settingId = Setting::where('name', 'user.showonline')->first()->id;
         // Now join the correct setting_values row
         $baseQuery->leftJoin('setting_values', function ($join) use($settingId) {
             $join->on('setting_values.user_id', '=', 'users.id')->where('setting_values.setting_id', '=', $settingId);
         });
         // Either the setting is true or not set...
         $baseQuery->where(function ($query) {
             $query->where('setting_values.value', true)->orWhereNull('setting_values.value');
             // ... or we're querying our row at the moment
             if ($this->guard->check()) {
                 $query->orWhere('users.id', '=', $this->guard->user()->id);
             }
         });
     }
     if ($num > 0) {
         return $baseQuery->paginate($num, ['users.*']);
     }
     return $baseQuery->get(['users.*']);
 }
예제 #2
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->check()) {
         return new RedirectResponse(url('/'));
     }
     return $next($request);
 }
예제 #3
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // The route settings aren't loaded at this point so we need to get it manually
     $options = $this->getOptions($this->router, $request);
     if ($this->isDebugBarRequest($request)) {
         return $next($request);
     }
     if (!isset($options['noOnline']) || $options['noOnline'] !== true) {
         if ($this->guard->check()) {
             $this->guard->user()->update(['last_visit' => new \DateTime(), 'last_page' => $request->path()]);
         }
     }
     return $next($request);
 }
예제 #4
0
파일: Post.php 프로젝트: Adamzynoni/mybb2
 /**
  * Check whether the current user has liked the post.
  *
  * @return bool Whether the post has been liked by the current user.
  */
 public function hasLikedPost()
 {
     if ($this->guard->check()) {
         $user = $this->guard->user();
         $containsLike = $this->wrappedObject->likes->contains(function ($key, Like $like) use(&$likes, &$numLikesToList, $user) {
             if ($like->user->id === $user->getAuthIdentifier()) {
                 return true;
             }
             return false;
         });
         return $containsLike !== false;
     }
     return false;
 }
예제 #5
0
 /**
  * Check whether the current user has permission to perform this request.
  *
  * @param Guard $guard
  *
  * @return bool
  */
 public function authorize(Guard $guard)
 {
     if (!$guard->check()) {
         return false;
     }
     // TODO: Check user permissions here...
     return true;
 }