【问题标题】:Password reset link token not including port in Laravel密码重置链接令牌不包括 Laravel 中的端口
【发布时间】:2020-05-15 08:59:50
【问题描述】:

我有一个包含多个身份验证系统的应用程序。有一个系统是使用 make:auth 命令制作的,另外四个是我手动制作的。一切正常,除了使用我使用 make:auth 命令创建的身份验证系统重置密码时通过电子邮件发送给用户的密码重置链接。

我已隔离问题,发现正在发送的令牌不包括端口。因此,当用户单击电子邮件中收到的重置密码按钮时,他们会收到一条错误消息,提示“找不到对象”。如果我将端口添加到 URL,那么它可以工作。

我转到 .env 文件并修改 APP_URL 以添加端口,如下所示:

APP_URL=http://localhost:8000

这并没有解决问题。

我没有对“Illuminate\Foundation\Auth\SendsPasswordResetEmails.php”文件进行任何修改。该文件中触发的函数是:

    public function sendResetLinkEmail(Request $request)
{
    $this->validateEmail($request);

    // We will send the password reset link to this user. Once we have attempted
    // to send the link, we will examine the response then see the message we
    // need to show to the user. Finally, we'll send out a proper response.
    $response = $this->broker()->sendResetLink(
        $this->credentials($request)
    );

    return $response == Password::RESET_LINK_SENT
                ? $this->sendResetLinkResponse($request, $response)
                : $this->sendResetLinkFailedResponse($request, $response);
}

【问题讨论】:

    标签: laravel


    【解决方案1】:

    Laravel 在 vendor\laravel\framework\src\Illuminate\Auth\Notifications\ResetPassword 命中 ResetPassword 类 从那里发送带有密码重置链接的电子邮件。

      public function toMail($notifiable)
        {
            if (static::$toMailCallback) {
                return call_user_func(static::$toMailCallback, $notifiable, $this->token);
            }
    
            return (new MailMessage)
                ->subject(Lang::getFromJson('Reset Password Notification'))
                ->line(Lang::getFromJson('You are receiving this email because we received a password reset request for your account.'))
                ->action(Lang::getFromJson('Reset Password'), url(config('app.url').route('password.reset', ['token' => $this->token, 'email' => $notifiable->getEmailForPasswordReset()], false)))
                ->line(Lang::getFromJson('This password reset link will expire in :count minutes.', ['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]))
                ->line(Lang::getFromJson('If you did not request a password reset, no further action is required.'));
        }
    
    

    在这个函数 url(config('app.url'). 中,这段代码从 config 文件夹中的 app 文件中获取 url (config/app.php)。 它自动设置为 localhost 作为基本 url。

    【讨论】:

    • 我去了 config/app.php 文件并修改了 url 为:'url' => env('APP_URL', 'localhost:8000'),。但是,它仍然在发送没有端口的按钮
    • 在 toMail 函数中将 ->action() 行替换为 ->action('Reset Password', url('your_route',$this->token) )。 your_route 像 ('/resetpasswod' )。它会默认创建 localhost:8000/resetpassword
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-13
    • 2017-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-30
    相关资源
    最近更新 更多