/
updated_password.go
83 lines (80 loc) · 2.07 KB
/
updated_password.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
package password
import (
"github.com/moisespsena-go/aorm"
"net/mail"
"github.com/ecletus/auth"
"github.com/ecletus/mailer"
"github.com/moisespsena/template/html/template"
)
// DefaultUpdatePasswordMailer default update password mailer
var DefaultUpdatedPasswordNotifier = func(TO []mail.Address, context *auth.Context, user auth.User, passwd string) error {
Mailer := mailer.FromSite(context.Site)
if Mailer == nil {
log.Warningf("No mailer for %q. Password for user %q#%s is %q", context.Site.Name(), user.Schema().Name, aorm.IdOf(user), passwd)
return nil
}
if you := user.Schema().MailAddress(); you != nil {
subject := context.Ts(ChangedPasswordFlashMessage)
if err := Mailer.Send(
&mailer.Email{
Context: context,
Lang: append(user.Schema().Lang, context.GetI18nContext().Locales()...),
TO: []mail.Address{*you},
Subject: subject,
}, mailer.Template{
Name: "auth/password/you_password_updated",
Data: context,
Context: context.Context,
}.Funcs(template.FuncMap{
"you": func() *mail.Address {
return you
},
"user": func() interface{} {
return user
},
"login_url": func() string {
return context.AuthURL("login")
},
"user_info": func() *auth.Schema {
return user.Schema()
},
"has_password": func() bool {
return passwd != ""
},
"password": func() string {
return passwd
},
}),
); err != nil {
return err
}
}
return Mailer.Send(
&mailer.Email{
Context: context,
Lang: context.GetI18nContext().Locales(),
TO: TO,
Subject: context.Ts(ResetPasswordMailSubject),
}, mailer.Template{
Name: "auth/password/updated_password",
Data: context,
Context: context.Context,
}.Funcs(template.FuncMap{
"user": func() interface{} {
return user
},
"login_url": func() string {
return context.AuthURL("login")
},
"user_info": func() *auth.Schema {
return user.Schema()
},
"has_password": func() bool {
return passwd != ""
},
"password": func() string {
return passwd
},
}),
)
}