forked from makeless/makeless-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail_password_request.go
72 lines (64 loc) · 2.53 KB
/
mail_password_request.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
package makeless_go
import (
"fmt"
"sync"
"github.com/makeless/makeless-go/mailer"
"github.com/makeless/makeless-go/mailer/basic"
"github.com/makeless/makeless-go/model"
"github.com/matcornic/hermes/v2"
)
func (makeless *Makeless) mailPasswordRequest(data map[string]interface{}) (makeless_go_mailer.Mail, error) {
var err error
var message, messageHtml string
var passwordRequest = data["passwordRequest"].(*makeless_go_model.PasswordRequest)
var messages = map[string]map[string]string{
"en": {
"subject": "Reset your password",
"instruction": "to reset your password, please click here:",
"button": "Reset password",
},
}
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{
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: messages[makeless.GetConfig().GetConfiguration().GetLocale()]["instruction"],
Button: hermes.Button{
Text: messages[makeless.GetConfig().GetConfiguration().GetLocale()]["button"],
Link: fmt.Sprintf(
"%s/password-reset?token=%s",
makeless.GetConfig().GetConfiguration().GetMail().GetLink(),
*passwordRequest.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{*passwordRequest.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
}