dongya2029 2016-09-12 19:26
浏览 88

更改重定向路径

So I am building this web application in laravel framework (version 5.3) and I want to change the redirect path whenever user fails login, So far I've tried this piece of code in my LoginController.php

protected $loginPath = "/my-given-path";

But it just doesn't seem to work, So I tried inspecting this AuthenticatesUsers trait and got to this file and then to RedirectUsers trait and there no such function revolving around $loginPath exists, but $redirectTo exists.


Alright so I came back to AuthenticatesUsers trait and inspected couple of functions to see this :-

public function login(Request $request)
{
    $this->validateLogin($request);

    // If the class is using the ThrottlesLogins trait, we can automatically throttle
    // the login attempts for this application. We'll key this by the username and
    // the IP address of the client making these requests into this application.
    if ($lockedOut = $this->hasTooManyLoginAttempts($request)) {
        $this->fireLockoutEvent($request);

        return $this->sendLockoutResponse($request);
    }

    $credentials = $this->credentials($request);

    if ($this->guard()->attempt($credentials, $request->has('remember'))) {
        return $this->sendLoginResponse($request);
    }

    // If the login attempt was unsuccessful we will increment the number of attempts
    // to login and redirect the user back to the login form. Of course, when this
    // user surpasses their maximum number of attempts they will get locked out.
    if (! $lockedOut) {
        $this->incrementLoginAttempts($request);
    }

    return $this->sendFailedLoginResponse($request);
}

hence I need to inspect this `sendFailedLoginResponse()' function and so here it goes :-

 protected function sendFailedLoginResponse(Request $request)
{
    return redirect()->back()
        ->withInput($request->only($this->username(), 'remember'))
        ->withErrors([
            $this->username() => Lang::get('auth.failed'),
        ]);
}

So now I tried changing redirect()->back()... to redirect('/my-given-path')... but still no luck.


I have been trying to solve this problem for the whole day and can't come up with solution and the one's asked before aren't of laravel 5.3 version. hence, I'd be glad if someone could tell what's going on and where I am being wrong?

  • 写回答

1条回答 默认 最新

  • douzui6173 2016-09-12 20:21
    关注

    Alright, So I found the solution, Actually I think I was doing something wrong when changing redirect()->back()... to redirect('/my-given-url')... in my AuthenticatesUsers.php file under function sendFailedLoginResponse().


    But $loginPath is no longer working and no such function exists in RedirectUsers trait, when $redirectTo exists. So I have to manually hardcode my desired path in the function of AuthenticatesUsers trait.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端