From 6ba35f09fcbf2e4925cf8795781b7990f5442cb6 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 16 Jul 2022 12:20:09 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E8=AE=BF=E9=97=AE=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E7=A0=81=E8=BE=93=E5=85=A5=E9=94=99=E8=AF=AF=203=20=E6=AC=A1?= =?UTF-8?q?=E5=90=8E=E5=8A=A0=E5=85=A5=E9=AA=8C=E8=AF=81=E7=A0=81=20https:?= =?UTF-8?q?//github.com/siyuan-note/siyuan/issues/5429?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/stage/auth.html | 2 +- kernel/model/session.go | 35 +++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/stage/auth.html b/app/stage/auth.html index c4239b94f..c63176e75 100644 --- a/app/stage/auth.html +++ b/app/stage/auth.html @@ -466,7 +466,7 @@ method: 'POST', body: JSON.stringify({ authCode: inputElement.value, - captchaImg: captchaElement.value, + captcha: captchaElement.value, }), }).then((response) => { return response.json() diff --git a/kernel/model/session.go b/kernel/model/session.go index 0a634fdaf..de75918bc 100644 --- a/kernel/model/session.go +++ b/kernel/model/session.go @@ -63,21 +63,19 @@ func LoginAuth(c *gin.Context) { var inputCaptcha string session := util.GetSession(c) if session.NeedCaptcha() { - _ = inputCaptcha - //captchaArg := arg["captcha"] - //if nil == captchaArg { - // c.Status(400) - // ret.Code = -1 - // ret.Msg = "need input captcha" - // return - //} - //inputCaptcha = captchaArg.(string) - // - //if session.Captcha != inputCaptcha { - // ret.Code = -1 - // ret.Msg = "invalid captcha" - // return - //} + captchaArg := arg["captcha"] + if nil == captchaArg { + ret.Code = 1 + ret.Msg = "need input captcha" + return + } + inputCaptcha = captchaArg.(string) + + if session.Captcha != inputCaptcha { + ret.Code = 1 + ret.Msg = "invalid captcha" + return + } } authCode := arg["authCode"].(string) @@ -110,7 +108,12 @@ func LoginAuth(c *gin.Context) { } func GetCaptcha(c *gin.Context) { - img, err := captcha.NewMathExpr(150, 30) + img, err := captcha.New(100, 26, func(options *captcha.Options) { + options.CharPreset = "abcdefghjkmnpqrtuvwxyz2346789" + options.Noise = 0.5 + options.CurveNumber = 0 + options.FontScale = 1.2 + }) if nil != err { util.LogErrorf("generates captcha failed: " + err.Error()) c.Status(500)