forked from NYANDEV/forgejo
Convert captcha, cache, csrf as middlewares
This commit is contained in:
parent
3428baa3b5
commit
7bbf644dd5
17 changed files with 46 additions and 1122 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue