Convert captcha, cache, csrf as middlewares

This commit is contained in:
Unknwon 2014-07-31 17:25:34 -04:00
parent 3428baa3b5
commit 7bbf644dd5
17 changed files with 46 additions and 1122 deletions

View file

@ -9,6 +9,7 @@ import (
"strings"
"github.com/Unknwon/macaron"
"github.com/macaron-contrib/csrf"
"github.com/gogits/gogs/modules/setting"
)
@ -34,9 +35,11 @@ func Toggle(options *ToggleOptions) macaron.Handler {
return
}
if !options.DisableCsrf && ctx.Req.Method == "POST" && !ctx.CsrfTokenValid() {
ctx.Error(403, "CSRF token does not match")
return
if !options.SignOutRequire && !options.DisableCsrf && ctx.Req.Method == "POST" {
csrf.Validate(ctx.Context, ctx.csrf)
if ctx.Written() {
return
}
}
if options.SignInRequire {