В этом конкретном случае учетные данные моего пользователя хранятся в браузере. Путь по умолчанию для перенаправления на пост-вход в систему - «/dashboard».
Если пользователь входит в систему, а затем выходит из системы, он перенаправляется на страницу входа (как и должно быть). Затем, если вместо нажатия кнопки «Войти» с предварительно заполненными учетными данными они решат перейти по URL-адресу и добавить «/ dashboard» (предположим, что они знали путь), Laravel зарегистрирует их и перенесет их туда. Пользователь должен войти в систему для доступа к / dashboard.
После запуска многих тестов это происходит только тогда, когда учетные данные пользователя сохраняются в браузере. Этот браузер или Laravel пытаются помочь? Мне кажется, что это неправильное поведение.
Я пытался использовать logout как метод GET и POST. И следующее в LoginController:
/**
* Validate the user login request.
*
* @param \Illuminate\Http\Request $request
* @return void
*
* @throws \Illuminate\Validation\ValidationException
*/
protected function validateLogin(Request $request)
{
$data = $request->all();
$validationList = [
'email' => 'required|string',
'password' => 'required|string',
];
$validator = Validator::make($data, $validationList);
if ($validator->fails())
{
return redirect()->back()->withErrors($validator->errors());
}
}
/**
* Handle a login request to the application.
* @param Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|void
* @throws ValidationException
*/
public function login(Request $request)
{
Log::emergency('login');
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
if ($this->attemptLogin($request))
{
return $this->sendLoginResponse($request);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
/**
* Get the failed login response instance.
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
protected function sendFailedLoginResponse(Request $request)
{
return redirect()->back()->withErrors(new MessageBag([
'password' => 'The email or password you entered is incorrect.',
]));
}
/**
* The user has been authenticated.
*
* @param \Illuminate\Http\Request $request
* @param mixed $user
* @return mixed
*/
protected function authenticated(Request $request, $user)
{
if (strpos(\session('url.intended'), '/logout') !== FALSE)
\session()->forget('url.intended');
$homeGuard = new HomeController();
$arguments = $homeGuard->getUserRoles();
if ($arguments['roles']->count() == 1) session(['userRole'=> $arguments['roles']->first()->Role]);
else return $homeGuard->chooseRoleView($arguments);
}
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/dashboard';
public function __construct()
{
$this->middleware('guest', ['except' => [
'logout',
'getLogout',
'otc.logout',
]]);
}
/**
* Log the user out of the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function logout(Request $request)
{
Log::emergency('logged out');
Auth::logout();
$request->session()->flush();
return $this->loggedOut($request) ?: redirect()->guest('/login');
}
/**
* The user has logged out of the application.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
protected function loggedOut(Request $request)
{
\auth()->logout();
return redirect()->guest('/login');
}
Как и ожидалось, пользователь «вышел», когда Laravel вернет представление входа в систему. Кто-нибудь знает, что может быть причиной такого поведения?