| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package requests
- import (
- "github.com/gin-gonic/gin"
- "github.com/runningwater/gohub/app/requests/validators"
- "github.com/thedevsaddam/govalidator"
- )
- type ResetByPhoneRequest struct {
- Phone string `json:"phone,omitempty" valid:"phone"`
- VerifyCode string `json:"verify_code,omitempty" valid:"verify_code"`
- Password string `json:"password,omitempty" valid:"password"`
- }
- // ResetByPhone 验证表单,返回长度等于零即通过
- func ResetByPhone(data any, c *gin.Context) map[string][]string {
- rules := govalidator.MapData{
- "phone": []string{"required", "digits:11"},
- "verify_code": []string{"required", "digits:6"},
- "password": []string{"required", "min:6"},
- }
- messages := govalidator.MapData{
- "phone": []string{
- "required:手机号为必填项,参数名称 phone",
- "digits:手机号长度必须为 11 位的数字",
- },
- "verify_code": []string{
- "required:验证码答案必填",
- "digits:验证码长度必须为 6 位的数字",
- },
- "password": []string{
- "required:密码为必填项",
- "min:密码长度需大于 6",
- },
- }
- errs := validate(data, rules, messages)
- // 验证码是否正确
- _data := data.(*ResetByPhoneRequest)
- errs = validators.ValidateVerifyCode(_data.Phone, _data.VerifyCode, errs)
- return errs
- }
|