Move update user email to

This commit is contained in:
kolaente 2021-02-07 18:54:00 +01:00
parent d1823448d4
commit 6a1afd01ca
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 54 additions and 7 deletions

View File

@ -912,7 +912,6 @@ type ` + name + ` struct {
// ToMail returns the mail notification for ` + name + `
func (n *` + name + `) ToMail() *notifications.Mail {
return notifications.NewMail().
To().
Subject("").
Greeting("Hi ").
Line("").

49
pkg/user/notifications.go Normal file
View File

@ -0,0 +1,49 @@
// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public Licensee as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public Licensee for more details.
//
// You should have received a copy of the GNU Affero General Public Licensee
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package user
import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/notifications"
)
// EmailConfirmNotification represents a EmailConfirmNotification notification
type EmailConfirmNotification struct {
User *User
IsNew bool
}
// ToMail returns the mail notification for EmailConfirmNotification
func (n *EmailConfirmNotification) ToMail() *notifications.Mail {
nn := notifications.NewMail().
Subject(n.User.GetName() + ", please confirm your email address at Vikunja").
Greeting("Hi " + n.User.GetName() + ",")
if n.IsNew {
nn.Line("Welcome to Vikunja!")
}
return nn.
Line("To confirm your email address, click the link below:").
Action("Confirm your email address", config.ServiceFrontendurl.GetString()+"?userEmailConfirm="+n.User.EmailConfirmToken).
Line("Have a nice day!")
}
// ToDB returns the EmailConfirmNotification notification in a format which can be saved in the db
func (n *EmailConfirmNotification) ToDB() interface{} {
return nil
}

View File

@ -18,7 +18,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"
)
@ -69,12 +69,11 @@ func UpdateEmail(s *xorm.Session, update *EmailUpdate) (err error) {
}
// Send the user a mail with a link to confirm the mail
data := map[string]interface{}{
"User": update.User,
"IsNew": false,
n := &EmailConfirmNotification{
User: update.User,
IsNew: false,
}
mail.SendMailWithTemplate(update.User.Email, update.User.Username+", please confirm your email address at Vikunja", "confirm-email", data)
err = notifications.Notify(update.User, n)
return
}