-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail_template.go
151 lines (122 loc) · 3.23 KB
/
mail_template.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package sesiones
import (
"bytes"
"html/template"
"github.com/pkg/errors"
)
// MailTemplate es el encargado de generar el HTML de los mails que se le
// enviarán al usuario para blanquear contraseña o confirmar usuario.
type MailTemplate struct {
// template es el template con el que se generará el mail
template *template.Template
// frontEndPath es el link que va en el mail. Lleva a una página, esa página hace
// la llamada al backend
frontEndPath string
}
// NewMailTemplate crea un nuevo template de mail.
//
// frontEndPath: es la URL a la que lleva el mail, por ejemplo la dirección
// www.sweet.com.ar/#/auth/confirmar_usuario
func NewMailTemplate(t, frontEndPath string) (mt *MailTemplate, err error) {
mt = &MailTemplate{}
// Leo el html del template
tpl := template.New("")
tpl, err = tpl.Parse(t)
if err != nil {
return mt, errors.Wrap(err, "parseando string del template")
}
mt.template = tpl
mt.frontEndPath = frontEndPath
return
}
func (mt *MailTemplate) body(nombre, idConfirmacion string) (html string, err error) {
url := mt.frontEndPath + "/?id=" + idConfirmacion
datos := struct {
Nombre string
URLConfirmacion string
}{
Nombre: nombre,
URLConfirmacion: url,
}
out := &bytes.Buffer{}
err = mt.template.Execute(out, datos)
if err != nil {
return html, errors.Wrap(err, "ejecutando template")
}
html = out.String()
return
}
var defaultBlanqueoTemplate = `
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet">
<style>
body {
background-color: lightblue;
}
* {
font-family: "Roboto", sans-serif;
font-weight: 300;
}
div#main {
max-width: 700px;
background-color: white;
margin: auto;
padding: 80px;
height: 95%;
}
p#rechazar {}
</style>
</head>
<body>
<div id='main'>
<p> Hola {{ .Nombre }}!</p>
<p>
Para continuar con el proceso de blanqueo de contraseña, haz clic <a href='{{ .URLConfirmacion }}'>AQUÍ</a>.
</p>
<p id="rechazar">
Si tú no has realizado la solicitud de blanqueo de contraseña haz clic aquí.
</p>
</div>
<br>
</body>
</html>
`
var defaultConfirmacionUsuarioTemplate = `
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet">
<style>
body {
background-color: lightblue;
}
* {
font-family: "Roboto", sans-serif;
font-weight: 300;
}
div#main {
max-width: 700px;
background-color: white;
margin: auto;
padding: 80px;
height: 95%;
}
p#rechazar {}
</style>
</head>
<body>
<div id='main'>
<p> Hola {{ .Nombre }}, gracias por sumarte a Sweet!</p>
<p>
Para confirmar tu alta como usuario, haz clic <a href='{{ .URLConfirmacion }}'>AQUÍ</a>.
</p>
<p id="rechazar">
Si tú no has realizado la solicitud de blanqueo de contraseña haz clic aquí.
</p>
</div>
<br>
</body>
</html>
`