chore: tidy swagger comments;

feat: password reset models;
feat: verification code validator
This commit is contained in:
2025-07-11 17:43:09 +03:00
parent c988a16783
commit 541847221b
6 changed files with 443 additions and 37 deletions

View File

@@ -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))
}},
}