login.go
1.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type LoginQuery struct {
// 设备类型
DeviceType int `json:"deviceType,omitempty"`
// 手机号
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
}