mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-04 08:17:24 -05:00
fix #91
This commit is contained in:
parent
46af92c57e
commit
2a1dc0085b
@ -21,7 +21,7 @@ type Form interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RegisterForm struct {
|
type RegisterForm struct {
|
||||||
UserName string `form:"username" binding:"Required;AlphaDash;MaxSize(30)"`
|
UserName string `form:"username" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
||||||
Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
|
Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
|
||||||
Password string `form:"passwd" binding:"Required;MinSize(6);MaxSize(30)"`
|
Password string `form:"passwd" binding:"Required;MinSize(6);MaxSize(30)"`
|
||||||
RetypePasswd string `form:"retypepasswd"`
|
RetypePasswd string `form:"retypepasswd"`
|
||||||
@ -123,6 +123,8 @@ func validate(errors *base.BindingErrors, data base.TmplData, form Form) {
|
|||||||
data["ErrorMsg"] = form.Name(field.Name) + " cannot be empty"
|
data["ErrorMsg"] = form.Name(field.Name) + " cannot be empty"
|
||||||
case base.BindingAlphaDashError:
|
case base.BindingAlphaDashError:
|
||||||
data["ErrorMsg"] = form.Name(field.Name) + " must be valid alpha or numeric or dash(-_) characters"
|
data["ErrorMsg"] = form.Name(field.Name) + " must be valid alpha or numeric or dash(-_) characters"
|
||||||
|
case base.BindingAlphaDashDotError:
|
||||||
|
data["ErrorMsg"] = form.Name(field.Name) + " must be valid alpha or numeric or dash(-_) or dot characters"
|
||||||
case base.BindingMinSizeError:
|
case base.BindingMinSizeError:
|
||||||
data["ErrorMsg"] = form.Name(field.Name) + " must contain at least " + getMinMaxSize(field) + " characters"
|
data["ErrorMsg"] = form.Name(field.Name) + " must contain at least " + getMinMaxSize(field) + " characters"
|
||||||
case base.BindingMaxSizeError:
|
case base.BindingMaxSizeError:
|
||||||
|
@ -45,6 +45,7 @@ func (this *BindingErrors) Combine(other BindingErrors) {
|
|||||||
const (
|
const (
|
||||||
BindingRequireError string = "Required"
|
BindingRequireError string = "Required"
|
||||||
BindingAlphaDashError string = "AlphaDash"
|
BindingAlphaDashError string = "AlphaDash"
|
||||||
|
BindingAlphaDashDotError string = "AlphaDashDot"
|
||||||
BindingMinSizeError string = "MinSize"
|
BindingMinSizeError string = "MinSize"
|
||||||
BindingMaxSizeError string = "MaxSize"
|
BindingMaxSizeError string = "MaxSize"
|
||||||
BindingEmailError string = "Email"
|
BindingEmailError string = "Email"
|
||||||
|
@ -180,9 +180,10 @@ func Validate(obj interface{}) martini.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
alphaDashPattern = regexp.MustCompile("[^\\d\\w-_]")
|
alphaDashPattern = regexp.MustCompile("[^\\d\\w-_]")
|
||||||
emailPattern = regexp.MustCompile("[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[a-zA-Z0-9](?:[\\w-]*[\\w])?")
|
alphaDashDotPattern = regexp.MustCompile("[^\\d\\w-_\\.]")
|
||||||
urlPattern = regexp.MustCompile(`(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?`)
|
emailPattern = regexp.MustCompile("[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[a-zA-Z0-9](?:[\\w-]*[\\w])?")
|
||||||
|
urlPattern = regexp.MustCompile(`(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func validateStruct(errors *base.BindingErrors, obj interface{}) {
|
func validateStruct(errors *base.BindingErrors, obj interface{}) {
|
||||||
@ -227,6 +228,11 @@ func validateStruct(errors *base.BindingErrors, obj interface{}) {
|
|||||||
errors.Fields[field.Name] = base.BindingAlphaDashError
|
errors.Fields[field.Name] = base.BindingAlphaDashError
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
case rule == "AlphaDashDot":
|
||||||
|
if alphaDashDotPattern.MatchString(fmt.Sprintf("%v", fieldValue)) {
|
||||||
|
errors.Fields[field.Name] = base.BindingAlphaDashDotError
|
||||||
|
break
|
||||||
|
}
|
||||||
case strings.HasPrefix(rule, "MinSize("):
|
case strings.HasPrefix(rule, "MinSize("):
|
||||||
min, err := strconv.Atoi(rule[8 : len(rule)-1])
|
min, err := strconv.Atoi(rule[8 : len(rule)-1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<nav class="nav">
|
<nav class="nav">
|
||||||
<a id="nav-logo" class="nav-item pull-left{{if .PageIsHome}} active{{end}}" href="/"><img src="/img/favicon.png" alt="Gogs Logo" id="logo"></a>
|
<a id="nav-logo" class="nav-item pull-left{{if .PageIsHome}} active{{end}}" href="/"><img src="/img/favicon.png" alt="Gogs Logo" id="logo"></a>
|
||||||
<a class="nav-item pull-left{{if .PageIsUserDashboard}} active{{end}}" href="/">Dashboard</a>
|
<a class="nav-item pull-left{{if .PageIsUserDashboard}} active{{end}}" href="/">Dashboard</a>
|
||||||
<a class="nav-item pull-left{{if .PageIsHelp}} active{{end}}" target="_blank" href="https://github.com/gogits/gogs/wiki">Help</a>{{if .IsSigned}}
|
<a class="nav-item pull-left{{if .PageIsHelp}} active{{end}}" target="_blank" href="http://gogs.io/docs">Help</a>{{if .IsSigned}}
|
||||||
{{if .HasAccess}}<form class="nav-item pull-left{{if .PageIsNewRepo}} active{{end}}" id="nav-search-form">
|
{{if .HasAccess}}<form class="nav-item pull-left{{if .PageIsNewRepo}} active{{end}}" id="nav-search-form">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-btn">
|
<div class="input-group-btn">
|
||||||
|
Loading…
Reference in New Issue
Block a user