-
Notifications
You must be signed in to change notification settings - Fork 12
/
mail_email_verification.go
82 lines (75 loc) · 2.72 KB
/
mail_email_verification.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package makeless_go
import (
"fmt"
"github.com/makeless/makeless-go/mailer"
"github.com/makeless/makeless-go/mailer/basic"
"github.com/makeless/makeless-go/model"
"github.com/matcornic/hermes/v2"
"sync"
)
func (makeless *Makeless) mailEmailVerification(data map[string]interface{}, locale string) (makeless_go_mailer.Mail, error) {
var err error
var message, messageHtml string
var user = data["user"].(*makeless_go_model.User)
var messages = map[string]map[string]string{
"en": {
"subject": "Please verify your email address",
"instruction": "to complete your registration, we just need to verify your email address:",
"button": "Verify email address",
},
"de": {
"subject": "Bitte verifiziere deine Email Adresse",
"instruction": "Bitte verifziere deine Email Adresse, um deine Registrierung abzuschließen:",
"button": "Email Adresse verifizieren",
},
}
config := hermes.Hermes{
Product: hermes.Product{
Name: makeless.GetConfig().GetConfiguration().GetMail().GetName(),
Link: makeless.GetConfig().GetConfiguration().GetMail().GetLink(),
Logo: makeless.GetConfig().GetConfiguration().GetMail().GetLogo(),
Copyright: makeless.GetConfig().GetConfiguration().GetMail().GetTexts(locale).GetCopyright(),
TroubleText: makeless.GetConfig().GetConfiguration().GetMail().GetTexts(locale).GetTroubleText(),
},
}
email := hermes.Email{
Body: hermes.Body{
Name: *user.GetName(),
Greeting: makeless.GetConfig().GetConfiguration().GetMail().GetTexts(locale).GetGreeting(),
Signature: makeless.GetConfig().GetConfiguration().GetMail().GetTexts(locale).GetSignature(),
Actions: []hermes.Action{
{
Instructions: fmt.Sprintf(
"%s %s",
messages[locale]["instruction"],
*user.GetEmail(),
),
Button: hermes.Button{
Text: messages[locale]["button"],
Link: fmt.Sprintf(
"%s/email-verification?token=%s",
makeless.GetConfig().GetConfiguration().GetMail().GetLink(),
*user.GetEmailVerification().GetToken(),
),
Color: makeless.GetConfig().GetConfiguration().GetMail().GetButtonColor(),
TextColor: makeless.GetConfig().GetConfiguration().GetMail().GetButtonTextColor(),
},
},
},
},
}
if message, err = config.GeneratePlainText(email); err != nil {
return nil, err
}
if messageHtml, err = config.GenerateHTML(email); err != nil {
return nil, err
}
return &makeless_go_mailer_basic.Mail{
To: []string{*user.GetEmail()},
From: makeless.GetConfig().GetConfiguration().GetMail().GetFrom(),
Subject: messages[locale]["subject"],
Message: []byte(message),
HtmlMessage: []byte(messageHtml),
RWMutex: new(sync.RWMutex),
}, nil
}