aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2014-03-15 23:38:58 +0800
committerLunny Xiao <xiaolunwen@gmail.com>2014-03-15 23:38:58 +0800
commitf047df6e2b69ecb41c3fe4bef746145916aa4063 (patch)
tree3dac61306b89a9040df6bad3afa2c98a9601fedb /modules
parent6bdd6f9b18136a6066f3fc87349037027eb7a499 (diff)
parentb43cfc5b39c0aeec04b1810f01e57ece96abdd7e (diff)
Merge branch 'master' of github.com:gogits/gogs
Diffstat (limited to 'modules')
-rw-r--r--modules/middleware/context.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/modules/middleware/context.go b/modules/middleware/context.go
index 7a1dba3d..d3fe7bbf 100644
--- a/modules/middleware/context.go
+++ b/modules/middleware/context.go
@@ -41,6 +41,23 @@ func (ctx *Context) Query(name string) string {
// return ctx.p[name]
// }
+// HasError returns true if error occurs in form validation.
+func (ctx *Context) HasError() bool {
+ hasErr, ok := ctx.Data["HasError"]
+ if !ok {
+ return false
+ }
+ return hasErr.(bool)
+}
+
+// RenderWithErr used for page has form validation but need to prompt error to users.
+func (ctx *Context) RenderWithErr(msg, tpl string, form auth.Form) {
+ ctx.Data["HasError"] = true
+ ctx.Data["ErrorMsg"] = msg
+ auth.AssignForm(form, ctx.Data)
+ ctx.Render.HTML(200, tpl, ctx.Data)
+}
+
// Handle handles and logs error by given status.
func (ctx *Context) Handle(status int, title string, err error) {
ctx.Data["ErrorMsg"] = err