Feat: model validate update

pull/21/head
zijiren233 2 years ago
parent 43d40ab357
commit a026f82300

@ -26,13 +26,13 @@ func (p *PushMovieReq) Decode(ctx *gin.Context) error {
}
func (p *PushMovieReq) Validate() error {
if len(p.Url) > 1024 {
if len(p.Url) > 8192 {
return ErrUrlTooLong
}
if p.Name == "" {
return ErrEmptyName
} else if len(p.Name) > 1024 {
} else if len(p.Name) > 512 {
return ErrNameTooLong
}

@ -27,8 +27,9 @@ var (
)
var (
alphaNumReg = regexp.MustCompile(`^[a-zA-Z0-9_\-]+$`)
alphaNumChineseReg = regexp.MustCompile(`^[\p{Han}a-zA-Z0-9_\-]+$`)
alnumReg = regexp.MustCompile(`^[[:alnum:]]+$`)
alnumPrintReg = regexp.MustCompile(`^[[:print:][:alnum:]]+$`)
alnumPrintHanReg = regexp.MustCompile(`^[[:print:][:alnum:]\p{Han}]+$`)
)
type FormatEmptyPasswordError string
@ -52,14 +53,14 @@ func (c *CreateRoomReq) Validate() error {
return ErrEmptyRoomName
} else if len(c.RoomName) > 32 {
return ErrRoomNameTooLong
} else if !alphaNumChineseReg.MatchString(c.RoomName) {
} else if !alnumPrintHanReg.MatchString(c.RoomName) {
return ErrRoomNameHasInvalidChar
}
if c.Password != "" {
if len(c.Password) > 32 {
return ErrPasswordTooLong
} else if !alphaNumReg.MatchString(c.Password) {
} else if !alnumPrintReg.MatchString(c.Password) {
return ErrPasswordHasInvalidChar
}
} else if conf.Conf.Room.MustPassword {
@ -106,7 +107,7 @@ func (s *SetRoomPasswordReq) Decode(ctx *gin.Context) error {
func (s *SetRoomPasswordReq) Validate() error {
if len(s.Password) > 32 {
return ErrPasswordTooLong
} else if !alphaNumReg.MatchString(s.Password) {
} else if !alnumPrintReg.MatchString(s.Password) {
return ErrPasswordHasInvalidChar
}
return nil

@ -20,7 +20,7 @@ func (s *SetUserPasswordReq) Validate() error {
return FormatEmptyPasswordError("user")
} else if len(s.Password) > 32 {
return ErrPasswordTooLong
} else if !alphaNumReg.MatchString(s.Password) {
} else if !alnumPrintReg.MatchString(s.Password) {
return ErrPasswordHasInvalidChar
}
return nil
@ -64,7 +64,7 @@ func (s *SignupUserReq) Validate() error {
return errors.New("username is empty")
} else if len(s.Username) > 32 {
return ErrUsernameTooLong
} else if !alphaNumChineseReg.MatchString(s.Username) {
} else if !alnumPrintHanReg.MatchString(s.Username) {
return ErrUsernameHasInvalidChar
}
@ -72,7 +72,7 @@ func (s *SignupUserReq) Validate() error {
return FormatEmptyPasswordError("user")
} else if len(s.Password) > 32 {
return ErrPasswordTooLong
} else if !alphaNumReg.MatchString(s.Password) {
} else if !alnumPrintReg.MatchString(s.Password) {
return ErrPasswordHasInvalidChar
}
return nil

Loading…
Cancel
Save