Php Laravel 4身份验证不适用于子域
在我的L4应用程序中,我使用子域路由到不同的东西Php Laravel 4身份验证不适用于子域,php,laravel,laravel-4,Php,Laravel,Laravel 4,在我的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/f
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
}
谢谢您的帮助。将
app/config/session.php
中的域设置为.domain.com
,这样子域之间可以共享会话
要重定向用户,可以在会话配置文件中返回redirect::back()
或redirect::route()
,将'.mydomain.com'
放在域
键中。返回redirect::designed('foo/bar')
将您带到您要去的地方,如果您不想去其他任何地方,则默认为foo/bar
。我想在该设置中使用任何TLD,那么我如何才能做到这一点?我尝试了一个通配符('domain'=>'.domain.{tld}'
),但它不是这样工作的。