@@ -17,7 +17,6 @@ import (
17
17
"code.gitea.io/gitea/modules/markup/markdown"
18
18
"code.gitea.io/gitea/modules/setting"
19
19
"gopkg.in/gomail.v2"
20
- "gopkg.in/macaron.v1"
21
20
)
22
21
23
22
const (
@@ -45,11 +44,11 @@ func SendTestMail(email string) error {
45
44
}
46
45
47
46
// SendUserMail sends a mail to the user
48
- func SendUserMail (c * macaron. Context , u * User , tpl base.TplName , code , subject , info string ) {
47
+ func SendUserMail (language string , u * User , tpl base.TplName , code , subject , info string ) {
49
48
data := map [string ]interface {}{
50
49
"DisplayName" : u .DisplayName (),
51
- "ActiveCodeLives" : base .MinutesToFriendly (setting .Service .ActiveCodeLives , c . Locale . Language () ),
52
- "ResetPwdCodeLives" : base .MinutesToFriendly (setting .Service .ResetPwdCodeLives , c . Locale . Language () ),
50
+ "ActiveCodeLives" : base .MinutesToFriendly (setting .Service .ActiveCodeLives , language ),
51
+ "ResetPwdCodeLives" : base .MinutesToFriendly (setting .Service .ResetPwdCodeLives , language ),
53
52
"Code" : code ,
54
53
}
55
54
@@ -66,21 +65,27 @@ func SendUserMail(c *macaron.Context, u *User, tpl base.TplName, code, subject,
66
65
mailer .SendAsync (msg )
67
66
}
68
67
68
+ // Locale represents an interface to translation
69
+ type Locale interface {
70
+ Language () string
71
+ Tr (string , ... interface {}) string
72
+ }
73
+
69
74
// SendActivateAccountMail sends an activation mail to the user (new user registration)
70
- func SendActivateAccountMail (c * macaron. Context , u * User ) {
71
- SendUserMail (c , u , mailAuthActivate , u .GenerateActivateCode (), c .Tr ("mail.activate_account" ), "activate account" )
75
+ func SendActivateAccountMail (locale Locale , u * User ) {
76
+ SendUserMail (locale . Language () , u , mailAuthActivate , u .GenerateActivateCode (), locale .Tr ("mail.activate_account" ), "activate account" )
72
77
}
73
78
74
79
// SendResetPasswordMail sends a password reset mail to the user
75
- func SendResetPasswordMail (c * macaron. Context , u * User ) {
76
- SendUserMail (c , u , mailAuthResetPassword , u .GenerateActivateCode (), c .Tr ("mail.reset_password" ), "recover account" )
80
+ func SendResetPasswordMail (locale Locale , u * User ) {
81
+ SendUserMail (locale . Language () , u , mailAuthResetPassword , u .GenerateActivateCode (), locale .Tr ("mail.reset_password" ), "recover account" )
77
82
}
78
83
79
84
// SendActivateEmailMail sends confirmation email to confirm new email address
80
- func SendActivateEmailMail (c * macaron. Context , u * User , email * EmailAddress ) {
85
+ func SendActivateEmailMail (locale Locale , u * User , email * EmailAddress ) {
81
86
data := map [string ]interface {}{
82
87
"DisplayName" : u .DisplayName (),
83
- "ActiveCodeLives" : base .MinutesToFriendly (setting .Service .ActiveCodeLives , c . Locale .Language ()),
88
+ "ActiveCodeLives" : base .MinutesToFriendly (setting .Service .ActiveCodeLives , locale .Language ()),
84
89
"Code" : u .GenerateEmailActivateCode (email .Email ),
85
90
"Email" : email .Email ,
86
91
}
@@ -92,14 +97,14 @@ func SendActivateEmailMail(c *macaron.Context, u *User, email *EmailAddress) {
92
97
return
93
98
}
94
99
95
- msg := mailer .NewMessage ([]string {email .Email }, c .Tr ("mail.activate_email" ), content .String ())
100
+ msg := mailer .NewMessage ([]string {email .Email }, locale .Tr ("mail.activate_email" ), content .String ())
96
101
msg .Info = fmt .Sprintf ("UID: %d, activate email" , u .ID )
97
102
98
103
mailer .SendAsync (msg )
99
104
}
100
105
101
106
// SendRegisterNotifyMail triggers a notify e-mail by admin created a account.
102
- func SendRegisterNotifyMail (c * macaron. Context , u * User ) {
107
+ func SendRegisterNotifyMail (locale Locale , u * User ) {
103
108
data := map [string ]interface {}{
104
109
"DisplayName" : u .DisplayName (),
105
110
"Username" : u .Name ,
@@ -112,7 +117,7 @@ func SendRegisterNotifyMail(c *macaron.Context, u *User) {
112
117
return
113
118
}
114
119
115
- msg := mailer .NewMessage ([]string {u .Email }, c .Tr ("mail.register_notify" ), content .String ())
120
+ msg := mailer .NewMessage ([]string {u .Email }, locale .Tr ("mail.register_notify" ), content .String ())
116
121
msg .Info = fmt .Sprintf ("UID: %d, registration notify" , u .ID )
117
122
118
123
mailer .SendAsync (msg )
0 commit comments