diff options
author | skyblue <ssx205@gmail.com> | 2014-03-23 22:40:35 +0800 |
---|---|---|
committer | skyblue <ssx205@gmail.com> | 2014-03-23 22:40:35 +0800 |
commit | 4bac3616055110da6f060e98174bc2381ef91286 (patch) | |
tree | 6fc09df1b6bef1a73fac40771702ae5f4f71f1d4 /web.go | |
parent | b9302749ddc0e0a10911a83bf80e165b792c8c1e (diff) | |
parent | f7f175a0793a53f3c50d20d89e324a610f94c442 (diff) | |
download | gitea-4bac3616055110da6f060e98174bc2381ef91286.tar.gz gitea-4bac3616055110da6f060e98174bc2381ef91286.zip |
merge with branch master
Diffstat (limited to 'web.go')
-rw-r--r-- | web.go | 122 |
1 files changed, 72 insertions, 50 deletions
@@ -12,7 +12,6 @@ import ( "github.com/codegangsta/cli" "github.com/codegangsta/martini" - "github.com/martini-contrib/sessions" "github.com/gogits/binding" @@ -82,72 +81,95 @@ func runWeb(*cli.Context) { // Middlewares. m.Use(middleware.Renderer(middleware.RenderOptions{Funcs: []template.FuncMap{base.TemplateFuncs}})) - // TODO: should use other store because cookie store is not secure. - store := sessions.NewCookieStore([]byte("secret123")) - m.Use(sessions.Sessions("my_session", store)) - m.Use(middleware.InitContext()) - reqSignIn := middleware.SignInRequire(true) - ignSignIn := middleware.SignInRequire(base.Service.RequireSignInView) - reqSignOut := middleware.SignOutRequire() + reqSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true}) + ignSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: base.Service.RequireSignInView}) + reqSignOut := middleware.Toggle(&middleware.ToggleOptions{SignOutRequire: true}) + // Routers. m.Get("/", ignSignIn, routers.Home) m.Get("/issues", reqSignIn, user.Issues) m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/stars", reqSignIn, user.Stars) - m.Any("/user/login", reqSignOut, binding.BindIgnErr(auth.LogInForm{}), user.SignIn) - m.Any("/user/logout", reqSignIn, user.SignOut) - m.Any("/user/sign_up", reqSignOut, binding.BindIgnErr(auth.RegisterForm{}), user.SignUp) - m.Any("/user/delete", reqSignIn, user.Delete) - m.Get("/user/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds) - m.Get("/user/activate", user.Activate) - - m.Any("/user/setting", reqSignIn, binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting) - m.Any("/user/setting/password", reqSignIn, binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword) - m.Any("/user/setting/ssh", reqSignIn, binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys) - m.Any("/user/setting/notification", reqSignIn, user.SettingNotification) - m.Any("/user/setting/security", reqSignIn, user.SettingSecurity) + m.Get("/help", routers.Help) + + avatarCache := avatar.HttpHandler("public/img/avatar/", "public/img/avatar/default.jpg") + m.Get("/avatar/:hash", avatarCache.ServeHTTP) + + m.Group("/user", func(r martini.Router) { + r.Any("/login", binding.BindIgnErr(auth.LogInForm{}), user.SignIn) + r.Any("/sign_up", binding.BindIgnErr(auth.RegisterForm{}), user.SignUp) + }, reqSignOut) + m.Group("/user", func(r martini.Router) { + r.Any("/logout", user.SignOut) + r.Any("/delete", user.Delete) + r.Any("/setting", binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting) + }, reqSignIn) + m.Group("/user", func(r martini.Router) { + r.Get("/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds) + r.Get("/activate", user.Activate) + }) + + m.Group("/user/setting", func(r martini.Router) { + r.Any("/password", binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword) + r.Any("/ssh", binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys) + r.Any("/notification", user.SettingNotification) + r.Any("/security", user.SettingSecurity) + }, reqSignIn) m.Get("/user/:username", ignSignIn, user.Profile) m.Any("/repo/create", reqSignIn, binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create) - m.Get("/help", routers.Help) - - avatarHandler := avatar.HttpHandler("public/img/avatar", "public/img/avatar/default.jpg") - m.Get("/avatar/:hash", avatarHandler.ServeHTTP) - - adminReq := middleware.AdminRequire() - m.Get("/admin", reqSignIn, adminReq, admin.Dashboard) - m.Get("/admin/users", reqSignIn, adminReq, admin.Users) - m.Any("/admin/users/new", reqSignIn, adminReq, binding.BindIgnErr(auth.RegisterForm{}), admin.NewUser) - m.Any("/admin/users/:userid", reqSignIn, adminReq, binding.BindIgnErr(auth.AdminEditUserForm{}), admin.EditUser) - m.Get("/admin/repos", reqSignIn, adminReq, admin.Repositories) - m.Get("/admin/config", reqSignIn, adminReq, admin.Config) - - m.Post("/:username/:reponame/settings", reqSignIn, middleware.RepoAssignment(true), repo.SettingPost) - m.Get("/:username/:reponame/settings", reqSignIn, middleware.RepoAssignment(true), repo.Setting) - - m.Get("/:username/:reponame/commits/:branchname", ignSignIn, middleware.RepoAssignment(true), repo.Commits) - m.Get("/:username/:reponame/issues", ignSignIn, middleware.RepoAssignment(true), repo.Issues) - m.Get("/:username/:reponame/pulls", ignSignIn, middleware.RepoAssignment(true), repo.Pulls) - m.Get("/:username/:reponame/branches", ignSignIn, middleware.RepoAssignment(true), repo.Branches) - m.Get("/:username/:reponame/action/:action", reqSignIn, middleware.RepoAssignment(true), repo.Action) - m.Get("/:username/:reponame/src/:branchname/**", - ignSignIn, middleware.RepoAssignment(true), repo.Single) - m.Get("/:username/:reponame/src/:branchname", - ignSignIn, middleware.RepoAssignment(true), repo.Single) - m.Get("/:username/:reponame/commit/:commitid/**", ignSignIn, middleware.RepoAssignment(true), repo.Single) - m.Get("/:username/:reponame/commit/:commitid", ignSignIn, middleware.RepoAssignment(true), repo.Single) - m.Get("/:username/:reponame", ignSignIn, middleware.RepoAssignment(true), repo.Single) - - m.Any("/:username/:reponame/**", ignSignIn, repo.Http) + adminReq := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true, AdminRequire: true}) + + m.Get("/admin", adminReq, admin.Dashboard) + m.Group("/admin", func(r martini.Router) { + r.Get("/users", admin.Users) + r.Get("/repos", admin.Repositories) + r.Get("/config", admin.Config) + }, adminReq) + m.Group("/admin/users", func(r martini.Router) { + r.Any("/new", binding.BindIgnErr(auth.RegisterForm{}), admin.NewUser) + r.Any("/:userid", binding.BindIgnErr(auth.AdminEditUserForm{}), admin.EditUser) + r.Any("/:userid/delete", admin.DeleteUser) + }, adminReq) + + m.Group("/:username/:reponame", func(r martini.Router) { + r.Post("/settings", repo.SettingPost) + r.Get("/settings", repo.Setting) + r.Get("/action/:action", repo.Action) + }, reqSignIn, middleware.RepoAssignment(true)) + m.Group("/:username/:reponame", func(r martini.Router) { + r.Get("/commits/:branchname", repo.Commits) + r.Get("/issues", repo.Issues) + r.Any("/issues/new", binding.BindIgnErr(auth.CreateIssueForm{}), repo.CreateIssue) + r.Get("/issues/:issueid", repo.ViewIssue) + r.Get("/pulls", repo.Pulls) + r.Get("/branches", repo.Branches) + r.Get("/src/:branchname", repo.Single) + r.Get("/src/:branchname/**", repo.Single) + r.Get("/commits/:branchname", repo.Commits) + r.Get("/commits/:branchname", repo.Commits) + }, ignSignIn, middleware.RepoAssignment(true)) + + // TODO: implement single commit page + // m.Get("/:username/:reponame/commit/:commitid/**", ignSignIn, middleware.RepoAssignment(true), repo.Single) + // m.Get("/:username/:reponame/commit/:commitid", ignSignIn, middleware.RepoAssignment(true), repo.Single) + + m.Group("/:username", func(r martini.Router) { + r.Get("/:reponame", middleware.RepoAssignment(true), repo.Single) + r.Any("/:reponame/**", repo.Http) + }, ignSignIn) if martini.Env == martini.Dev { m.Get("/template/**", dev.TemplatePreview) } + // Not found handler. + m.NotFound(routers.NotFound) + listenAddr := fmt.Sprintf("%s:%s", base.Cfg.MustValue("server", "HTTP_ADDR"), base.Cfg.MustValue("server", "HTTP_PORT", "3000")) |