审查视图

pkg/application/auth/command/send_smscode.go 807 字节
yangfu authored
1 2 3 4 5 6 7 8 9 10
package command

import (
	"fmt"

	"github.com/beego/beego/v2/core/validation"
)

type SendSmsCodeCommand struct {
	Phone string `json:"phone" valid:"Required"`
11 12 13 14
	// 0:无  1:需要账号存在于账号系统内,才能发送验证码
	Flag int `json:"flag"`
	// [1:登录][2:修改密码][3:找回密码][4:注册][5:修改手机号]
	Action int `json:"action"`
yangfu authored
15 16
}
17
func (cmd *SendSmsCodeCommand) Valid(validation *validation.Validation) {
yangfu authored
18 19 20

}
21
func (cmd *SendSmsCodeCommand) ValidateCommand() error {
yangfu authored
22
	valid := validation.Validation{}
23 24 25 26
	b, err := valid.Valid(cmd)
	if cmd.Action == 1 || cmd.Action == 2 || cmd.Action == 3 {
		cmd.Flag = 1
	}
yangfu authored
27 28 29 30 31 32 33 34 35 36
	if err != nil {
		return err
	}
	if !b {
		for _, validErr := range valid.Errors {
			return fmt.Errorf("%s  %s", validErr.Key, validErr.Message)
		}
	}
	return nil
}