diff options
author | Unknown <joe2010xtmf@163.com> | 2014-06-22 13:14:03 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-06-22 13:14:03 -0400 |
commit | 9924e65ca11770f247723b10fcbdb81dc9534b32 (patch) | |
tree | 23995a2838ac24c88ebfd9267b567ec7e4f1a05c /modules | |
parent | c280415e0b449b420f4540886b8e16ae3c9e6454 (diff) | |
download | gitea-9924e65ca11770f247723b10fcbdb81dc9534b32.tar.gz gitea-9924e65ca11770f247723b10fcbdb81dc9534b32.zip |
In progress of name template name constant
Diffstat (limited to 'modules')
-rw-r--r-- | modules/base/base.go | 1 | ||||
-rw-r--r-- | modules/mailer/mail.go | 19 | ||||
-rw-r--r-- | modules/middleware/context.go | 8 |
3 files changed, 19 insertions, 9 deletions
diff --git a/modules/base/base.go b/modules/base/base.go index 145fae6f13..570600c3d4 100644 --- a/modules/base/base.go +++ b/modules/base/base.go @@ -7,6 +7,7 @@ package base type ( // Type TmplData represents data in the templates. TmplData map[string]interface{} + TplName string ApiJsonErr struct { Message string `json:"message"` diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go index e212d0066f..62e15cd7fe 100644 --- a/modules/mailer/mail.go +++ b/modules/mailer/mail.go @@ -17,6 +17,15 @@ import ( "github.com/gogits/gogs/modules/setting" ) +const ( + AUTH_ACTIVE base.TplName = "mail/auth/active" + AUTH_REGISTER_SUCCESS base.TplName = "mail/auth/register_success" + AUTH_RESET_PASSWORD base.TplName = "mail/auth/reset_passwd" + + NOTIFY_COLLABORATOR base.TplName = "mail/notify/collaborator" + NOTIFY_MENTION base.TplName = "mail/notify/mention" +) + // Create New mail message use MailFrom and MailUser func NewMailMessageFrom(To []string, from, subject, body string) Message { msg := NewHtmlMessage(To, from, subject, body) @@ -61,7 +70,7 @@ func SendRegisterMail(r *middleware.Render, u *models.User) { data := GetMailTmplData(u) data["Code"] = code - body, err := r.HTMLString("mail/auth/register_success", data) + body, err := r.HTMLString(string(AUTH_REGISTER_SUCCESS), data) if err != nil { log.Error("mail.SendRegisterMail(fail to render): %v", err) return @@ -81,7 +90,7 @@ func SendActiveMail(r *middleware.Render, u *models.User) { data := GetMailTmplData(u) data["Code"] = code - body, err := r.HTMLString("mail/auth/active_email", data) + body, err := r.HTMLString(string(AUTH_ACTIVE), data) if err != nil { log.Error("mail.SendActiveMail(fail to render): %v", err) return @@ -101,7 +110,7 @@ func SendResetPasswdMail(r *middleware.Render, u *models.User) { data := GetMailTmplData(u) data["Code"] = code - body, err := r.HTMLString("mail/auth/reset_passwd", data) + body, err := r.HTMLString(string(AUTH_RESET_PASSWORD), data) if err != nil { log.Error("mail.SendResetPasswdMail(fail to render): %v", err) return @@ -161,7 +170,7 @@ func SendIssueMentionMail(r *middleware.Render, u, owner *models.User, data["IssueLink"] = fmt.Sprintf("%s/%s/issues/%d", owner.Name, repo.Name, issue.Index) data["Subject"] = subject - body, err := r.HTMLString("mail/notify/mention", data) + body, err := r.HTMLString(string(NOTIFY_MENTION), data) if err != nil { return fmt.Errorf("mail.SendIssueMentionMail(fail to render): %v", err) } @@ -182,7 +191,7 @@ func SendCollaboratorMail(r *middleware.Render, u, owner *models.User, data["RepoLink"] = path.Join(owner.Name, repo.Name) data["Subject"] = subject - body, err := r.HTMLString("mail/notify/collaborator", data) + body, err := r.HTMLString(string(NOTIFY_COLLABORATOR), data) if err != nil { return fmt.Errorf("mail.SendCollaboratorMail(fail to render): %v", err) } diff --git a/modules/middleware/context.go b/modules/middleware/context.go index 19556118e3..45f0140a28 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -104,12 +104,12 @@ func (ctx *Context) HasError() bool { } // HTML calls render.HTML underlying but reduce one argument. -func (ctx *Context) HTML(status int, name string, htmlOpt ...HTMLOptions) { - ctx.Render.HTML(status, name, ctx.Data, htmlOpt...) +func (ctx *Context) HTML(status int, name base.TplName, htmlOpt ...HTMLOptions) { + ctx.Render.HTML(status, string(name), ctx.Data, htmlOpt...) } // RenderWithErr used for page has form validation but need to prompt error to users. -func (ctx *Context) RenderWithErr(msg, tpl string, form auth.Form) { +func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form auth.Form) { if form != nil { auth.AssignForm(form, ctx.Data) } @@ -133,7 +133,7 @@ func (ctx *Context) Handle(status int, title string, err error) { case 500: ctx.Data["Title"] = "Internal Server Error" } - ctx.HTML(status, fmt.Sprintf("status/%d", status)) + ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status))) } func (ctx *Context) Debug(msg string, args ...interface{}) { |