【发布时间】:2014-03-10 00:15:05
【问题描述】:
在我的 L4 应用程序中,我使用子域来路由到不同的东西。
accounts.domain.com = where alle the Authentication stuff happens
dashboard.domain.com = The main frontpage for authenticated users
community.domain.com = Community stuff for authenticated users.
如果有人访问 community.domain.com/forum 并且未通过身份验证,他应该被发送到 accounts.domain.com,登录然后被重定向回论坛。
但现在我有两个问题。 1和主要问题:登录后,用户仅对域进行身份验证:accounts.domain.com 对于所有其他域,他会被重定向到登录。 如果用户通过身份验证并尝试访问 dashboard.domain.com,他会被重定向到登录页面。
2.问题是登录后的重定向。 Atm 我在登录后只有一个静态重定向,不管用户来自哪里。我该如何更改它,以便他被重定向回他之前尝试以未经身份验证的用户身份访问的页面? 我的路线文件:
Route::get('login', function()
{
return Redirect::action('AccountsController@getLogin');
});
Route::group(array('domain' => 'accounts.domain.com'), function()
{
Route::get('/', function()
{
return Redirect::action('AccountsController@getLogin');
});
Route::get('users/sing_in', array('as' => 'login', 'uses' => 'AccountsController@getLogin'));
Route::post('users/sing_in', array('as' => 'login', 'uses' => 'AccountsController@doLogin'));
Route::get('users/sing_out', array('as' => 'logout', 'uses' => 'AccountsController@doLogout'));
Route::group(array('before' => 'auth'), function() {
Route::get('users/profile', array('as' => 'profile', 'uses' => 'AccountsController@getProfile'));
});
});
Route::group(array('domain' => 'dashboard.domain.com'), function()
{
Route::group(array('before' => 'auth'), function() {
Route::get('/', array('as' => 'dashhome', 'uses' => 'DashboardController@getIndex')); //If someone tries to access this, he get redirected to the login page, even if he just authenticated himself
});
});
还有我的登录控制器:
public function getLogin()
{
if (Auth::check()) {
return Redirect::action('AccountsController@getProfile');
} else {
return View::make('login.index');
}
}
public function doLogin()
{
$rules = array(
'email' => 'required|email',
'password' => 'required|min:3'
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::route('login')
->withErrors($validator)
->withInput(Input::except('password'));
} else {
$userdata = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
if (Auth::attempt($userdata)) {
return Redirect::action('AccountsController@getProfile');
} else {
return Redirect::route('login')->withErros('Wrong E-mail address or Password');
}
}
}
public function doLogout()
{
Auth::logout(); // log the user out of our application
return Redirect::route('login'); // redirect the user to the login screen
}
感谢您的帮助。
【问题讨论】:
-
在会话配置文件中,将
'.mydomain.com'放入domain键中。 -
return Redirect::intended('foo/bar');将您带到您想去的地方,如果您不想去其他地方,则默认为foo/bar。