Move user create confirm to notification
This commit is contained in:
parent
6a1afd01ca
commit
18116d71b4
|
@ -29,8 +29,14 @@ type EmailConfirmNotification struct {
|
|||
|
||||
// ToMail returns the mail notification for EmailConfirmNotification
|
||||
func (n *EmailConfirmNotification) ToMail() *notifications.Mail {
|
||||
|
||||
subject := n.User.GetName() + ", please confirm your email address at Vikunja"
|
||||
if n.IsNew {
|
||||
subject = n.User.GetName() + " + Vikunja = <3"
|
||||
}
|
||||
|
||||
nn := notifications.NewMail().
|
||||
Subject(n.User.GetName() + ", please confirm your email address at Vikunja").
|
||||
Subject(subject).
|
||||
Greeting("Hi " + n.User.GetName() + ",")
|
||||
|
||||
if n.IsNew {
|
||||
|
|
|
@ -19,7 +19,7 @@ package user
|
|||
import (
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"code.vikunja.io/api/pkg/events"
|
||||
"code.vikunja.io/api/pkg/mail"
|
||||
"code.vikunja.io/api/pkg/notifications"
|
||||
"code.vikunja.io/api/pkg/utils"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"xorm.io/xorm"
|
||||
|
@ -83,8 +83,17 @@ func CreateUser(s *xorm.Session, user *User) (newUser *User, err error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
sendConfirmEmail(user)
|
||||
// Dont send a mail if no mailer is configured
|
||||
if !config.MailerEnabled.GetBool() {
|
||||
return
|
||||
}
|
||||
|
||||
n := &EmailConfirmNotification{
|
||||
User: user,
|
||||
IsNew: false,
|
||||
}
|
||||
|
||||
err = notifications.Notify(user, n)
|
||||
return newUserOut, err
|
||||
}
|
||||
|
||||
|
@ -145,18 +154,3 @@ func checkIfUserExists(s *xorm.Session, user *User) (err error) {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func sendConfirmEmail(user *User) {
|
||||
// Dont send a mail if no mailer is configured
|
||||
if !config.MailerEnabled.GetBool() {
|
||||
return
|
||||
}
|
||||
|
||||
// Send the user a mail with a link to confirm the mail
|
||||
data := map[string]interface{}{
|
||||
"User": user,
|
||||
"IsNew": true,
|
||||
}
|
||||
|
||||
mail.SendMailWithTemplate(user.Email, user.Username+" + Vikunja = <3", "confirm-email", data)
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
{{template "mail-header.tmpl" .}}
|
||||
<p>
|
||||
Hi {{.User.Username}},<br>
|
||||
{{if .IsNew}}
|
||||
<br>
|
||||
Welcome to Vikunja!
|
||||
{{end}}
|
||||
<br/>
|
||||
To confirm your email address, click the link below:
|
||||
</p>
|
||||
<a href="{{.FrontendURL}}?userEmailConfirm={{.User.EmailConfirmToken}}" title="Confirm your email address" 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">
|
||||
Confirm your email address
|
||||
</a>
|
||||
<p>
|
||||
If the button above doesn't work, copy the url below and paste it in your browsers address bar:<br/>
|
||||
{{.FrontendURL}}?userEmailConfirm={{.User.EmailConfirmToken}}
|
||||
</p>
|
||||
{{template "mail-footer.tmpl"}}
|
|
@ -1,9 +0,0 @@
|
|||
Hi {{.User.Username}},
|
||||
|
||||
{{if .IsNew}}
|
||||
Welcome to Vikunja!
|
||||
|
||||
{{end}}
|
||||
To confirm your email address, copy the link below and paste it in your browser:
|
||||
|
||||
{{.FrontendURL}}?userEmailConfirm={{.User.EmailConfirmToken}}
|
Loading…
Reference in New Issue