【问题标题】:Laravel 5 Auth - How to output the status message after email sent from password reset pageLaravel 5 Auth - 如何在密码重置页面发送电子邮件后输出状态消息
【发布时间】:2016-03-24 21:12:06
【问题描述】:

如何在您的视图中单击 laravel 5.1 中内置的 auth 后的密码重置按钮输出状态消息?

【问题讨论】:

    标签: authentication laravel-5 passwords reset


    【解决方案1】:

    代码在 Illuminate\Foundation\Auth\ResetsPasswords 中

    在函数 postReset。

    public function postReset(Request $request)
        {
            $this->validate($request, [
                'token' => 'required',
                'email' => 'required|email',
                'password' => 'required|confirmed|min:6',
            ]);
    
            $credentials = $request->only(
                'email', 'password', 'password_confirmation', 'token'
            );
    
            $response = Password::reset($credentials, function ($user, $password) {
                $this->resetPassword($user, $password);
            });
    
            switch ($response) {
                case Password::PASSWORD_RESET:
                    return redirect($this->redirectPath())->with('status', trans($response));
    
                default:
                    return redirect()->back()
                                ->withInput($request->only('email'))
                                ->withErrors(['email' => trans($response)]);
            }
        }
    

    检查大小写密码:PASSWORD_RESET:状态是负责消息的变量。这个变量的值是

    “我们已经通过电子邮件发送了您的密码重置链接!”

    使用下面的代码输出上面的状态信息

    {{ Session::get('status') }}
    

    或者你可以使用

    {{ Session::has('status') }} 
    

    它会返回一个值 1。

    要更改状态消息的值,只需转到

    /resources/lang/en/passwords.php

    下面是passwords.php的代码

    <?php
    
    return [
    
        /*
        |--------------------------------------------------------------------------
        | Password Reminder Language Lines
        |--------------------------------------------------------------------------
        |
        | The following language lines are the default lines which match reasons
        | that are given by the password broker for a password update attempt
        | has failed, such as for an invalid token or invalid new password.
        |
        */
    
        'password' => 'Passwords must be at least six characters and match the confirmation.',
        'reset' => 'Your password has been reset!',
        'sent' => 'We have e-mailed your password reset link!',
        'token' => 'This password reset token is invalid.',
        'user' => "We can't find a user with that e-mail address.",
    
    ];
    

    希望对你有所帮助。

    【讨论】:

      猜你喜欢
      • 2016-03-01
      • 2017-09-02
      • 2017-01-20
      • 1970-01-01
      • 2017-07-07
      • 1970-01-01
      • 2018-11-02
      • 2015-11-26
      • 2021-08-05
      相关资源
      最近更新 更多