From ccd43b09b22f551070c2656dd2f4c7f347619a1c Mon Sep 17 00:00:00 2001 From: "shengxiang[skyblue]" Date: Tue, 18 Mar 2014 21:58:58 +0800 Subject: [PATCH] add some comment --- models/action.go | 4 +-- routers/user/setting.go | 2 ++ update.go | 4 +-- web.go | 58 ++++++++++++++++++++++------------------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/models/action.go b/models/action.go index 7917929df..d388bca99 100644 --- a/models/action.go +++ b/models/action.go @@ -22,8 +22,8 @@ const ( // Action represents user operation type and information to the repository. type Action struct { Id int64 - UserId int64 // Receiver user id. - OpType int + UserId int64 // Receiver user id. + OpType int // Operations: CREATE DELETE STAR ... ActUserId int64 // Action user id. ActUserName string // Action user name. RepoId int64 diff --git a/routers/user/setting.go b/routers/user/setting.go index 91e992b18..ea42f70cf 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -14,6 +14,7 @@ import ( "github.com/gogits/gogs/modules/middleware" ) +// render user setting page (email, website modify) func Setting(ctx *middleware.Context, form auth.UpdateProfileForm) { ctx.Data["Title"] = "Setting" ctx.Data["PageIsUserSetting"] = true @@ -26,6 +27,7 @@ func Setting(ctx *middleware.Context, form auth.UpdateProfileForm) { return } + // below is for POST requests if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) { ctx.Render.HTML(200, "user/setting", ctx.Data) return diff --git a/update.go b/update.go index 23d8fb028..baa433d75 100644 --- a/update.go +++ b/update.go @@ -10,8 +10,7 @@ import ( "github.com/codegangsta/cli" - git "github.com/gogits/git" - + "github.com/gogits/git" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/log" ) @@ -25,6 +24,7 @@ gogs serv provide access auth for repositories`, Flags: []cli.Flag{}, } +// for command: ./gogs update func runUpdate(*cli.Context) { userName := os.Getenv("userName") userId := os.Getenv("userId") diff --git a/web.go b/web.go index cc2009790..a0e397117 100644 --- a/web.go +++ b/web.go @@ -61,48 +61,52 @@ func runWeb(*cli.Context) { m.Use(middleware.InitContext()) + ignSignIn := middleware.SignInRequire(false) + reqSignIn, reqSignOut := middleware.SignInRequire(true), middleware.SignOutRequire() // Routers. - m.Get("/", middleware.SignInRequire(false), routers.Home) - m.Get("/issues", middleware.SignInRequire(true), user.Issues) - m.Get("/pulls", middleware.SignInRequire(true), user.Pulls) - m.Get("/stars", middleware.SignInRequire(true), user.Stars) - m.Any("/user/login", middleware.SignOutRequire(), binding.BindIgnErr(auth.LogInForm{}), user.SignIn) - m.Any("/user/logout", middleware.SignInRequire(true), user.SignOut) - m.Any("/user/sign_up", middleware.SignOutRequire(), binding.BindIgnErr(auth.RegisterForm{}), user.SignUp) - m.Any("/user/delete", middleware.SignInRequire(true), user.Delete) + 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.Any("/user/setting", middleware.SignInRequire(true), binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting) - m.Any("/user/setting/password", middleware.SignInRequire(true), binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword) - m.Any("/user/setting/ssh", middleware.SignInRequire(true), binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys) - m.Any("/user/setting/notification", middleware.SignInRequire(true), user.SettingNotification) - m.Any("/user/setting/security", middleware.SignInRequire(true), user.SettingSecurity) + 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("/user/:username", middleware.SignInRequire(false), user.Profile) + m.Get("/user/:username", ignSignIn, user.Profile) - m.Any("/repo/create", middleware.SignInRequire(true), binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create) + m.Any("/repo/create", reqSignIn, binding.BindIgnErr(auth.CreateRepoForm{}), repo.Create) m.Get("/help", routers.Help) - m.Post("/:username/:reponame/settings", middleware.SignInRequire(true), middleware.RepoAssignment(true), repo.SettingPost) - m.Get("/:username/:reponame/settings", middleware.SignInRequire(true), middleware.RepoAssignment(true), repo.Setting) + 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", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Commits) - m.Get("/:username/:reponame/issues", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Issues) - m.Get("/:username/:reponame/pulls", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Pulls) - m.Get("/:username/:reponame/branches", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Branches) + 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/tree/:branchname/**", - middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single) + ignSignIn, middleware.RepoAssignment(true), repo.Single) m.Get("/:username/:reponame/tree/:branchname", - middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single) - m.Get("/:username/:reponame/commit/:commitid/**", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single) - m.Get("/:username/:reponame/commit/:commitid", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single) + 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", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single) + m.Get("/:username/:reponame", ignSignIn, middleware.RepoAssignment(true), repo.Single) listenAddr := fmt.Sprintf("%s:%s", base.Cfg.MustValue("server", "HTTP_ADDR"), base.Cfg.MustValue("server", "HTTP_PORT", "3000")) log.Info("Listen: %s", listenAddr) - http.ListenAndServe(listenAddr, m) + if err := http.ListenAndServe(listenAddr, m); err != nil { + log.Critical(err.Error()) + } }