forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forgot_password_handler.go
42 lines (32 loc) · 1.01 KB
/
forgot_password_handler.go
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
35
36
37
38
39
40
41
42
package uadmin
import (
"fmt"
"net/http"
"strings"
)
// forgotPasswordHandler !
func forgotPasswordHandler(u *User, r *http.Request, link string, msg string) error {
if u.Email == "" {
return fmt.Errorf("unable to reset password, the user does not have an email")
}
if msg == "" {
msg = `<p>Dear {NAME},</p>
Have you forgotten your password to access {WEBSITE}. Don't worry we got your back. Please follow the link below to reset your password.
If you want to reset your password, click this link:
<a href="{URL}">{URL}</a>
If you didn't request a password reset, you can ignore this message.
Regards,
{WEBSITE} Support
`
}
link, err := u.GeneratePasswordResetLink(r, link)
if err != nil {
return err
}
msg = strings.ReplaceAll(msg, "{NAME}", u.String())
msg = strings.ReplaceAll(msg, "{WEBSITE}", SiteName)
msg = strings.ReplaceAll(msg, "{URL}", link)
subject := "Password reset for " + SiteName
err = SendEmail([]string{u.Email}, []string{}, []string{}, subject, msg)
return err
}