通报错误
This commit is contained in:
parent
3f68510076
commit
5fd1c739ac
5 changed files with 29 additions and 4 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue