【发布时间】:2014-02-03 09:04:10
【问题描述】:
我希望路由在成功登录后绕过身份验证过滤器。所以我使用Redirect::intended。但这会产生问题。这是我的代码
在登录控制器@doLogin
if (Auth::attempt($credentials)) {
return Redirect::intended("home.index");
}
在路线中
Route::group(array('before' => 'auth'), function() {
Route::resource('home', 'HomeController');
Route::get('/', 'HomeController');
});
我的路线
如果我在没有auth 过滤器的情况下放置主资源路由,那么它将起作用。 (不重定向到登录路径。)。该代码在下面给出
Route::resource('home', 'HomeController');
Route::group(array('before' => 'auth'), function() {
Route::get('/', 'HomeController');
}); /* No Problem with this code */
但我想使用 auth 过滤器。我使用的是 laravel 4。
请帮帮我...
【问题讨论】:
-
那么你的问题是什么?你每次都重定向到
/login? -
@Andreyco 是的,它每次都会重定向到 /login。但我不想在成功匹配用户名和密码-
(Auth::attempt($credentials))后重定向到 /login。如果我们使用Redirect::intended,它将忽略给定路由的身份验证-(auth) 过滤器。但它不适用于我的项目。 -
一切看起来都很好——你确定这不是某种cookie问题吗?如果您能够登录并点击“预期”代码行,则您的身份验证成功。如果它消失了,这听起来像是一个 cookie 问题,可能来自浏览器插件。
-
这意味着 cookie/session 是这里的问题。不知何故,您的应用程序无法保持用户登录。尝试转储所有cookie和会话,或执行
dd(Auth::user());,查看Auth::attempt($credentials);之后用户登录状态是否改变 -
@Artsemis 谢谢,这是一个会话问题。我修好了。