summaryrefslogtreecommitdiffstats
path: root/modules/middleware
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-05 13:08:01 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-05 13:08:01 -0400
commitc1eb4d894a092aed1b87ddf5f80ee824fd56789d (patch)
treeb58beee7c762cbbb1cec524c16471788820609b6 /modules/middleware
parent5f653898f3b39669ce9dbf0ee2263c391695019d (diff)
downloadgitea-c1eb4d894a092aed1b87ddf5f80ee824fd56789d.tar.gz
gitea-c1eb4d894a092aed1b87ddf5f80ee824fd56789d.zip
Clean api code
Diffstat (limited to 'modules/middleware')
-rw-r--r--modules/middleware/auth.go12
-rw-r--r--modules/middleware/context.go13
2 files changed, 18 insertions, 7 deletions
diff --git a/modules/middleware/auth.go b/modules/middleware/auth.go
index 39b7796d92..cd00d4679e 100644
--- a/modules/middleware/auth.go
+++ b/modules/middleware/auth.go
@@ -21,23 +21,21 @@ type ToggleOptions struct {
func Toggle(options *ToggleOptions) martini.Handler {
return func(ctx *Context) {
+ // Cannot view any page before installation.
if !base.InstallLock {
ctx.Redirect("/install")
return
}
+ // Redirect to dashboard if user tries to visit any non-login page.
if options.SignOutRequire && ctx.IsSigned && ctx.Req.RequestURI != "/" {
ctx.Redirect("/")
return
}
- if !options.DisableCsrf {
- if ctx.Req.Method == "POST" {
- if !ctx.CsrfTokenValid() {
- ctx.Error(403, "CSRF token does not match")
- return
- }
- }
+ if !options.DisableCsrf && ctx.Req.Method == "POST" && !ctx.CsrfTokenValid() {
+ ctx.Error(403, "CSRF token does not match")
+ return
}
if options.SignInRequire {
diff --git a/modules/middleware/context.go b/modules/middleware/context.go
index 31fdca681a..e9084d330c 100644
--- a/modules/middleware/context.go
+++ b/modules/middleware/context.go
@@ -79,6 +79,19 @@ func (ctx *Context) Query(name string) string {
// }
// HasError returns true if error occurs in form validation.
+func (ctx *Context) HasApiError() bool {
+ hasErr, ok := ctx.Data["HasError"]
+ if !ok {
+ return false
+ }
+ return hasErr.(bool)
+}
+
+func (ctx *Context) GetErrMsg() string {
+ return ctx.Data["ErrorMsg"].(string)
+}
+
+// HasError returns true if error occurs in form validation.
func (ctx *Context) HasError() bool {
hasErr, ok := ctx.Data["HasError"]
if !ok {