1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 12:54:53 -05:00

add some comment

This commit is contained in:
shengxiang[skyblue] 2014-03-18 21:58:58 +08:00
parent 76644c2fcc
commit ccd43b09b2
4 changed files with 37 additions and 31 deletions

View file

@ -23,7 +23,7 @@ const (
type Action struct { type Action struct {
Id int64 Id int64
UserId int64 // Receiver user id. UserId int64 // Receiver user id.
OpType int OpType int // Operations: CREATE DELETE STAR ...
ActUserId int64 // Action user id. ActUserId int64 // Action user id.
ActUserName string // Action user name. ActUserName string // Action user name.
RepoId int64 RepoId int64

View file

@ -14,6 +14,7 @@ import (
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
) )
// render user setting page (email, website modify)
func Setting(ctx *middleware.Context, form auth.UpdateProfileForm) { func Setting(ctx *middleware.Context, form auth.UpdateProfileForm) {
ctx.Data["Title"] = "Setting" ctx.Data["Title"] = "Setting"
ctx.Data["PageIsUserSetting"] = true ctx.Data["PageIsUserSetting"] = true
@ -26,6 +27,7 @@ func Setting(ctx *middleware.Context, form auth.UpdateProfileForm) {
return return
} }
// below is for POST requests
if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) { if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) {
ctx.Render.HTML(200, "user/setting", ctx.Data) ctx.Render.HTML(200, "user/setting", ctx.Data)
return return

View file

@ -10,8 +10,7 @@ import (
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
git "github.com/gogits/git" "github.com/gogits/git"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/log"
) )
@ -25,6 +24,7 @@ gogs serv provide access auth for repositories`,
Flags: []cli.Flag{}, Flags: []cli.Flag{},
} }
// for command: ./gogs update
func runUpdate(*cli.Context) { func runUpdate(*cli.Context) {
userName := os.Getenv("userName") userName := os.Getenv("userName")
userId := os.Getenv("userId") userId := os.Getenv("userId")

58
web.go
View file

@ -61,48 +61,52 @@ func runWeb(*cli.Context) {
m.Use(middleware.InitContext()) m.Use(middleware.InitContext())
ignSignIn := middleware.SignInRequire(false)
reqSignIn, reqSignOut := middleware.SignInRequire(true), middleware.SignOutRequire()
// Routers. // Routers.
m.Get("/", middleware.SignInRequire(false), routers.Home) m.Get("/", ignSignIn, routers.Home)
m.Get("/issues", middleware.SignInRequire(true), user.Issues) m.Get("/issues", reqSignIn, user.Issues)
m.Get("/pulls", middleware.SignInRequire(true), user.Pulls) m.Get("/pulls", reqSignIn, user.Pulls)
m.Get("/stars", middleware.SignInRequire(true), user.Stars) m.Get("/stars", reqSignIn, user.Stars)
m.Any("/user/login", middleware.SignOutRequire(), binding.BindIgnErr(auth.LogInForm{}), user.SignIn) m.Any("/user/login", reqSignOut, binding.BindIgnErr(auth.LogInForm{}), user.SignIn)
m.Any("/user/logout", middleware.SignInRequire(true), user.SignOut) m.Any("/user/logout", reqSignIn, user.SignOut)
m.Any("/user/sign_up", middleware.SignOutRequire(), binding.BindIgnErr(auth.RegisterForm{}), user.SignUp) m.Any("/user/sign_up", reqSignOut, binding.BindIgnErr(auth.RegisterForm{}), user.SignUp)
m.Any("/user/delete", middleware.SignInRequire(true), user.Delete) m.Any("/user/delete", reqSignIn, user.Delete)
m.Get("/user/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds) 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", reqSignIn, binding.BindIgnErr(auth.UpdateProfileForm{}), user.Setting)
m.Any("/user/setting/password", middleware.SignInRequire(true), binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword) m.Any("/user/setting/password", reqSignIn, binding.BindIgnErr(auth.UpdatePasswdForm{}), user.SettingPassword)
m.Any("/user/setting/ssh", middleware.SignInRequire(true), binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys) m.Any("/user/setting/ssh", reqSignIn, binding.BindIgnErr(auth.AddSSHKeyForm{}), user.SettingSSHKeys)
m.Any("/user/setting/notification", middleware.SignInRequire(true), user.SettingNotification) m.Any("/user/setting/notification", reqSignIn, user.SettingNotification)
m.Any("/user/setting/security", middleware.SignInRequire(true), user.SettingSecurity) 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.Get("/help", routers.Help)
m.Post("/:username/:reponame/settings", middleware.SignInRequire(true), middleware.RepoAssignment(true), repo.SettingPost) m.Post("/:username/:reponame/settings", reqSignIn, middleware.RepoAssignment(true), repo.SettingPost)
m.Get("/:username/:reponame/settings", middleware.SignInRequire(true), middleware.RepoAssignment(true), repo.Setting) 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/commits/:branchname", ignSignIn, middleware.RepoAssignment(true), repo.Commits)
m.Get("/:username/:reponame/issues", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Issues) m.Get("/:username/:reponame/issues", ignSignIn, middleware.RepoAssignment(true), repo.Issues)
m.Get("/:username/:reponame/pulls", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Pulls) m.Get("/:username/:reponame/pulls", ignSignIn, middleware.RepoAssignment(true), repo.Pulls)
m.Get("/:username/:reponame/branches", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Branches) m.Get("/:username/:reponame/branches", ignSignIn, middleware.RepoAssignment(true), repo.Branches)
m.Get("/:username/:reponame/tree/:branchname/**", 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", m.Get("/:username/:reponame/tree/:branchname",
middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Single) ignSignIn, 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/**", ignSignIn, 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", 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", listenAddr := fmt.Sprintf("%s:%s",
base.Cfg.MustValue("server", "HTTP_ADDR"), base.Cfg.MustValue("server", "HTTP_ADDR"),
base.Cfg.MustValue("server", "HTTP_PORT", "3000")) base.Cfg.MustValue("server", "HTTP_PORT", "3000"))
log.Info("Listen: %s", listenAddr) log.Info("Listen: %s", listenAddr)
http.ListenAndServe(listenAddr, m) if err := http.ListenAndServe(listenAddr, m); err != nil {
log.Critical(err.Error())
}
} }