guest()) { Session::put('backurl', URL::full()); Session::save(); return Redirect::action('UserController@getLogin'); } // log debug info about the user and his request $url = $request->getRequestUri(); $method = $request->getMethod(); $current_user = Auth::user(); Log::debug ( sprintf ( "Authenticate::handle method %s url %s current user %s (%s) groups %s", $method, $url, $current_user->getEmail(), $current_user->getId(), $current_user->getGroupsNice() ) ); // An XHR that expects JSON must reach its controller: the first // authenticated request after a deep-link sign-in would otherwise be // answered with a 302 to backurl, and the caller would read an HTML page // instead of its JSON (e.g. the recovery-code enrollment call made by // the login page). backurl stays in the session for the real navigation. if ($request->expectsJson()) { return $next($request); } $redirect = Session::get('backurl'); if (!empty($redirect)) { Session::forget('backurl'); Session::save(); Log::debug ( sprintf ( "Authenticate::handle method %s url %s current user %s (%s) groups %s redirecting to %s", $method, $url, $current_user->getEmail(), $current_user->getId(), $current_user->getGroupsNice(), $redirect ) ); return Redirect::to($redirect); } return $next($request); } }