diff options
author | Unknown <joe2010xtmf@163.com> | 2014-05-05 19:58:13 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-05-05 19:58:13 -0400 |
commit | 6e3dba2cc559275b5287673957ec855e61b4163a (patch) | |
tree | e7188a38aad06b17663aa48b03b523ab24329c58 /modules | |
parent | bbdfe2576966210cfffc830bfbe3731bcf653b3b (diff) | |
download | gitea-6e3dba2cc559275b5287673957ec855e61b4163a.tar.gz gitea-6e3dba2cc559275b5287673957ec855e61b4163a.zip |
Clean repo code
Diffstat (limited to 'modules')
-rw-r--r-- | modules/auth/admin.go | 15 | ||||
-rw-r--r-- | modules/auth/auth.go | 14 | ||||
-rw-r--r-- | modules/auth/authentication.go | 15 | ||||
-rw-r--r-- | modules/auth/repo.go | 51 | ||||
-rw-r--r-- | modules/middleware/binding/binding.go | 5 | ||||
-rw-r--r-- | modules/middleware/repo.go | 15 |
6 files changed, 42 insertions, 73 deletions
diff --git a/modules/auth/admin.go b/modules/auth/admin.go index 39d2d09620..02a4dc489a 100644 --- a/modules/auth/admin.go +++ b/modules/auth/admin.go @@ -11,7 +11,6 @@ import ( "github.com/go-martini/martini" "github.com/gogits/gogs/modules/base" - "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware/binding" ) @@ -36,20 +35,6 @@ func (f *AdminEditUserForm) Name(field string) string { } func (f *AdminEditUserForm) Validate(errors *binding.BindingErrors, req *http.Request, context martini.Context) { - if req.Method == "GET" || errors.Count() == 0 { - return - } - data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) - data["HasError"] = true - AssignForm(f, data) - - if len(errors.Overall) > 0 { - for _, err := range errors.Overall { - log.Error("AdminEditUserForm.Validate: %v", err) - } - return - } - validate(errors, data, f) } diff --git a/modules/auth/auth.go b/modules/auth/auth.go index a0e00c10c5..a7b281e4c9 100644 --- a/modules/auth/auth.go +++ b/modules/auth/auth.go @@ -183,20 +183,6 @@ func (f *InstallForm) Name(field string) string { } func (f *InstallForm) Validate(errors *binding.BindingErrors, req *http.Request, context martini.Context) { - if req.Method == "GET" || errors.Count() == 0 { - return - } - data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) - data["HasError"] = true - AssignForm(f, data) - - if len(errors.Overall) > 0 { - for _, err := range errors.Overall { - log.Error("InstallForm.Validate: %v", err) - } - return - } - validate(errors, data, f) } diff --git a/modules/auth/authentication.go b/modules/auth/authentication.go index 376a52e9a7..51a9469cbd 100644 --- a/modules/auth/authentication.go +++ b/modules/auth/authentication.go @@ -11,7 +11,6 @@ import ( "github.com/go-martini/martini" "github.com/gogits/gogs/modules/base" - "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware/binding" ) @@ -44,20 +43,6 @@ func (f *AuthenticationForm) Name(field string) string { } func (f *AuthenticationForm) Validate(errors *binding.BindingErrors, req *http.Request, context martini.Context) { - if req.Method == "GET" || errors.Count() == 0 { - return - } - data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) - data["HasError"] = true - AssignForm(f, data) - - if len(errors.Overall) > 0 { - for _, err := range errors.Overall { - log.Error("AuthenticationForm.Validate: %v", err) - } - return - } - validate(errors, data, f) } diff --git a/modules/auth/repo.go b/modules/auth/repo.go index e61e8202ff..54fa99c83d 100644 --- a/modules/auth/repo.go +++ b/modules/auth/repo.go @@ -11,12 +11,11 @@ import ( "github.com/go-martini/martini" "github.com/gogits/gogs/modules/base" - "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware/binding" ) type CreateRepoForm struct { - RepoName string `form:"repo" binding:"Required;AlphaDash"` + RepoName string `form:"repo" binding:"Required;AlphaDash;MaxSize(100)"` Private bool `form:"private"` Description string `form:"desc" binding:"MaxSize(100)"` Language string `form:"language"` @@ -33,21 +32,7 @@ func (f *CreateRepoForm) Name(field string) string { } func (f *CreateRepoForm) Validate(errors *binding.BindingErrors, req *http.Request, context martini.Context) { - if req.Method == "GET" || errors.Count() == 0 { - return - } - data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) - data["HasError"] = true - AssignForm(f, data) - - if len(errors.Overall) > 0 { - for _, err := range errors.Overall { - log.Error("CreateRepoForm.Validate: %v", err) - } - return - } - validate(errors, data, f) } @@ -55,7 +40,7 @@ type MigrateRepoForm struct { Url string `form:"url" binding:"Url"` AuthUserName string `form:"auth_username"` AuthPasswd string `form:"auth_password"` - RepoName string `form:"repo" binding:"Required;AlphaDash"` + RepoName string `form:"repo" binding:"Required;AlphaDash;MaxSize(100)"` Mirror bool `form:"mirror"` Private bool `form:"private"` Description string `form:"desc" binding:"MaxSize(100)"` @@ -71,20 +56,30 @@ func (f *MigrateRepoForm) Name(field string) string { } func (f *MigrateRepoForm) Validate(errors *binding.BindingErrors, req *http.Request, context martini.Context) { - if req.Method == "GET" || errors.Count() == 0 { - return - } - data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) - data["HasError"] = true - AssignForm(f, data) + validate(errors, data, f) +} - if len(errors.Overall) > 0 { - for _, err := range errors.Overall { - log.Error("MigrateRepoForm.Validate: %v", err) - } - return +type RepoSettingForm struct { + RepoName string `form:"name" binding:"Required;AlphaDash;MaxSize(100)"` + Description string `form:"desc" binding:"MaxSize(100)"` + Website string `form:"url" binding:"Url;MaxSize(100)"` + Branch string `form:"branch"` + Interval int `form:"interval"` + Private bool `form:"private"` + GoGet bool `form:"goget"` +} + +func (f *RepoSettingForm) Name(field string) string { + names := map[string]string{ + "RepoName": "Repository name", + "Description": "Description", + "Website": "Website address", } + return names[field] +} +func (f *RepoSettingForm) Validate(errors *binding.BindingErrors, req *http.Request, context martini.Context) { + data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) validate(errors, data, f) } diff --git a/modules/middleware/binding/binding.go b/modules/middleware/binding/binding.go index 6de5955154..93fb51d994 100644 --- a/modules/middleware/binding/binding.go +++ b/modules/middleware/binding/binding.go @@ -267,7 +267,10 @@ func validateStruct(errors *BindingErrors, obj interface{}) { break } case rule == "Url": - if !urlPattern.MatchString(fmt.Sprintf("%v", fieldValue)) { + str := fmt.Sprintf("%v", fieldValue) + if len(str) == 0 { + continue + } else if !urlPattern.MatchString(str) { errors.Fields[field.Name] = BindingUrlError break } diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index f681ac139a..7d0cc97970 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -7,6 +7,7 @@ package middleware import ( "errors" "fmt" + "net/url" "strings" "github.com/go-martini/martini" @@ -238,3 +239,17 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler { ctx.Data["IsRepositoryWatching"] = ctx.Repo.IsWatching } } + +func RequireOwner() martini.Handler { + return func(ctx *Context) { + if !ctx.Repo.IsOwner { + if !ctx.IsSigned { + ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI)) + ctx.Redirect("/user/login") + return + } + ctx.Handle(404, ctx.Req.RequestURI, nil) + return + } + } +} |