summaryrefslogtreecommitdiffstats
path: root/modules/auth
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-08-01 06:12:14 -0400
committerUnknwon <joe2010xtmf@163.com>2014-08-01 06:12:14 -0400
commit669552e255fb98021b779918394c65792fe6f1d2 (patch)
tree83749a52ede967df34285a5e9f79310abed473c0 /modules/auth
parent17d2675dd263ba70a4d5370070d879776469144a (diff)
downloadgitea-669552e255fb98021b779918394c65792fe6f1d2.tar.gz
gitea-669552e255fb98021b779918394c65792fe6f1d2.zip
Fix #340
Diffstat (limited to 'modules/auth')
-rw-r--r--modules/auth/apiv1/miscellaneous.go4
-rw-r--r--modules/auth/auth.go16
-rw-r--r--modules/auth/user_form.go10
3 files changed, 19 insertions, 11 deletions
diff --git a/modules/auth/apiv1/miscellaneous.go b/modules/auth/apiv1/miscellaneous.go
index 30515eb861..ea3892977a 100644
--- a/modules/auth/apiv1/miscellaneous.go
+++ b/modules/auth/apiv1/miscellaneous.go
@@ -63,9 +63,9 @@ func validateApiReq(errs *binding.Errors, data map[string]interface{}, f interfa
case binding.BindingAlphaDashDotError:
data["ErrorMsg"] = fieldName + " must be valid alpha or numeric or dash(-_) or dot characters"
case binding.BindingMinSizeError:
- data["ErrorMsg"] = fieldName + " must contain at least " + auth.GetMinMaxSize(field) + " characters"
+ data["ErrorMsg"] = fieldName + " must contain at least " + auth.GetMinSize(field) + " characters"
case binding.BindingMaxSizeError:
- data["ErrorMsg"] = fieldName + " must contain at most " + auth.GetMinMaxSize(field) + " characters"
+ data["ErrorMsg"] = fieldName + " must contain at most " + auth.GetMaxSize(field) + " characters"
case binding.BindingEmailError:
data["ErrorMsg"] = fieldName + " is not a valid e-mail address"
case binding.BindingUrlError:
diff --git a/modules/auth/auth.go b/modules/auth/auth.go
index 2236de4761..bcd2fcb35d 100644
--- a/modules/auth/auth.go
+++ b/modules/auth/auth.go
@@ -92,15 +92,23 @@ func AssignForm(form interface{}, data map[string]interface{}) {
}
}
-func GetMinMaxSize(field reflect.StructField) string {
+func getSize(field reflect.StructField, prefix string) string {
for _, rule := range strings.Split(field.Tag.Get("binding"), ";") {
- if strings.HasPrefix(rule, "MinSize(") || strings.HasPrefix(rule, "MaxSize(") {
+ if strings.HasPrefix(rule, prefix) {
return rule[8 : len(rule)-1]
}
}
return ""
}
+func GetMinSize(field reflect.StructField) string {
+ return getSize(field, "MinSize(")
+}
+
+func GetMaxSize(field reflect.StructField) string {
+ return getSize(field, "MaxSize(")
+}
+
func validate(errs *binding.Errors, data map[string]interface{}, f interface{}, l i18n.Locale) {
if errs.Count() == 0 {
return
@@ -142,9 +150,9 @@ func validate(errs *binding.Errors, data map[string]interface{}, f interface{},
case binding.BindingAlphaDashDotError:
data["ErrorMsg"] = trName + l.Tr("form.alpha_dash_dot_error")
case binding.BindingMinSizeError:
- data["ErrorMsg"] = trName + l.Tr("form.min_size_error", GetMinMaxSize(field))
+ data["ErrorMsg"] = trName + l.Tr("form.min_size_error", GetMinSize(field))
case binding.BindingMaxSizeError:
- data["ErrorMsg"] = trName + l.Tr("form.max_size_error", GetMinMaxSize(field))
+ data["ErrorMsg"] = trName + l.Tr("form.max_size_error", GetMaxSize(field))
case binding.BindingEmailError:
data["ErrorMsg"] = trName + l.Tr("form.email_error")
case binding.BindingUrlError:
diff --git a/modules/auth/user_form.go b/modules/auth/user_form.go
index 30080e859b..df713b570f 100644
--- a/modules/auth/user_form.go
+++ b/modules/auth/user_form.go
@@ -24,7 +24,7 @@ type InstallForm struct {
Domain string `form:"domain"`
AppUrl string `form:"app_url"`
AdminName string `form:"admin_name" binding:"Required;AlphaDashDot;MaxSize(30)"`
- AdminPasswd string `form:"admin_pwd" binding:"Required;MinSize(6);MaxSize(30)"`
+ AdminPasswd string `form:"admin_pwd" binding:"Required;MinSize(6);MaxSize(255)"`
AdminEmail string `form:"admin_email" binding:"Required;Email;MaxSize(50)"`
SmtpHost string `form:"smtp_host"`
SmtpEmail string `form:"mailer_user"`
@@ -47,7 +47,7 @@ func (f *InstallForm) Validate(ctx *macaron.Context, errs *binding.Errors, l i18
type RegisterForm struct {
UserName string `form:"uname" binding:"Required;AlphaDashDot;MaxSize(35)"`
Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
- Password string `form:"password" binding:"Required;MinSize(6);MaxSize(30)"`
+ Password string `form:"password" binding:"Required;MinSize(6);MaxSize(255)"`
Retype string `form:"retype"`
LoginType string `form:"logintype"`
LoginName string `form:"loginname"`
@@ -59,7 +59,7 @@ func (f *RegisterForm) Validate(ctx *macaron.Context, errs *binding.Errors, l i1
type SignInForm struct {
UserName string `form:"uname" binding:"Required;MaxSize(35)"`
- Password string `form:"password" binding:"Required;MinSize(6);MaxSize(30)"`
+ Password string `form:"password" binding:"Required;MinSize(6);MaxSize(255)"`
Remember bool `form:"remember"`
}
@@ -88,8 +88,8 @@ func (f *UpdateProfileForm) Validate(ctx *macaron.Context, errs *binding.Errors,
}
type ChangePasswordForm struct {
- OldPassword string `form:"old_password" binding:"Required;MinSize(6);MaxSize(30)"`
- Password string `form:"password" binding:"Required;MinSize(6);MaxSize(30)"`
+ OldPassword string `form:"old_password" binding:"Required;MinSize(6);MaxSize(255)"`
+ Password string `form:"password" binding:"Required;MinSize(6);MaxSize(255)"`
Retype string `form:"retype"`
}