Move user password reset to notification

This commit is contained in:
kolaente 2021-02-07 19:18:59 +01:00
parent b6b960d154
commit 773f708d3a
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 23 additions and 22 deletions

View File

@ -72,3 +72,23 @@ func (n *PasswordChangedNotification) ToMail() *notifications.Mail {
func (n *PasswordChangedNotification) ToDB() interface{} {
return nil
}
// ResetPasswordNotification represents a ResetPasswordNotification notification
type ResetPasswordNotification struct {
User *User
}
// ToMail returns the mail notification for ResetPasswordNotification
func (n *ResetPasswordNotification) ToMail() *notifications.Mail {
return notifications.NewMail().
Subject("Reset your password on Vikunja").
Greeting("Hi "+n.User.GetName()+",").
Line("To reset your password, click the link below:").
Action("Reset your password", config.ServiceFrontendurl.GetString()+"?userPasswordReset="+n.User.PasswordResetToken).
Line("Have a nice day!")
}
// ToDB returns the ResetPasswordNotification notification in a format which can be saved in the db
func (n *ResetPasswordNotification) ToDB() interface{} {
return nil
}

View File

@ -18,7 +18,6 @@ package user
import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/mail"
"code.vikunja.io/api/pkg/notifications"
"code.vikunja.io/api/pkg/utils"
"xorm.io/xorm"
@ -125,11 +124,10 @@ func RequestUserPasswordResetToken(s *xorm.Session, user *User) (err error) {
return
}
data := map[string]interface{}{
"User": user,
n := &ResetPasswordNotification{
User: user,
}
// Send the user a mail with the reset token
mail.SendMailWithTemplate(user.Email, "Reset your password on Vikunja", "reset-password", data)
err = notifications.Notify(user, n)
return
}

View File

@ -1,14 +0,0 @@
{{template "mail-header.tmpl" .}}
<p>
Hi {{.User.Username}},<br>
<br>
To reset your password, click the link below:
</p>
<a href="{{.FrontendURL}}?userPasswordReset={{.User.PasswordResetToken}}" title="Reset your password" style="-webkit-box-shadow: 0.3em 0.3em 1em #b2d0ff; box-shadow: 0.3em 0.3em 1em #b2d0ff; background-color: #1973ff; border-color: transparent; color: #fff; text-decoration: none; text-align: center; text-rendering: optimizelegibility; text-transform: uppercase; font-weight: bold; font-size: 14px; padding: 10px 14px; margin: 10px auto; border-radius: 4px; user-select: none; display: block; width: 280px;font-family:sans-serif">
Reset your password
</a>
<p>
If the button above doesn't work, copy the url below and paste it in your browsers address bar:<br/>
{{.FrontendURL}}?userPasswordReset={{.User.PasswordResetToken}}
</p>
{{template "mail-footer.tmpl"}}

View File

@ -1,3 +0,0 @@
Hi {{.User.Username}},
Use the following link to reset your password: {{.FrontendURL}}?userPasswordReset={{.User.PasswordResetToken}}