当用户登录时,浏览器通常会重定向到仪表板页面。但是,浏览器不是显示页面,而是显示带有纯文本“重定向到:http://.......com/dashboard”并返回登录页面的白页。我已经检查了storage / logs / laravel.log中的日志文件,但一无所获。
为什么会发生这种情况?我已经阅读了很多关于此的文章,但这种奇怪的行为仍然存在 谢谢!
public function doLogin() {
//validation rule
$rules = [
'username' => 'required',
'password' => 'required'
];
$messages = [
'required' => ':attribute is required.'
];
$credentials = [
'username' => Input::get('username'),
'password' => Input::get('password')
];
$validator = Validator::make($credentials, $rules, $messages);
if ($validator->passes()) {
if (Auth::attempt(['UserID' => Input::get('username'), 'password' => Input::get('password'), 'Status' => User::ACTIVE])) {
if(checkMatrixCategory('dashboard')){
return Redirect::intended('dashboard');
}
return Redirect::intended('profile');
} else {
return Redirect::back()->withInput(Input::except('password'))->with('error', 'Wrong username/password.');
}
}
return Redirect::back()
->withErrors($validator)
->withInput(Input::except('password'));
}
我的路线:
Route::get('/', array('as' => 'home', 'uses' => 'UserController@showLogin'));
Route::post('/login', array('as' => 'user/login', 'uses' => 'UserController@doLogin'));
Route::group(array('before' => 'auth'), function() {
Route::get('/profile', array('as' => 'profile', 'uses' => 'HomeController@showProfile'));
Route::post('/profile', array('as' => 'profile', 'uses' => 'HomeController@doUpdateProfile'));
Route::group(array('before' => 'matrix'), function() {
Route::get('/dashboard', array('as' => 'dashboard', 'uses' => 'HomeController@showDashboard'));
filters.php:
Route::filter('auth', function() {
if(Auth::guest()) {
if(Request::ajax()) {
return Response::make('Unauthorized', 401);
} else {
return Redirect::guest('/');
}
}
});
Route::filter('matrix', function() {
$route = explode('/', Route::getCurrentRoute()->getPath())[0];
if(!checkMatrix($route)) {
Auth::logout();
return Redirect::route('home')->with('accessDenied','Access denied! Please call your administrator to get permissions.');
}
});
答案 0 :(得分:0)
很久以前我遇到过这个问题。经过几天的搜索,我发现当涉及到4.2版时,laravel generateSessionId 功能存在问题。 您可以在重定向期间检查是否存在多个会话文件生成。那么这是唯一的原因 你可以在这里找到这个方法 projectFOlder / vendor / laravel / framework / src / Illuminate / Session / Store.php。。行:171
protected function generateSessionId()
{
// return sha1(uniqid('', true).str_random(25).microtime(true));
return md5('Getpikk');
}
这就是我解决问题的方法。我希望它也能帮到你..