微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 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/forum并且未进行身份验证,则应将其发送至accounts.domain.com,登录,然后重定向回论坛.

但现在我有两个问题.
1和主要问题:登录后,用户只对该域进行了认证:accounts.domain.com
对于所有其他域,他被重定向登录.
如果用户是autenticated并尝试访问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(<用户应该登陆的地方>).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐