/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { $as = $request->input('_as'); if ($this->authorize() && !is_null($as)) { $this->auth->loginUsingId($as); return $this->response->redirectTo($request->url()); } return $next($request); }
/** * Response on authorized request. * * @param \Illuminate\Http\Request $request * * @return mixed */ protected function responseOnUnauthorized($request) { if ($request->ajax()) { return $this->response->make('Unauthorized', 401); } $type = $this->auth->guest() ? 'guest' : 'user'; $url = $this->config->get("orchestra/foundation::routes.{$type}"); return $this->response->redirectTo($this->foundation->handles($url)); }
/** * Get all possible user roles. * * @return array */ protected function getUserRoles() { if (!is_null($this->userRoles)) { return $this->userRoles; } elseif (!$this->auth->guest()) { return $this->auth->roles(); } return $this->roles->has('guest') ? ['guest'] : []; }
/** * Check whether the menu should be displayed. * * @param \Orchestra\Contracts\Auth\Guard $auth * * @return bool */ public function authorize(Guard $auth) { return !$auth->guest(); }
/** * Get user. * * @return \Orchestra\Model\User|null */ protected function getUser() { return $this->auth->getUser(); }