diff --git a/config/config.go b/config/config.go index 6dae08e1..6309d056 100644 --- a/config/config.go +++ b/config/config.go @@ -136,6 +136,11 @@ func (cfg *Config) SetDefaults() { } } +// IsDebug 是否为调试模式 +func IsDebug() bool { + return Conf.Mode == "debug" +} + func init() { Conf = NewConfig() } diff --git a/user/captcha.go b/user/captcha.go index ef97cfac..334c629d 100644 --- a/user/captcha.go +++ b/user/captcha.go @@ -80,8 +80,8 @@ func MakeCaptcha(option CaptchaOption) (string, string) { } // 打印日志 - if config.Conf.Mode == "debug" { - xlog.Println("图形/音频验证码:", captchaStore.Get(id, false)) + if config.IsDebug() { + xlog.Println("图形/音频 ID:", id, "验证码:", captchaStore.Get(id, false)) } return id, content diff --git a/user/process.go b/user/process.go index 7a6a8880..0d6e0acd 100644 --- a/user/process.go +++ b/user/process.go @@ -6,6 +6,8 @@ import ( "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() { @@ -16,8 +18,27 @@ func init() { // ProcessLogin xiang.user.Login 用户登录 func ProcessLogin(process *gou.Process) interface{} { process.ValidateArgNums(1) - payload := process.ArgsMap(0) - utils.Dump(payload) + 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()