Laravel 5 Auth - 如何在密码重置页面发送电子邮件后输出状态消息

时间:2015-12-18 07:58:07

标签: authentication laravel-5 passwords reset

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

1 个答案:

答案 0 :(得分:10)

代码位于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.",

];

希望这会对你有所帮助。