/** * Allow a request to proceed only if we hold a valid OAuth token * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (\App\Http\Helpers\OAuth::valid()) { return $next($request); } else { return \App\Http\Helpers\OAuth::toAuthorisationServer($request->route()->getUri()); } }
/** * Show the index that allows users to quickly register for the upcoming meal * @return View */ public function index() { $data = []; // Add more data if we have a current user if (OAuth::valid()) { $data['meals'] = Meal::available()->get(); $data['user'] = OAuth::user(); } else { $data['meals'] = Meal::available()->take(1)->get(); } return $this->setPageContent(view('register/index', $data)); }
/** * Allow a request to proceed only if we have board-level permissions * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (!App\Http\Helpers\OAuth::valid()) { App::abort(500, 'Attempted board authorization without a valid session'); } if (App\Http\Helpers\OAuth::isBoardMember()) { // Proceed with request return $next($request); } else { App::abort(403, 'Access denied: you\'re not authorized to access this'); } }
/** * Format the main navigation into proper HTML * @return string rendered HTML */ public static function show() { $output = ''; // Determine which elements to show $level = 0; if (OAuth::valid()) { $level = 1; if (OAuth::isBoardMember()) { $level = 2; } } foreach (self::$menu as $entry) { if ($level >= $entry['level']) { $entry['current'] = self::isCurrent($entry['url']); $output .= view('navigation/item')->with($entry); } } return $output; }
public static function photoURL() { // Must have a valid session if (!OAuth::valid()) { return null; } $user = self::user(); $access_token = Session::get('oauth.token')->access_token; return 'https://people.debolk.nl/persons/' . $user->username . '/photo/128/128?access_token=' . $access_token; }