douding7189
douding7189
2017-02-14 07:05
浏览 58
已采纳

Laravel 5.2:失败后将用户重定向到登录页面

How should i redirect user to login page after a failed login? i tried in AuthController :

  protected $redirectTo ='/login';
protected $loginView = 'auth.login_register_form';
protected $loginPath = '/login';

but user does not redirected to /login page , he get redirected back to the page he was in before
of curse there is a method in AuthenticateUser.php that serve as login fails method:

protected function sendFailedLoginResponse(Request $request)
{
    return redirect()->back()
        ->withInput($request->only($this->loginUsername(), 'remember'))
        ->withErrors([
            $this->loginUsername() => $this->getFailedLoginMessage(),
        ]);
}

but i'm not allowed to edit this method . this is one of laravel core files.

图片转代码服务由CSDN问答提供 功能建议

登录失败后如何将用户重定向到登录页面? i尝试在 AuthController

  protected $ redirectTo ='/ login'; 
protected $ loginView ='auth.login_register_form'; 
protected $ loginPath ='/ login'; 
   
 
 

但是用户没有重定向到 / login 页面,他被重定向回到他之前的页面。 诅咒有一个 AuthenticateUser.php 中用作登录失败的方法:

  protected function sendFailedLoginResponse(Request $ request)
 {
 return redirect()  - > back()
  - > withInput($ request-> only($ this-> loginUsername(),'remember'))
  - > withErrors([
 $ this-> loginUsername  ()=> $ this-> getFailedLoginMessage(),
]); 
} 
   
 
 

但我不允许编辑此方法。 这是laravel核心文件之一。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doujuegai8830
    doujuegai8830 2017-02-14 07:08
    已采纳

    In your controller you have to return him redirect (not just assign path to variable), for example

    return redirect('/login');
    

    If it's form with filled inputs you can do something like

    return redirect('/login')->withInput();
    

    In your example

    protected function sendFailedLoginResponse(Request $request)
    {
        return redirect('/login')
            ->withInput($request->only($this->loginUsername(), 'remember'))
            ->withErrors([
                $this->loginUsername() => $this->getFailedLoginMessage(),
            ]);
    }
    
    点赞 评论

相关推荐