/** * Attempt to show a user's profile * * @param $slug * @param $id * @return Response */ public function showProfile($slug, $id) { if (!$slug || !$id) { // We don't have a user slug, what should we do? if (Auth::check()) { $user = Auth::user(); $user->update(array('last_active_desc' => 'Viewing ' . $user->name . '\'s profile')); return view('core.user.profile', ['user' => Auth::user()]); } else { return redirect()->to('/'); } // Somehow none of the above conditions return true... // so we just redirect to the home page if this happens. return redirect()->to('/'); } else { $user = User::where('slug', '=', $slug)->where('id', '=', $id)->first(); // doing first() just in case there are somehow two users with the same ID... if ($user == null || !$user) { return view('core.errors.modelnotfound'); } if ($user->isBanned()) { return view('core.errors.profilenotavailable', array('user' => $user)); } return view('core.user.profile', ['user' => $user]); } }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { $name_or_email = $this->input('name_or_email'); $password = $this->input('password'); $db_field = filter_var($name_or_email, FILTER_VALIDATE_EMAIL) ? 'email' : 'name'; $user = User::where($db_field, '=', $name_or_email)->first(); if ($db_field == 'name') { $name_change = NameChange::where('old_name', '=', $name_or_email)->first(); if ($name_change != null) { // Username used to be the input, but it was changed Flash::error('It seems like you\'re trying to log in with a username that has changed. Please use your new username.'); return false; } } if ($user == null || !$user) { Flash::error('User not found'); return false; } if (!Hash::check($password, $user->password)) { Flash::error('Invalid password'); return false; } if (Auth::attempt([$db_field => $name_or_email, 'password' => $password], $this->has('remember'))) { return true; } else { Flash::error('You could not be logged in due to an unknown error.'); return false; } return false; }
/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { if (Schema::hasTable('migrations') && Schema::hasTable('users')) { $banned = User::banned()->get(); $all = User::all(); $schedule->call(function () use($banned) { foreach ($banned as $u) { if ($u->banned_until != null) { if ($u->banned_until < Carbon::now()->toDateTimeString()) { $u->update(array('is_banned' => 0, 'banned_until' => null)); } } } })->when(function () use($banned) { return $banned->count() > 0; })->cron('* * * * *'); $schedule->call(function () use($all) { $now = Carbon::now(); $now->subMinutes(15); // A user is offline if they do nothing for 15 minutes foreach ($all as $u) { if ($u->last_active != null && $u->last_active < $now->toDateTimeString()) { $u->update(array('is_online' => 0)); } } })->when(function () use($all) { return $all->count() > 0; })->cron('* * * * *'); } }
/** * Show a list of members. * * @return mixed */ public function showMembers() { $users = User::orderBy('name', 'asc')->get(); $users = $users->filter(function ($item) { // Only show if the user is not banned and they have confirmed // their account. This is to prevent spambot clutter. return !$item->isBanned() && $item->isConfirmed(); }); return view('core.forum.members', compact('users')); }
/** * Creates a new message thread * * @return mixed */ public function create() { $users = User::where('id', '!=', Auth::id())->get(); $names = User::where('id', '!=', Auth::id())->lists('name', 'id'); return view('core.conversations.create', compact('users', 'names')); }
/** * Determine if current user follows another user. * * @param User $otherUser * @return bool */ public function isFollowedBy(User $otherUser) { $idsWhoOtherUserFollows = $otherUser->followedUsers()->lists('followed_id'); return in_array($this->id, $idsWhoOtherUserFollows); }
/** * Check to see if this object is liked by a user. * * @param User $user * @return boolean */ public function isLikedBy(User $user) { return in_array($user->getId(), $this->likes()->lists('user_id')); }
/** * Bootstrap any application services. * * @return void */ public function boot() { // // Set up the view composers view()->composer('core.partials.layouts.master', function ($view) { $site_title = Setting::where('name', '=', 'sitename')->first(); $site_theme = Setting::where('name', '=', 'bootswatch_theme')->first(); $navbar_style = Setting::where('name', '=', 'navbar_style')->first(); $recaptcha_enabled = Setting::where('name', '=', 'recaptcha')->first(); $view->with('recaptcha_enabled', $recaptcha_enabled != null ? $recaptcha_enabled->value : '0'); $view->with('site_title', $site_title != null ? e($site_title->value) : 'Fetch404'); $view->with('theme_id', $site_theme != null ? e($site_theme->value) : '1'); $view->with('navbar_style', $navbar_style != null ? e($navbar_style->value) : '0'); if (Auth::check()) { $user = Auth::user(); $view->with('user', $user); $notifications = $user->notifications; $notifications = $notifications->sortByDesc(function ($item) { return $item->created_at; }); $notifications = $notifications->filter(function ($item) { return time() - strtotime($item->created_at) < 60 * 60 * (24 * 3); }); $view->with('notifications', $notifications->take(5)); $messages = Thread::forUserWithNewMessages($user->id)->get(); $messages = $messages->sortByDesc(function ($item) { return $item->created_at; }); $messages = $messages->filter(function ($item) use($user) { return time() - strtotime($item->created_at) < 60 * 60 * (24 * 3) && $item->isUnread($user->id); }); $view->with('messages', $messages); if ($user->can('viewReports')) { $reports = Report::all(); $reports = $reports->sortByDesc(function ($item) { return $item->updated_at; }); $reports = $reports->filter(function ($item) { return !$item->isClosed(); }); $view->with('reports', $reports); } } }); view()->composer('core.admin.layouts.default', function ($view) { $site_title = Setting::where('name', '=', 'sitename')->first(); $site_theme = Setting::where('name', '=', 'bootswatch_theme')->first(); $navbar_style = Setting::where('name', '=', 'navbar_style')->first(); $view->with('site_title', $site_title != null ? e($site_title->value) : 'Fetch404'); $view->with('theme_id', $site_theme != null ? e($site_theme->value) : '1'); $view->with('navbar_style', $navbar_style != null ? e($navbar_style->value) : '0'); $user = Auth::user(); $view->with('user', $user); if ($user->can('viewReports')) { $reports = Report::all(); $reports = $reports->sortByDesc(function ($item) { return $item->updated_at; }); $reports = $reports->filter(function ($item) use($user) { return !$item->isClosed(); }); $view->with('reports', $reports); } }); view()->composer('core.admin.general', function ($view) { $site_title = Setting::where('name', '=', 'sitename')->first(); $site_theme = Setting::where('name', '=', 'bootswatch_theme')->first(); $navbar_style = Setting::where('name', '=', 'navbar_style')->first(); $recaptcha_enabled = Setting::where('name', '=', 'recaptcha')->first(); $recaptcha_key = Setting::where('name', '=', 'recaptcha_key')->first(); $view->with('site_title', $site_title != null ? e($site_title->value) : 'Fetch404'); $view->with('theme_id', $site_theme != null ? e($site_theme->value) : '1'); $view->with('navbar_style', $navbar_style != null ? e($navbar_style->value) : '0'); $view->with('recaptcha_enabled', $recaptcha_enabled != null ? $recaptcha_enabled->value == 'true' ? 'true' : 'false' : 'false'); $view->with('recaptcha_key', $recaptcha_key != null ? e($recaptcha_key->value) : ''); }); view()->composer('core.admin.index', function ($view) { $date = new Carbon(); $date->subWeek(); $users = User::where('created_at', '>', $date->toDateTimeString())->get(); $view->with('latest_users', $users); $view->with('roles', Role::all()); }); view()->composer('core.admin.partials.sidebar', function ($view) { $user = Auth::user(); if ($user->can('viewReports')) { $reports = Report::all(); $reports = $reports->sortByDesc(function ($item) { return $item->updated_at; }); $reports = $reports->filter(function ($item) use($user) { return !$item->isClosed(); }); $view->with('reports', $reports); } }); view()->composer('core.auth.register', function ($view) { $recaptcha_enabled = Setting::where('name', '=', 'recaptcha')->first(); $recaptcha_key = Setting::where('name', '=', 'recaptcha_key')->first(); $view->with('recaptcha_enabled', $recaptcha_enabled != null ? $recaptcha_enabled->value == 'true' ? 'true' : 'false' : 'false'); $view->with('recaptcha_key', $recaptcha_key != null ? e($recaptcha_key->value) : ''); }); view()->composer('core.forum.partials.latest-threads', function ($view) { $threads = Topic::all()->take(5); $threads = $threads->filter(function ($item) { return $item != null && $item->channel != null && $item->channel->category != null && $item->channel->category->canView(Auth::user()) && $item->channel->canView(Auth::user()); }); $threads = $threads->sortByDesc(function ($item) { return $item->getLatestPost()->created_at; }); $view->with('threads', $threads); }); view()->composer('core.forum.partials.online-users', function ($view) { $online = User::where('is_online', '=', 1)->orderBy('name', 'asc')->get(); $view->with('users', $online); }); view()->composer('core.forum.partials.stats', function ($view) { $users = User::all(); $latestUser = User::latest('created_at')->first(); $view->with('users', $users); $view->with('latestUser', $latestUser); }); view()->composer('core.forum.partials.latest-statuses', function ($view) { $statuses = ProfilePost::latest('created_at')->take(5); $statuses = $statuses->filter(function (ProfilePost $item) { return !$item->toUser->isBanned(); }); $statuses = $statuses->sortByDesc(function ($item) { return $item->getLatestPost()->created_at; }); $view->with('statuses', $statuses); }); }