aboutsummaryrefslogtreecommitdiff
path: root/modules/middleware/context.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/middleware/context.go')
-rw-r--r--modules/middleware/context.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/modules/middleware/context.go b/modules/middleware/context.go
index 6ac87de3..a25a3dbb 100644
--- a/modules/middleware/context.go
+++ b/modules/middleware/context.go
@@ -12,8 +12,11 @@ import (
"github.com/codegangsta/martini"
"github.com/martini-contrib/sessions"
+ "github.com/gogits/cache"
+
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
+ "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log"
)
@@ -25,6 +28,7 @@ type Context struct {
Req *http.Request
Res http.ResponseWriter
Session sessions.Session
+ Cache cache.Cache
User *models.User
IsSigned bool
@@ -61,24 +65,29 @@ func (ctx *Context) HasError() bool {
return hasErr.(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...)
+}
+
// 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.HTML(200, tpl, ctx.Data)
+ ctx.HTML(200, tpl)
}
// Handle handles and logs error by given status.
func (ctx *Context) Handle(status int, title string, err error) {
log.Error("%s: %v", title, err)
if martini.Dev == martini.Prod {
- ctx.HTML(500, "status/500", ctx.Data)
+ ctx.HTML(500, "status/500")
return
}
ctx.Data["ErrorMsg"] = err
- ctx.HTML(status, fmt.Sprintf("status/%d", status), ctx.Data)
+ ctx.HTML(status, fmt.Sprintf("status/%d", status))
}
// InitContext initializes a classic context for a request.
@@ -92,6 +101,7 @@ func InitContext() martini.Handler {
Req: r,
Res: res,
Session: session,
+ Cache: base.Cache,
Render: rd,
}
@@ -106,6 +116,7 @@ func InitContext() martini.Handler {
ctx.Data["SignedUser"] = user
ctx.Data["SignedUserId"] = user.Id
ctx.Data["SignedUserName"] = user.LowerName
+ ctx.Data["IsAdmin"] = ctx.User.IsAdmin
}
ctx.Data["PageStartTime"] = time.Now()