diff options
Diffstat (limited to 'routers')
-rw-r--r-- | routers/admin/admin.go | 3 | ||||
-rw-r--r-- | routers/admin/users.go | 5 | ||||
-rw-r--r-- | routers/api/v1/admin/user.go | 6 | ||||
-rw-r--r-- | routers/init.go | 2 | ||||
-rw-r--r-- | routers/repo/setting.go | 3 | ||||
-rw-r--r-- | routers/routes/routes.go | 3 | ||||
-rw-r--r-- | routers/user/auth.go | 12 | ||||
-rw-r--r-- | routers/user/auth_openid.go | 4 | ||||
-rw-r--r-- | routers/user/setting/account.go | 3 |
9 files changed, 26 insertions, 15 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 496aca375f..538d01f9a4 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -22,6 +22,7 @@ import ( "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/services/mailer" "gitea.com/macaron/macaron" "github.com/unknwon/com" @@ -197,7 +198,7 @@ func Dashboard(ctx *context.Context) { func SendTestMail(ctx *context.Context) { email := ctx.Query("email") // Send a test email to the user's email address and redirect back to Config - if err := models.SendTestMail(email); err != nil { + if err := mailer.SendTestMail(email); err != nil { ctx.Flash.Error(ctx.Tr("admin.config.test_mail_failed", email, err)) } else { ctx.Flash.Info(ctx.Tr("admin.config.test_mail_sent", email)) diff --git a/routers/admin/users.go b/routers/admin/users.go index aa595edad9..660f116682 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/routers" + "code.gitea.io/gitea/services/mailer" "github.com/unknwon/com" ) @@ -116,8 +117,8 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) { log.Trace("Account created by admin (%s): %s", ctx.User.Name, u.Name) // Send email notification. - if form.SendNotify && setting.MailService != nil { - models.SendRegisterNotifyMail(ctx.Context, u) + if form.SendNotify { + mailer.SendRegisterNotifyMail(ctx.Locale, u) } ctx.Flash.Success(ctx.Tr("admin.users.new_success", u.Name)) diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go index f4b694aa22..70076b626b 100644 --- a/routers/api/v1/admin/user.go +++ b/routers/api/v1/admin/user.go @@ -9,10 +9,10 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/routers/api/v1/convert" "code.gitea.io/gitea/routers/api/v1/user" + "code.gitea.io/gitea/services/mailer" ) func parseLoginSource(ctx *context.APIContext, u *models.User, sourceID int64, loginName string) { @@ -88,8 +88,8 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) { log.Trace("Account created by admin (%s): %s", ctx.User.Name, u.Name) // Send email notification. - if form.SendNotify && setting.MailService != nil { - models.SendRegisterNotifyMail(ctx.Context.Context, u) + if form.SendNotify { + mailer.SendRegisterNotifyMail(ctx.Locale, u) } ctx.JSON(201, convert.ToUser(u, ctx.IsSigned, ctx.User.IsAdmin)) } diff --git a/routers/init.go b/routers/init.go index fdf90904ce..5c8741f244 100644 --- a/routers/init.go +++ b/routers/init.go @@ -16,11 +16,11 @@ import ( "code.gitea.io/gitea/modules/highlight" issue_indexer "code.gitea.io/gitea/modules/indexer/issues" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/mailer" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/external" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/ssh" + "code.gitea.io/gitea/services/mailer" "gitea.com/macaron/macaron" ) diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 91db519d62..b0af396e7d 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -24,6 +24,7 @@ import ( "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/validation" "code.gitea.io/gitea/routers/utils" + "code.gitea.io/gitea/services/mailer" "github.com/unknwon/com" "mvdan.cc/xurls/v2" @@ -549,7 +550,7 @@ func CollaborationPost(ctx *context.Context) { } if setting.Service.EnableNotifyMail { - models.SendCollaboratorMail(u, ctx.User, ctx.Repo.Repository) + mailer.SendCollaboratorMail(u, ctx.User, ctx.Repo.Repository) } ctx.Flash.Success(ctx.Tr("repo.settings.add_collaborator_success")) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 93ce220b00..e18ac0923e 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -34,6 +34,7 @@ import ( "code.gitea.io/gitea/routers/repo" "code.gitea.io/gitea/routers/user" userSetting "code.gitea.io/gitea/routers/user/setting" + "code.gitea.io/gitea/services/mailer" // to registers all internal adapters _ "code.gitea.io/gitea/modules/session" @@ -166,7 +167,7 @@ func NewMacaron() *macaron.Macaron { )) m.Use(templates.HTMLRenderer()) - models.InitMailRender(templates.Mailer()) + mailer.InitMailRender(templates.Mailer()) localeNames, err := options.Dir("locale") diff --git a/routers/user/auth.go b/routers/user/auth.go index dedb9c7b0d..3def867f64 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -21,6 +21,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/services/mailer" "gitea.com/macaron/captcha" "github.com/markbates/goth" @@ -948,7 +949,8 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au // Send confirmation email if setting.Service.RegisterEmailConfirm && u.ID > 1 { - models.SendActivateAccountMail(ctx.Context, u) + mailer.SendActivateAccountMail(ctx.Locale, u) + ctx.Data["IsSendRegisterMail"] = true ctx.Data["Email"] = u.Email ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) @@ -1094,7 +1096,8 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo // Send confirmation email, no need for social account. if setting.Service.RegisterEmailConfirm && u.ID > 1 { - models.SendActivateAccountMail(ctx.Context, u) + mailer.SendActivateAccountMail(ctx.Locale, u) + ctx.Data["IsSendRegisterMail"] = true ctx.Data["Email"] = u.Email ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) @@ -1125,7 +1128,7 @@ func Activate(ctx *context.Context) { ctx.Data["ResendLimited"] = true } else { ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) - models.SendActivateAccountMail(ctx.Context, ctx.User) + mailer.SendActivateAccountMail(ctx.Locale, ctx.User) if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil { log.Error("Set cache(MailResendLimit) fail: %v", err) @@ -1247,7 +1250,8 @@ func ForgotPasswdPost(ctx *context.Context) { return } - models.SendResetPasswordMail(ctx.Context, u) + mailer.SendResetPasswordMail(ctx.Locale, u) + if err = ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { log.Error("Set cache(MailResendLimit) fail: %v", err) } diff --git a/routers/user/auth_openid.go b/routers/user/auth_openid.go index 832766b16c..ccaea8264f 100644 --- a/routers/user/auth_openid.go +++ b/routers/user/auth_openid.go @@ -18,6 +18,7 @@ import ( "code.gitea.io/gitea/modules/recaptcha" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/services/mailer" "gitea.com/macaron/captcha" ) @@ -444,7 +445,8 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si // Send confirmation email, no need for social account. if setting.Service.RegisterEmailConfirm && u.ID > 1 { - models.SendActivateAccountMail(ctx.Context, u) + mailer.SendActivateAccountMail(ctx.Locale, u) + ctx.Data["IsSendRegisterMail"] = true ctx.Data["Email"] = u.Email ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) diff --git a/routers/user/setting/account.go b/routers/user/setting/account.go index 674606cce8..71d98fd3b9 100644 --- a/routers/user/setting/account.go +++ b/routers/user/setting/account.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/services/mailer" ) const ( @@ -130,7 +131,7 @@ func EmailPost(ctx *context.Context, form auth.AddEmailForm) { // Send confirmation email if setting.Service.RegisterEmailConfirm { - models.SendActivateEmailMail(ctx.Context, ctx.User, email) + mailer.SendActivateEmailMail(ctx.Locale, ctx.User, email) if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil { log.Error("Set cache(MailResendLimit) fail: %v", err) |