forked from makeless/makeless-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail_email_verification.go
76 lines (69 loc) · 2.64 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
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{}) (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",
},
}
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(makeless.GetConfig().GetConfiguration().GetLocale()).GetCopyright(),
},
}
email := hermes.Email{
Body: hermes.Body{
Name: *user.GetName(),
Greeting: makeless.GetConfig().GetConfiguration().GetMail().GetTexts(makeless.GetConfig().GetConfiguration().GetLocale()).GetGreeting(),
Signature: makeless.GetConfig().GetConfiguration().GetMail().GetTexts(makeless.GetConfig().GetConfiguration().GetLocale()).GetSignature(),
Actions: []hermes.Action{
{
Instructions: fmt.Sprintf(
"%s %s",
messages[makeless.GetConfig().GetConfiguration().GetLocale()]["instruction"],
*user.GetEmail(),
),
Button: hermes.Button{
Text: messages[makeless.GetConfig().GetConfiguration().GetLocale()]["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[makeless.GetConfig().GetConfiguration().GetLocale()]["subject"],
Message: []byte(message),
HtmlMessage: []byte(messageHtml),
RWMutex: new(sync.RWMutex),
}, nil
}