Forget the password through the mail to retrieve more in line with the current situation, but the logic is more chaotic, here to sort out. Please read on
1. Create a button link where you forgot your password
<a href="/admin/password/reset"// Skip to writing the email address class="am-btn am-btn-default am-btn-sm am-fr" style="border-radius: 4px;"> Forget password </a> Address You can query the address links using the PHP artisan Route :list terminalCopy the code
2. Now that we have skipped to the sending and filling email interface, we need to create a notification class
PHP artisan make: Notification ResetPassword PHP artisan make: Notification ResetPassword
3. Now that the notification class has been created, all you need to do is send the notification in an email.
There are two ways to send it. The first is to write a method to send an email in the authentication module user.php that Laravel automatically generates. The second is to use the Notification face class. Notification::send($users, new ResetPassword($token)) Notification::send($users, new ResetPassword($token))
4. We open ituser.php
Put a public method at the bottom
public function sendPasswordResetNotification($token) {
$this->notify(new ResetPassword($token));
}
Copy the code
5. Now we need to configure it.env
The files are as follows :(take qq mailbox as an example)
MAIL_DRIVER=smtp MAIL_HOST=smtp.qq.com MAIL_PORT=465 [email protected] MAIL_PASSWORD=fzzbaradqwfsbfgd Enter the authorization code MAIL_ENCRYPTION= SSL [email protected] MAIL_FROM_NAME=SHOP MallCopy the code
Note: If it is qq mailbox 163, you need to set the mailbox by yourself
This is pretty much where the functionality is. It’s time to email…
6. At this time, we go to the interface entered in the first step, fill in the email number and click Send
[email protected]
ResetPassword.php
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Reset password')
->line('We have received your email request! ')
->action('Click to change password', url('/admin/password/reset'.$this->token))
->line('Thank you for your support and trust in our SHOP mall! ');
}
$this->token This is passed in by the constructor to create a member property var on it$tokenThe constructor is like publicfunction __construct($token)
{
$this->token = $token;
}
Copy the code
7. The effect picture is as follows:
8. Clicking the blue button in the picture will lead to the page of reset password
If it is to jump to the XXX. Dev/home at this time only need the middleware middleware folder RedirectIfAuthenticated. PHP will modify the content of the inside as shown in the figure below.