Merge pull request #31 from shxsun/master

add some comment
release/v1.15
无闻 2014-03-18 17:47:50 -04:00
commit 58147bef20
4 changed files with 37 additions and 31 deletions

View File

@ -22,8 +22,8 @@ const (
// Action represents user operation type and information to the repository. // Action represents user operation type and information to the repository.
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())
}
} }