Move user password changed to notification
This commit is contained in:
parent
18116d71b4
commit
b6b960d154
|
@ -53,3 +53,22 @@ func (n *EmailConfirmNotification) ToMail() *notifications.Mail {
|
|||
func (n *EmailConfirmNotification) ToDB() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// PasswordChangedNotification represents a PasswordChangedNotification notification
|
||||
type PasswordChangedNotification struct {
|
||||
User *User
|
||||
}
|
||||
|
||||
// ToMail returns the mail notification for PasswordChangedNotification
|
||||
func (n *PasswordChangedNotification) ToMail() *notifications.Mail {
|
||||
return notifications.NewMail().
|
||||
Subject("Your Password on Vikunja was changed").
|
||||
Greeting("Hi " + n.User.GetName() + ",").
|
||||
Line("Your account password was successfully changed.").
|
||||
Line("If this wasn't you, it could mean someone compromised your account. In this case contact your server's administrator.")
|
||||
}
|
||||
|
||||
// ToDB returns the PasswordChangedNotification notification in a format which can be saved in the db
|
||||
func (n *PasswordChangedNotification) ToDB() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ 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"
|
||||
)
|
||||
|
@ -44,10 +45,10 @@ func ResetPassword(s *xorm.Session, reset *PasswordReset) (err error) {
|
|||
}
|
||||
|
||||
// Check if we have a token
|
||||
var user User
|
||||
user := &User{}
|
||||
exists, err := s.
|
||||
Where("password_reset_token = ?", reset.Token).
|
||||
Get(&user)
|
||||
Get(user)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -67,7 +68,7 @@ func ResetPassword(s *xorm.Session, reset *PasswordReset) (err error) {
|
|||
_, err = s.
|
||||
Cols("password", "password_reset_token").
|
||||
Where("id = ?", user.ID).
|
||||
Update(&user)
|
||||
Update(user)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -78,12 +79,11 @@ func ResetPassword(s *xorm.Session, reset *PasswordReset) (err error) {
|
|||
}
|
||||
|
||||
// Send a mail to the user to notify it his password was changed.
|
||||
data := map[string]interface{}{
|
||||
"User": user,
|
||||
n := &PasswordChangedNotification{
|
||||
User: user,
|
||||
}
|
||||
|
||||
mail.SendMailWithTemplate(user.Email, "Your password on Vikunja was changed", "password-changed", data)
|
||||
|
||||
err = notifications.Notify(user, n)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
{{template "mail-header.tmpl" .}}
|
||||
<p>
|
||||
Hi {{.User.Username}},<br/>
|
||||
<br/>
|
||||
Your account password was successfully changed.
|
||||
<br/>
|
||||
If this wasn't you, it could mean someone compromised your account. In this case contact your server's administrator.
|
||||
</p>
|
||||
{{template "mail-footer.tmpl"}}
|
|
@ -1,5 +0,0 @@
|
|||
Hi {{.User.Username}},
|
||||
|
||||
Your account password was successfully changed.
|
||||
|
||||
If this wasn't you, it could mean someone compromised your account. In this case contact your server's administrator.
|
Loading…
Reference in New Issue