diff options
author | Unknwon <joe2010xtmf@163.com> | 2014-08-01 06:12:14 -0400 |
---|---|---|
committer | Unknwon <joe2010xtmf@163.com> | 2014-08-01 06:12:14 -0400 |
commit | 669552e255fb98021b779918394c65792fe6f1d2 (patch) | |
tree | 83749a52ede967df34285a5e9f79310abed473c0 /modules/auth/auth.go | |
parent | 17d2675dd263ba70a4d5370070d879776469144a (diff) | |
download | gitea-669552e255fb98021b779918394c65792fe6f1d2.tar.gz gitea-669552e255fb98021b779918394c65792fe6f1d2.zip |
Fix #340
Diffstat (limited to 'modules/auth/auth.go')
-rw-r--r-- | modules/auth/auth.go | 16 |
1 files changed, 12 insertions, 4 deletions
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: |