chore: tidy swagger comments;
feat: password reset models; feat: verification code validator
This commit is contained in:
@@ -19,6 +19,7 @@ package validation
|
||||
|
||||
import (
|
||||
"easywish/config"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
@@ -76,6 +77,25 @@ func GetCustomHandlers() []CustomValidatorHandler {
|
||||
|
||||
return true
|
||||
}},
|
||||
|
||||
{
|
||||
FieldName: "verification_code",
|
||||
Function: func(fl validator.FieldLevel) bool {
|
||||
codeType := fl.Param()
|
||||
code := fl.Field().String()
|
||||
|
||||
if codeType == "reg" {
|
||||
return regexp.MustCompile(`[\d]{6,6}`).MatchString(code)
|
||||
}
|
||||
|
||||
if codeType == "reset" {
|
||||
return regexp.MustCompile(
|
||||
`^[{(]?([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})[})]?$`,
|
||||
).MatchString(code)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("'%s' is not a valid verification code type", codeType))
|
||||
}},
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user