在laravel 5.4中成功重置密码后,返回登录页面 [英] Take back to login page after successfully reset his/her password in laravel 5.4

查看:164
本文介绍了在laravel 5.4中成功重置密码后,返回登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当用户在laravel 5.4中成功重置密码时,我都希望重定向到登录页面.

I want to redirect to login page whenever a user successfully reset his/her password in laravel 5.4.

当前,成功重置后,它会重定向到仪表板页面. 我环顾了所有人都说要放置的所有内容
$ redirectTo ='/home';在受保护的$ redirectTo ='/'; 但这并没有给我任何解决方案.

Currently it redirects to dashboard page after successfully reset. I looked around all stuff all are saying to place
protected $redirectTo = '/home'; in protected $redirectTo = '/'; But it does not give me any solution.

推荐答案

默认情况下,Laravel在重置密码后对用户进行身份验证.因此,不可能重定向到登录页面,因为只有来宾用户才能查看登录页面.即使将$redirectTo设置为/login,来宾中间件也会将用户重定向回/home,因为该用户已通过身份验证.

By default Laravel authenticates the user after they reset their password. So it's impossible to redirect to the login page since only guest users can view the login page. Even if you set the $redirectTo to /login, the guest middleware would redirect the user back to /home since the user is authenticated.

如果您需要防止用户使用重置密码自动登录并将其重定向到登录页面,则需要执行以下步骤.

If you need to prevent the user from being automatically logged in on resetting password and redirect them to the login page, you need to follow these steps.

在位于app/Http/Controllers/AuthResetPasswordController中进行以下更改.

Do the following changes in ResetPasswordController located at app/Http/Controllers/Auth.

将重定向路径更改为您的登录页面.

Change the redirect path to your login page.

protected $redirectTo = '/login';

重写resetPassword方法以防止用户登录.将其添加到控制器.

Override the resetPassword method to prevent user being logged in. Add this to the controller.

protected function resetPassword($user, $password)
{
    $user->forceFill([
        'password' => bcrypt($password),
        'remember_token' => Str::random(60),
    ])->save();
}

将此添加到顶部

use Illuminate\Support\Str;


具有ResetsPasswords特性的原始方法如下所示.


The original method in ResetsPasswords trait looks like this.

protected function resetPassword($user, $password)
{
    $user->forceFill([
        'password' => bcrypt($password),
        'remember_token' => Str::random(60),
    ])->save();

    $this->guard()->login($user);
}

编辑:要发送重定向时的自定义响应,您可以在控制器中覆盖sendResetResponse并添加任何自定义会话/Flash消息.默认情况下,laravel会在成功重置密码后设置自己的响应.

Edit : To send a custom response on redirection you can override sendResetResponse in your controller and add any custom session/flash messages. By default laravel sets its own response on successful password reset.

protected function sendResetResponse($response)
{
    return redirect($this->redirectPath())
                        ->with('status', trans($response));
}

这篇关于在laravel 5.4中成功重置密码后,返回登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆