diff options
author | Unknwon <joe2010xtmf@163.com> | 2014-07-31 17:25:34 -0400 |
---|---|---|
committer | Unknwon <joe2010xtmf@163.com> | 2014-07-31 17:25:34 -0400 |
commit | 7bbf644dd5eaca77c3e8df57419180486bda0fc2 (patch) | |
tree | 84033fb9507c4657d74b85dccd5f16595f8517a8 /cmd/web.go | |
parent | 3428baa3b57b39f2e010254bffede93e7d3cdf37 (diff) | |
download | gitea-7bbf644dd5eaca77c3e8df57419180486bda0fc2.tar.gz gitea-7bbf644dd5eaca77c3e8df57419180486bda0fc2.zip |
Convert captcha, cache, csrf as middlewares
Diffstat (limited to 'cmd/web.go')
-rw-r--r-- | cmd/web.go | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/cmd/web.go b/cmd/web.go index a0690cda25..bd2eb79dbd 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -14,6 +14,9 @@ import ( "github.com/Unknwon/macaron" "github.com/codegangsta/cli" + "github.com/macaron-contrib/cache" + "github.com/macaron-contrib/captcha" + "github.com/macaron-contrib/csrf" "github.com/macaron-contrib/i18n" "github.com/macaron-contrib/session" @@ -21,7 +24,6 @@ import ( "github.com/gogits/gogs/modules/auth/apiv1" "github.com/gogits/gogs/modules/avatar" "github.com/gogits/gogs/modules/base" - "github.com/gogits/gogs/modules/captcha" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware/binding" @@ -78,10 +80,20 @@ func newMacaron() *macaron.Macaron { Names: setting.Names, Redirect: true, })) + m.Use(cache.Cacher(cache.Options{ + Adapter: setting.CacheAdapter, + Interval: setting.CacheInternal, + Conn: setting.CacheConn, + })) + m.Use(captcha.Captchaer()) m.Use(session.Sessioner(session.Options{ Provider: setting.SessionProvider, Config: *setting.SessionConfig, })) + m.Use(csrf.Generate(csrf.Options{ + Secret: setting.SecretKey, + SetCookie: true, + })) m.Use(middleware.Contexter()) return m } @@ -121,16 +133,12 @@ func runWeb(*cli.Context) { // Repositories. r.Get("/orgs/:org/repos/search", v1.SearchOrgRepositoreis) - r.Any("**", func(ctx *middleware.Context) { + r.Any("/*", func(ctx *middleware.Context) { ctx.JSON(404, &base.ApiJsonErr{"Not Found", v1.DOC_URL}) }) }) }) - avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg") - os.MkdirAll("public/img/avatar/", os.ModePerm) - m.Get("/avatar/:hash", avt.ServeHTTP) - // User routers. m.Group("/user", func(r *macaron.Router) { r.Get("/login", user.SignIn) @@ -165,10 +173,10 @@ func runWeb(*cli.Context) { m.Get("/user/:username", ignSignIn, user.Profile) // TODO: Legacy - // Captcha service. - cpt := captcha.NewCaptcha("/captcha/", setting.Cache) - m.Map(cpt) - m.Get("/captcha/*", cpt.Handler) + // Gravatar service. + avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg") + os.MkdirAll("public/img/avatar/", os.ModePerm) + m.Get("/avatar/:hash", avt.ServeHTTP) adminReq := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true, AdminRequire: true}) @@ -199,7 +207,7 @@ func runWeb(*cli.Context) { m.Get("/:username", ignSignIn, user.Profile) if macaron.Env == macaron.DEV { - m.Get("/template/**", dev.TemplatePreview) + m.Get("/template/*", dev.TemplatePreview) dev.RegisterDebugRoutes(m) } |