成功登录后重定向

时间:2016-08-10 00:55:54

标签: php laravel authentication redirect login

我的用户希望注册以获取用户。第一个布局用于注册该事件。但我的用户已经有了一个帐户,并选择了一个自动引导他进入登录路线的选项。在他成功认证之后,我想将他重定向到我的付款表单。通常,我的成功验证会返回我的用户个人资料。我想保持该流,除非用户正在注册此活动。我的项目是Laravel 4.2 。我可以使用令牌或其他内容吗?有什么选择吗?

这是 AuthRepository 功能:

class AuthRepository implements AuthRepositoryInterface {

    private $messageBag;
    private $errors;

    public function __construct(MessageBag $messageBag) {
        $this->messageBag = $messageBag;
    }

public function postLogin() {

        $remember_me = (Input::get('remember_me') == 1 ? true : false);

        try
        {
            // Login credentials
            $credentials = array(
                'email'    => Input::get('email'),
                'password' => Input::get('password'),
            );

            // Authenticate the user
            $user = \Sentry::authenticate($credentials, $remember_me);

            // Redirect to homepage
            return Redirect::route('profile')->with('success' , trans('users::success.login_success'));

        }
        catch (\Cartalyst\Sentry\Users\LoginRequiredException $e)
        {
            //echo 'Login field is required.';
            $this->setErrors('email' , trans('users::users.login_field_is_required'));
            return Redirect::back()->withInput()->withErrors($this->getErrors());
        }
        catch (\Cartalyst\Sentry\Users\PasswordRequiredException $e)
        {
            //echo 'Password field is required.';
            $this->setErrors('password' , trans('users::users.password_field_is_required') );
            return Redirect::back()->withInput()->withErrors($this->getErrors());
        }
        catch (\Cartalyst\Sentry\Users\WrongPasswordException $e)
        {
            //echo 'Wrong password, try again.';
            $this->setErrors('password' , trans('users::users.wrong_password') );
            return Redirect::back()->withInput()->withErrors($this->getErrors());
        }
        catch (\Cartalyst\Sentry\Users\UserNotFoundException $e)
        {
            //echo 'User was not found.';
            $this->setErrors('email' , trans('users::users.user_was_not_found') );
            return Redirect::back()->withInput()->withErrors($this->getErrors());
        }
        catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e)
        {
            //echo 'User is not activated.';
            $this->setErrors('email' , trans('users::users.user_is_not_activated') );
            return Redirect::back()->withInput()->withErrors($this->getErrors());
        }

        // The following is only required if the throttling is enabled
        catch (\Cartalyst\Sentry\Throttling\UserSuspendedException $e)
        {
            //echo 'User is suspended.';
            $this->setErrors('email' , trans('users::users.user_is_suspended') );
            return Redirect::back()->withInput()->withErrors($this->getErrors());
        }
        catch (\Cartalyst\Sentry\Throttling\UserBannedException $e)
        {
            //echo 'User is banned.';
            $this->setErrors('email' , trans('users::users.user_is_banned') );
            return Redirect::back()->withInput()->withErrors($this->getErrors());
        }

    }


}

我的 AuthController

namespace \Users\Controllers;

use \Users\Repositories\AuthRepository;


class AuthController extends \BaseController {

    protected $auth;


    public function __construct(AuthRepository $auth) {
        $this->auth = $auth;
    }

    public function login() {
        return $this->auth->login();
    }

    public function postLogin() {
        return $this->auth->postLogin();
    }

    public function logout() {
        return $this->auth->logout();
    }
} 

我的路线

Route::get( '/login' ,                              array( 'as' => 'login' , 'uses' => 'HomeController@userLogin' ) );
Route::post('/login' ,                              array( 'as' => 'postLogin' , 'uses' => '\Users\Controllers\AuthController@postLogin' ) );

最终我想要重定向到:

Route::get('/fee/{id}/register/'  ,                 array( 'as' => 'frontend.fee.registration' ,    'uses' => 'FeeController@feeRegistration' ) );

1 个答案:

答案 0 :(得分:2)

在登录身份验证中抓取您之前的网址。如果注册成功,请重定向到以前的URL。检查过程是否在先前的URL中完成并重定向到付款表单。您的请求对象应具有以前的URL。