Skip to content

Commit e63274e

Browse files
lunnylafriks
authored andcommitted
remove macaron dependent on models/mail.go (#6931)
1 parent 36b68fd commit e63274e

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

models/mail.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"code.gitea.io/gitea/modules/markup/markdown"
1818
"code.gitea.io/gitea/modules/setting"
1919
"gopkg.in/gomail.v2"
20-
"gopkg.in/macaron.v1"
2120
)
2221

2322
const (
@@ -45,11 +44,11 @@ func SendTestMail(email string) error {
4544
}
4645

4746
// 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) {
4948
data := map[string]interface{}{
5049
"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),
5352
"Code": code,
5453
}
5554

@@ -66,21 +65,27 @@ func SendUserMail(c *macaron.Context, u *User, tpl base.TplName, code, subject,
6665
mailer.SendAsync(msg)
6766
}
6867

68+
// Locale represents an interface to translation
69+
type Locale interface {
70+
Language() string
71+
Tr(string, ...interface{}) string
72+
}
73+
6974
// 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")
7277
}
7378

7479
// 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")
7782
}
7883

7984
// 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) {
8186
data := map[string]interface{}{
8287
"DisplayName": u.DisplayName(),
83-
"ActiveCodeLives": base.MinutesToFriendly(setting.Service.ActiveCodeLives, c.Locale.Language()),
88+
"ActiveCodeLives": base.MinutesToFriendly(setting.Service.ActiveCodeLives, locale.Language()),
8489
"Code": u.GenerateEmailActivateCode(email.Email),
8590
"Email": email.Email,
8691
}
@@ -92,14 +97,14 @@ func SendActivateEmailMail(c *macaron.Context, u *User, email *EmailAddress) {
9297
return
9398
}
9499

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())
96101
msg.Info = fmt.Sprintf("UID: %d, activate email", u.ID)
97102

98103
mailer.SendAsync(msg)
99104
}
100105

101106
// 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) {
103108
data := map[string]interface{}{
104109
"DisplayName": u.DisplayName(),
105110
"Username": u.Name,
@@ -112,7 +117,7 @@ func SendRegisterNotifyMail(c *macaron.Context, u *User) {
112117
return
113118
}
114119

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())
116121
msg.Info = fmt.Sprintf("UID: %d, registration notify", u.ID)
117122

118123
mailer.SendAsync(msg)

0 commit comments

Comments
 (0)