login.go 963 字节
package query

import (
	"fmt"

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

type LoginQuery struct {
	// 手机号
	Phone string `json:"phone,omitempty"`
	// signInPassword(密码登录) 或 signInCaptcha(验证码登录)或signInCredentials(凭证登录)
	GrantType string `json:"grantType,omitempty"`
	// 密码(grantType = signInPassword)
	Password string `json:"password,omitempty"`
	// 验证码(grantType = signInCaptcha)
	Captcha string `json:"captcha,omitempty"`
	// 凭证(grantType = signInCredentials)
	Credentials string `json:"credentials,omitempty"`
}

func (loginQuery *LoginQuery) Valid(validation *validation.Validation) {

}

func (loginQuery *LoginQuery) ValidateQuery() error {
	valid := validation.Validation{}
	b, err := valid.Valid(loginQuery)
	if err != nil {
		return err
	}
	if !b {
		for _, validErr := range valid.Errors {
			return fmt.Errorf("%s  %s", validErr.Key, validErr.Message)
		}
	}
	return nil
}