aboutsummaryrefslogtreecommitdiff
path: root/modules/auth
diff options
context:
space:
mode:
Diffstat (limited to 'modules/auth')
-rw-r--r--modules/auth/auth.go9
-rw-r--r--modules/auth/user.go78
2 files changed, 80 insertions, 7 deletions
diff --git a/modules/auth/auth.go b/modules/auth/auth.go
index e4748650..0e871688 100644
--- a/modules/auth/auth.go
+++ b/modules/auth/auth.go
@@ -23,7 +23,7 @@ type Form interface {
}
type RegisterForm struct {
- UserName string `form:"username" binding:"Required;AlphaDash;MinSize(5);MaxSize(30)"`
+ UserName string `form:"username" binding:"Required;AlphaDash;MaxSize(30)"`
Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
Password string `form:"passwd" binding:"Required;MinSize(6);MaxSize(30)"`
RetypePasswd string `form:"retypepasswd"`
@@ -59,7 +59,7 @@ func (f *RegisterForm) Validate(errors *binding.Errors, req *http.Request, conte
}
type LogInForm struct {
- UserName string `form:"username" binding:"Required;AlphaDash;MinSize(5);MaxSize(30)"`
+ UserName string `form:"username" binding:"Required;AlphaDash;MaxSize(30)"`
Password string `form:"passwd" binding:"Required;MinSize(6);MaxSize(30)"`
}
@@ -90,11 +90,6 @@ func (f *LogInForm) Validate(errors *binding.Errors, req *http.Request, context
validate(errors, data, f)
}
-type FeedsForm struct {
- UserId int64 `form:"userid" binding:"Required"`
- Offset int64 `form:"offset"`
-}
-
func getMinMaxSize(field reflect.StructField) string {
for _, rule := range strings.Split(field.Tag.Get("binding"), ";") {
if strings.HasPrefix(rule, "MinSize(") || strings.HasPrefix(rule, "MaxSize(") {
diff --git a/modules/auth/user.go b/modules/auth/user.go
index 4059edfd..ef595c60 100644
--- a/modules/auth/user.go
+++ b/modules/auth/user.go
@@ -5,10 +5,15 @@
package auth
import (
+ "net/http"
+ "reflect"
+
"github.com/codegangsta/martini"
"github.com/martini-contrib/render"
"github.com/martini-contrib/sessions"
+ "github.com/gogits/binding"
+
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log"
@@ -83,3 +88,76 @@ func SignOutRequire() martini.Handler {
}
}
}
+
+type FeedsForm struct {
+ UserId int64 `form:"userid" binding:"Required"`
+ Offset int64 `form:"offset"`
+}
+
+type UpdateProfileForm struct {
+ Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
+ Website string `form:"website" binding:"MaxSize(50)"`
+ Location string `form:"location" binding:"MaxSize(50)"`
+ Avatar string `form:"avatar" binding:"Required;Email;MaxSize(50)"`
+}
+
+func (f *UpdateProfileForm) Name(field string) string {
+ names := map[string]string{
+ "Email": "Email address",
+ "Website": "Website",
+ "Location": "Location",
+ "Avatar": "Gravatar Email",
+ }
+ return names[field]
+}
+
+func (f *UpdateProfileForm) Validate(errors *binding.Errors, 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
+
+ if len(errors.Overall) > 0 {
+ for _, err := range errors.Overall {
+ log.Error("UpdateProfileForm.Validate: %v", err)
+ }
+ return
+ }
+
+ validate(errors, data, f)
+}
+
+type UpdatePasswdForm struct {
+ OldPasswd string `form:"oldpasswd" binding:"Required;MinSize(6);MaxSize(30)"`
+ NewPasswd string `form:"newpasswd" binding:"Required;MinSize(6);MaxSize(30)"`
+ RetypePasswd string `form:"retypepasswd"`
+}
+
+func (f *UpdatePasswdForm) Name(field string) string {
+ names := map[string]string{
+ "OldPasswd": "Old password",
+ "NewPasswd": "New password",
+ "RetypePasswd": "Re-type password",
+ }
+ return names[field]
+}
+
+func (f *UpdatePasswdForm) Validate(errors *binding.Errors, 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
+
+ if len(errors.Overall) > 0 {
+ for _, err := range errors.Overall {
+ log.Error("UpdatePasswdForm.Validate: %v", err)
+ }
+ return
+ }
+
+ validate(errors, data, f)
+}