forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.go
87 lines (77 loc) · 2.51 KB
/
process.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package user
import (
"github.com/yaoapp/gou"
"github.com/yaoapp/kun/any"
"github.com/yaoapp/kun/exception"
"github.com/yaoapp/kun/maps"
"github.com/yaoapp/kun/utils"
"github.com/yaoapp/xiang/config"
"github.com/yaoapp/xiang/xlog"
)
func init() {
gou.RegisterProcessHandler("xiang.user.Captcha", ProcessCaptcha)
gou.RegisterProcessHandler("xiang.user.Login", ProcessLogin)
}
// ProcessLogin xiang.user.Login 用户登录
func ProcessLogin(process *gou.Process) interface{} {
process.ValidateArgNums(1)
payload := process.ArgsMap(0).Dot()
if config.IsDebug() {
xlog.Println(payload)
}
id := any.Of(payload.Get("captcha.id")).CString()
value := any.Of(payload.Get("captcha.code")).CString()
if id == "" {
exception.New("请输入验证码ID", 400).Ctx(maps.Map{"id": id, "code": value}).Throw()
}
if value == "" {
exception.New("请输入验证码", 400).Ctx(maps.Map{"id": id, "code": value}).Throw()
}
if !ValidateCaptcha(id, value) {
if config.IsDebug() {
xlog.Println("ID:", id, " Code:", value)
}
exception.New("验证码不正确", 403).Ctx(maps.Map{"id": id, "code": value}).Throw()
return nil
}
email := any.Of(payload.Get("email")).CString()
mobile := any.Of(payload.Get("mobile")).CString()
password := any.Of(payload.Get("password")).CString()
if email != "" {
return Auth("email", email, password)
} else if mobile != "" {
utils.Dump(mobile, password)
return Auth("mobile", mobile, password)
}
exception.New("参数错误", 400).Ctx(payload).Throw()
return nil
}
// ProcessCaptcha xiang.user.Captcha 验证码
func ProcessCaptcha(process *gou.Process) interface{} {
process.ValidateArgNums(1)
option := CaptchaOption{
Width: any.Of(process.ArgsURLValue(0, "width", "240")).CInt(),
Height: any.Of(process.ArgsURLValue(0, "height", "80")).CInt(),
Length: any.Of(process.ArgsURLValue(0, "height", "4")).CInt(),
Type: process.ArgsURLValue(0, "type", "math"),
Background: process.ArgsURLValue(0, "background", "#FFFFFF"),
Lang: process.ArgsURLValue(0, "lang", "zh"),
}
id, content := MakeCaptcha(option)
return maps.Map{
"id": id,
"content": content,
}
}
// ProcessToken xiang.user.Token 使用 Key & Secret 换取 Token
func ProcessToken(process *gou.Process) interface{} {
return nil
}
// ProcessTokenRefresh xiang.user.TokenRefresh 刷新Token
func ProcessTokenRefresh(process *gou.Process) interface{} {
return nil
}
// ProcessInfo xiang.user.Info 读取当前用户资料
func ProcessInfo(process *gou.Process) interface{} {
return nil
}