diff options
Diffstat (limited to 'modules/auth')
-rw-r--r-- | modules/auth/org.go | 57 | ||||
-rw-r--r-- | modules/auth/repo.go | 33 | ||||
-rw-r--r-- | modules/auth/user.go | 58 |
3 files changed, 119 insertions, 29 deletions
diff --git a/modules/auth/org.go b/modules/auth/org.go new file mode 100644 index 00000000..f87d10a7 --- /dev/null +++ b/modules/auth/org.go @@ -0,0 +1,57 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package auth + +import ( + "net/http" + "reflect" + + "github.com/go-martini/martini" + + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/middleware/binding" +) + +type CreateOrgForm struct { + OrgName string `form:"orgname" binding:"Required;AlphaDashDot;MaxSize(30)"` + Email string `form:"email" binding:"Required;Email;MaxSize(50)"` +} + +func (f *CreateOrgForm) Name(field string) string { + names := map[string]string{ + "OrgName": "Organization name", + "Email": "E-mail address", + } + return names[field] +} + +func (f *CreateOrgForm) Validate(errs *binding.Errors, req *http.Request, ctx martini.Context) { + data := ctx.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) + validate(errs, data, f) +} + +type OrgSettingForm struct { + DisplayName string `form:"display_name" binding:"Required;MaxSize(100)"` + Email string `form:"email" binding:"Required;Email;MaxSize(50)"` + Description string `form:"desc" binding:"MaxSize(255)"` + Website string `form:"site" binding:"Url;MaxSize(100)"` + Location string `form:"location" binding:"MaxSize(50)"` +} + +func (f *OrgSettingForm) Name(field string) string { + names := map[string]string{ + "DisplayName": "Display name", + "Email": "E-mail address", + "Description": "Description", + "Website": "Website address", + "Location": "Location", + } + return names[field] +} + +func (f *OrgSettingForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { + data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) + validate(errors, data, f) +} diff --git a/modules/auth/repo.go b/modules/auth/repo.go index 82cd0786..d3d21532 100644 --- a/modules/auth/repo.go +++ b/modules/auth/repo.go @@ -22,9 +22,10 @@ import ( // \/ \/|__| \/ \/ type CreateRepoForm struct { + Uid int64 `form:"uid" binding:"Required"` RepoName string `form:"repo" binding:"Required;AlphaDash;MaxSize(100)"` Private bool `form:"private"` - Description string `form:"desc" binding:"MaxSize(100)"` + Description string `form:"desc" binding:"MaxSize(255)"` Language string `form:"language"` License string `form:"license"` InitReadme bool `form:"initReadme"` @@ -47,10 +48,11 @@ type MigrateRepoForm struct { Url string `form:"url" binding:"Url"` AuthUserName string `form:"auth_username"` AuthPasswd string `form:"auth_password"` + Uid int64 `form:"uid" binding:"Required"` RepoName string `form:"repo" binding:"Required;AlphaDash;MaxSize(100)"` Mirror bool `form:"mirror"` Private bool `form:"private"` - Description string `form:"desc" binding:"MaxSize(100)"` + Description string `form:"desc" binding:"MaxSize(255)"` } func (f *MigrateRepoForm) Name(field string) string { @@ -69,7 +71,7 @@ func (f *MigrateRepoForm) Validate(errors *binding.Errors, req *http.Request, co type RepoSettingForm struct { RepoName string `form:"name" binding:"Required;AlphaDash;MaxSize(100)"` - Description string `form:"desc" binding:"MaxSize(100)"` + Description string `form:"desc" binding:"MaxSize(255)"` Website string `form:"site" binding:"Url;MaxSize(100)"` Branch string `form:"branch"` Interval int `form:"interval"` @@ -205,14 +207,17 @@ func (f *CreateLabelForm) Validate(errors *binding.Errors, req *http.Request, co type NewReleaseForm struct { TagName string `form:"tag_name" binding:"Required"` + Target string `form:"tag_target" binding:"Required"` Title string `form:"title" binding:"Required"` Content string `form:"content" binding:"Required"` + Draft string `form:"draft"` Prerelease bool `form:"prerelease"` } func (f *NewReleaseForm) Name(field string) string { names := map[string]string{ "TagName": "Tag name", + "Target": "Target", "Title": "Release title", "Content": "Release content", } @@ -223,3 +228,25 @@ func (f *NewReleaseForm) Validate(errors *binding.Errors, req *http.Request, con data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) validate(errors, data, f) } + +type EditReleaseForm struct { + Target string `form:"tag_target" binding:"Required"` + Title string `form:"title" binding:"Required"` + Content string `form:"content" binding:"Required"` + Draft string `form:"draft"` + Prerelease bool `form:"prerelease"` +} + +func (f *EditReleaseForm) Name(field string) string { + names := map[string]string{ + "Target": "Target", + "Title": "Release title", + "Content": "Release content", + } + return names[field] +} + +func (f *EditReleaseForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { + data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) + validate(errors, data, f) +} diff --git a/modules/auth/user.go b/modules/auth/user.go index e672a9c1..4a781acf 100644 --- a/modules/auth/user.go +++ b/modules/auth/user.go @@ -16,57 +16,63 @@ import ( "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware/binding" + "github.com/gogits/gogs/modules/setting" ) // SignedInId returns the id of signed in user. -func SignedInId(session session.SessionStore) int64 { +func SignedInId(header http.Header, sess session.SessionStore) int64 { if !models.HasEngine { return 0 } - userId := session.Get("userId") - if userId == nil { + if setting.Service.EnableReverseProxyAuth { + webAuthUser := header.Get(setting.ReverseProxyAuthUser) + if len(webAuthUser) > 0 { + u, err := models.GetUserByName(webAuthUser) + if err != nil { + if err != models.ErrUserNotExist { + log.Error("auth.user.SignedInId(GetUserByName): %v", err) + } + return 0 + } + return u.Id + } + } + + uid := sess.Get("userId") + if uid == nil { return 0 } - if s, ok := userId.(int64); ok { - if _, err := models.GetUserById(s); err != nil { + if id, ok := uid.(int64); ok { + if _, err := models.GetUserById(id); err != nil { + if err != models.ErrUserNotExist { + log.Error("auth.user.SignedInId(GetUserById): %v", err) + } return 0 } - return s + return id } return 0 } -// SignedInName returns the name of signed in user. -func SignedInName(session session.SessionStore) string { - userName := session.Get("userName") - if userName == nil { - return "" - } - if s, ok := userName.(string); ok { - return s - } - return "" -} - // SignedInUser returns the user object of signed user. -func SignedInUser(session session.SessionStore) *models.User { - id := SignedInId(session) - if id <= 0 { +func SignedInUser(header http.Header, sess session.SessionStore) *models.User { + uid := SignedInId(header, sess) + if uid <= 0 { return nil } - user, err := models.GetUserById(id) + u, err := models.GetUserById(uid) if err != nil { log.Error("user.SignedInUser: %v", err) return nil } - return user + return u } // IsSignedIn check if any user has signed in. -func IsSignedIn(session session.SessionStore) bool { - return SignedInId(session) > 0 +func IsSignedIn(header http.Header, sess session.SessionStore) bool { + return SignedInId(header, sess) > 0 } type FeedsForm struct { @@ -87,7 +93,7 @@ func (f *UpdateProfileForm) Name(field string) string { names := map[string]string{ "UserName": "Username", "Email": "E-mail address", - "Website": "Website", + "Website": "Website address", "Location": "Location", "Avatar": "Gravatar Email", } |