add validator model
This commit is contained in:
@@ -80,7 +80,7 @@ func EncryptPhone(phone string) (string, Error) {
|
|||||||
// 提取各部分
|
// 提取各部分
|
||||||
prefix := phone[NumberZero:NumberThree] // 前三位
|
prefix := phone[NumberZero:NumberThree] // 前三位
|
||||||
middle := phone[NumberThree:NumberSeven] // 中四位
|
middle := phone[NumberThree:NumberSeven] // 中四位
|
||||||
suffix := phone[NumberSeven:NumberEleven] // 尾四位
|
suffix := phone[NumberSeven:] // 尾四位
|
||||||
newPhone := StringEmpty
|
newPhone := StringEmpty
|
||||||
username, cErr := Crypto{}.AESEncryptECB(prefix)
|
username, cErr := Crypto{}.AESEncryptECB(prefix)
|
||||||
if cErr != nil {
|
if cErr != nil {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"lone-services/pkg/utils"
|
"lone-services/pkg/utils"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
)
|
)
|
||||||
@@ -17,9 +18,14 @@ type IValidator interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var v *validator.Validate
|
var v *validator.Validate
|
||||||
|
var mobileReg = regexp.MustCompile(`^1[3-9]\d{9}$`)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
v = validator.New()
|
v = validator.New()
|
||||||
|
|
||||||
|
_ = v.RegisterValidation("mobile", func(fl validator.FieldLevel) bool {
|
||||||
|
return mobileReg.MatchString(fl.Field().String())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CopySameField 反射自动拷贝同名字段:src(proto入参) → dst(校验model结构体指针)
|
// CopySameField 反射自动拷贝同名字段:src(proto入参) → dst(校验model结构体指针)
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
Nacos:
|
|
||||||
Hosts:
|
|
||||||
- rnacos:8848
|
|
||||||
NamespaceId: test
|
|
||||||
Group: LONE_SERVICES
|
|
||||||
RegisterIP: admin
|
|
||||||
ConfigID: admin
|
|
||||||
@@ -96,7 +96,7 @@ func (p AdminStatusValidator) GetMessage() validate.ValidatorMessages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type LoginValidator struct {
|
type LoginValidator struct {
|
||||||
Username string `validate:"required"`
|
Username string `validate:"required,mobile"`
|
||||||
Password string `validate:"required"`
|
Password string `validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +104,7 @@ type LoginValidator struct {
|
|||||||
func (p LoginValidator) GetMessage() validate.ValidatorMessages {
|
func (p LoginValidator) GetMessage() validate.ValidatorMessages {
|
||||||
return validate.ValidatorMessages{
|
return validate.ValidatorMessages{
|
||||||
"Username.required": "账号不能为空",
|
"Username.required": "账号不能为空",
|
||||||
|
"Username.mobile": "账号不正确",
|
||||||
"Password.required": "密码不能为空",
|
"Password.required": "密码不能为空",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
Nacos:
|
|
||||||
Hosts:
|
|
||||||
- rnacos:8848
|
|
||||||
NamespaceId: test
|
|
||||||
Group: LONE_SERVICES
|
|
||||||
RegisterIP: log
|
|
||||||
ConfigID: develop-logs
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
Nacos:
|
|
||||||
Hosts:
|
|
||||||
- rnacos:8848
|
|
||||||
NamespaceId: test
|
|
||||||
Group: LONE_SERVICES
|
|
||||||
RegisterIP: order
|
|
||||||
ConfigID: develop-order
|
|
||||||
Reference in New Issue
Block a user