Laravel里我们可以使用php artisan make:auth来生成一套默认的登陆注册重置邮箱的Authentication System,但是如何修改系统发送给用户的重置密码邮件的样式和内容呢?

虽然默认的邮件样式很美观,但是不免全部是英文,我们至少可以添加进一些中文提示,方便用户查看。

首先我们需要明确的是:

  1. Laravel 默认的 Notification Class是ResetPassword,位于Illumintate/Auth/Notifications中。
  2. 我们不应该直接修改位于ResetPassword里的代码,因为如果更新package可能导致覆盖。

我们先来看一下ResetPassword

<?php
namespace Illuminate\Auth\Notifications; use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage; class ResetPassword extends Notification
{
public $token; public function __construct($token)
{
$this->token = $token;
} public function via($notifiable)
{
return ['mail'];
} public function toMail($notifiable)
{
return (new MailMessage)
->line('You are receiving this email because we received a password reset request for your account')
->action('Reset Password', url(config('app.url').route('password.reset', $this->token, false)))
->line('If you did not request a password reset, no further action is required.');
}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

可以看到,ResetPassword拓展了Notification这个类,所以我们需要做的就是新建一个Notification类,来完成我们自定义邮件内容的修改:

$ php artisan make:notification ResetPasswordNotification
  • 1

输入以上artisan命令,我们会发现在App\Notifications文件夹下多出了一个名为ResetPasswordNotification.php的文件,打开它,我们可以看到其内容跟ResetPassword很相似。我们只需要修改关键的代码即可:

<?php
namespace Illuminate\Auth\Notifications; use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage; class ResetPasswordNotification extends Notification
{
use Queueable; public $token; public function __construct($token)
{
$this->token = $token;
} public function via($notifiable)
{
return ['mail'];
} public function toMail($notifiable)
{
return (new MailMessage)
->line('这里可以放我们需要添加的内容')
->line('You are receiving this email because we received a password reset request for your account')
->action('Reset Password', url(config('app.url').route('password.reset', $this->token, false)))
->line('这里可以放我们需要添加的内容')
->line('If you did not request a password reset, no further action is required.');
}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

可以看到,我们可以以line作为单位来添加我们需要的信息。


那么信息内容搞定了,怎么样修改邮件样式呢?首先我们需要能够修改信息的Blade模板:

$ php artisan vendor:publish --tag=laravel-notifications
  • 1

以上命令把包裹里的模板发布到resources/views/vendor/notifications文件夹中,这样我们只需要修改resources/views/vendor/notifications/email.blade.php就可以了。

最后一步,我们在User模型里添加:

/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

这样,我们就可以使用ResetPasswordNotification来进行邮件的发送了。

模板的修改很简单,这里就不赘述了,完成后,我们可以看到新的邮件内容:

laravel 修改重置密码模板的更多相关文章

  1. Laravel实现找回密码及密码重置的例子

    https://mp.weixin.qq.com/s/PO5f5OJPt5FzUZr-7Xz8-g Laravel实现找回密码及密码重置功能在php实现与在这里实现会有什么区别呢,下面我们来看看Lar ...

  2. django用户认证系统——重置密码7

    当用户不小心忘记了密码时,网站需要提供让用户找回账户密码的功能.在示例项目中,我们将发送一封含有重置用户密码链接的邮件到用户注册时的邮箱,用户点击收到的链接就可以重置他的密码,下面是具体做法. 发送邮 ...

  3. [ Laravel 5.6 文档 ] 安全系列 —— 重置密码

    http://laravelacademy.org/post/8929.html 简介 想要快速实现该功能?只需要在新安装的 Laravel 应用下运行 php artisan make:auth(如 ...

  4. MVC5 网站开发之六 管理员 2、添加、删除、重置密码、修改密码、列表浏览

    目录 奔跑吧,代码小哥! MVC5网站开发之一 总体概述 MVC5 网站开发之二 创建项目 MVC5 网站开发之三 数据存储层功能实现 MVC5 网站开发之四 业务逻辑层的架构和基本功能 MVC5 网 ...

  5. ubuntu系统下mysql重置密码和修改密码操作

    一.忘记密码后想重置密码 在介绍修改密码之前,先介绍一个文件/etc/mysql/debian.cnf.其主要内容如下图: 里面有一个debian-sys-maint用户,这个用户只有Debian或U ...

  6. weblogic11g 修改密码和重置密码【原】

    修改密码 知道密码的情况下,可参考该链接 http://www.cnblogs.com/may12138/p/6022946.html 或 http://www.cnblogs.com/lsdb/p/ ...

  7. ASP.NET Core MVC 打造一个简单的图书馆管理系统 (修正版)(三)密码修改以及密码重置

     前言: 本系列文章主要为我之前所学知识的一次微小的实践,以我学校图书馆管理系统为雏形所作. 本系列文章主要参考资料: 微软文档:https://docs.microsoft.com/zh-cn/as ...

  8. laravel修改用户模块的密码验证

    做项目的时候,用户认证几乎是必不可少的,如果我们的项目由于一些原因不得不使用 users 之外的用户表进行认证,那么就需要多做一点工作来完成这个功能. 现在假设我们只需要修改登录用户的表,表名和表结构 ...

  9. phpcms修改重置后台账号和密码

    通过Phpmyadmin等工具,打开数据库中找到v9_admin表: 把password字段值改为: 0b817b72c5e28b61b32ab813fd1ebd7f再把encrypt字段值改为: 3 ...

随机推荐

  1. linux网络连接的查看和端口的监听

    网络软件都是由客户端和服务端组成,由服务端在服务器上监听指定的端口处理接收到的数据,而客户端是向服务器端监听的端口发送数据,并由服务器端对该数据进行处理,然后将处理结果返回给客户端. 那么我们在lin ...

  2. vue集成ueditor

    相关代码见github 1.引入ueditor相关的文件,具体目录见下图如下 我将下载的文件放在static下面,这里专门用来放置相关的静态文件 (在ueditor.config.js需要配置一下路径 ...

  3. erwin逆向工程,logical模型列名修改为中文

    逆向工程,应该选择physical template,这样拷贝到logical/physical 模型中,才可以将logical模型的列名修改为中文.

  4. .net 获取当前电脑账户

    string domainAndName = User.Identity.Name; ] { '\\' }, StringSplitOptions.RemoveEmptyEntries); strin ...

  5. Browserify命令行参数

    –outfile, -o: browserify日志打印到文件 –require, -r: 绑定模块名或文件,用逗号分隔 –entry, -e: 应用程序的入口 –ignore, -i: 省略输出 – ...

  6. 使用js合并table中的单元格

    用primefaces做的报表,领导要求合并相同内容的单元格,但是primefaces没有找到可以合并单元格的组件,想来想去,只有页面加载后用js合并了. http://blog.csdn.net/d ...

  7. wampserver安装及安装中可能遇到的问题

    首先wampserver是windows apache Mysql PHP 集成开发环境,即在windows下的apache.php和mysql的服务器.因此wampserver是一个服务器端应用程序 ...

  8. python PIL/Pillow图像扩展、复制、粘贴处理

    http://blog.csdn.net/yuanyangsdo/article/details/60957685

  9. 记录selenium操作

    # -*- coding: utf-8 -*- # coding:utf-8 必须在第一行才能支持中文注释 #!/usr/bin/python # android-build.py # Build a ...

  10. date.timezone not set in php.ini. Please contact ...解决方案

    无论是在LAMP还是在LNMP系统环境下, 只要PHP的版本在5.3及其以上的版本时, 无论是在安装oscommerce, 还是在安装zen cart, 以及其他的CMS时, 都会遇到如下所示的错误信 ...