From 5fd1c739acceb645efbb424bd5c7e60d7502772b Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 21 Nov 2021 22:34:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E6=8A=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper/captcha.go | 8 +++++++- helper/captcha_test.go | 4 ++++ helper/password.go | 2 ++ helper/password_test.go | 9 ++++++--- xiang/apis/xiang.http.json | 10 ++++++++++ 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/helper/captcha.go b/helper/captcha.go index 8c52e43e..69e14114 100644 --- a/helper/captcha.go +++ b/helper/captcha.go @@ -144,7 +144,13 @@ func captchaParseHexColorFast(s string) (c color.RGBA, err error) { // ProcessCaptchaValidate xiang.helper.CaptchaValidate 校验图形/音频验证码 func ProcessCaptchaValidate(process *gou.Process) interface{} { process.ValidateArgNums(2) - if !CaptchaValidate(process.ArgsString(0), process.ArgsString(1)) { + id := process.ArgsString(0) + code := process.ArgsString(1) + if code == "" { + exception.New("请输入验证码", 400).Throw() + return false + } + if !CaptchaValidate(id, code) { exception.New("验证码不正确", 400).Throw() return false } diff --git a/helper/captcha_test.go b/helper/captcha_test.go index 587f419a..6fb4cd8c 100644 --- a/helper/captcha_test.go +++ b/helper/captcha_test.go @@ -62,4 +62,8 @@ func TestProcessCaptcha(t *testing.T) { assert.Panics(t, func() { gou.NewProcess("xiang.helper.CaptchaValidate", res.Get("id"), "xxx").Run() }) + + assert.Panics(t, func() { + gou.NewProcess("xiang.helper.CaptchaValidate", res.Get("id"), "").Run() + }) } diff --git a/helper/password.go b/helper/password.go index 08a0ac85..1887959e 100644 --- a/helper/password.go +++ b/helper/password.go @@ -2,6 +2,7 @@ package helper import ( "github.com/yaoapp/gou" + "github.com/yaoapp/kun/exception" "golang.org/x/crypto/bcrypt" ) @@ -9,6 +10,7 @@ import ( func PasswordValidate(password string, passwordHash string) bool { err := bcrypt.CompareHashAndPassword([]byte(passwordHash), []byte(password)) if err != nil { + exception.New("密码不正确", 400).Throw() return false } return true diff --git a/helper/password_test.go b/helper/password_test.go index efe6a2f7..e03883a7 100644 --- a/helper/password_test.go +++ b/helper/password_test.go @@ -9,7 +9,9 @@ import ( func TestPassword(t *testing.T) { assert.True(t, PasswordValidate("U123456p+", "$2a$04$TS/rWBs66jADjQl8fa.w..ivkNAjH8d4sI1OPGvEB9Leed6EpzIF2")) - assert.False(t, PasswordValidate("U123456p+", "123456")) + assert.Panics(t, func() { + PasswordValidate("U123456p+", "123456") + }) } func TestProcessPassword(t *testing.T) { @@ -22,6 +24,7 @@ func TestProcessPassword(t *testing.T) { args = []interface{}{pwd, "123456"} process = gou.NewProcess("xiang.helper.PasswordValidate", args...) - res = process.Run() - assert.False(t, res.(bool)) + assert.Panics(t, func() { + process.Run() + }) } diff --git a/xiang/apis/xiang.http.json b/xiang/apis/xiang.http.json index e47e82c5..0e9e57b8 100644 --- a/xiang/apis/xiang.http.json +++ b/xiang/apis/xiang.http.json @@ -27,6 +27,16 @@ "type": "application/json" } }, + { + "path": "/menu", + "method": "GET", + "process": "flows.xiang.menu", + "in": ["$session.id"], + "out": { + "status": 200, + "type": "application/json" + } + }, { "path": "/favicon.ico", "method": "GET",