From 1fc6dd755b722589f4813eeead492f643510e453 Mon Sep 17 00:00:00 2001 From: "LinskRuis.32" Date: Sat, 24 Oct 2020 14:26:54 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=A4=B1=E8=B4=A5=E6=AC=A1?= =?UTF-8?q?=E6=95=B0=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mgr/trigger_hooks.go | 6 +++--- route/server/login.go | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/mgr/trigger_hooks.go b/mgr/trigger_hooks.go index d95554a..97f2b4e 100644 --- a/mgr/trigger_hooks.go +++ b/mgr/trigger_hooks.go @@ -59,9 +59,9 @@ function main(){ `, } HookjsMap["github"] = &Hookjs{ - Uis: map[string]string{"secretkey": "string", "branch": "string"}, - Desc: "secretkey:签名秘钥,branch:push对象分支", - Defs: `{"secretkey":"pwd","branch":"master"}`, + Uis: map[string]string{"password": "string", "branch": "string"}, + Desc: "password:签名秘钥,branch:push对象分支", + Defs: `{"password":"pwd","branch":"master"}`, js: ` function main(){ diff --git a/route/server/login.go b/route/server/login.go index 00e0f3f..d19ac59 100644 --- a/route/server/login.go +++ b/route/server/login.go @@ -27,6 +27,13 @@ func LoginInfo(c *gin.Context) { c.JSON(200, rets) } +type lgTimes struct { + times int + lgtm time.Time +} + +var mplgtms = make(map[string]*lgTimes) + func Login(c *gin.Context, req *ruisUtil.Map) { name := req.GetString("name") pass := req.GetString("pass") @@ -39,10 +46,30 @@ func Login(c *gin.Context, req *ruisUtil.Map) { c.String(511, "未找到用户!") return } + tms, ok := mplgtms[usr.Xid] + if ok && time.Since(tms.lgtm).Minutes() < 10 { + if tms.times >= 2 { + c.String(521, "失败次数太多,十分钟后再试!") + return + } + } if usr.Pass != ruisUtil.Md5String(pass) { + if ok { + tms.times++ + tms.lgtm = time.Now() + if tms.times > 2 { + tms.times = 1 + } + } else { + mplgtms[usr.Xid] = &lgTimes{ + times: 0, + lgtm: time.Now(), + } + } c.String(512, "密码错误!") return } + delete(mplgtms, usr.Xid) tks, err := core.CreateToken(&jwt.MapClaims{ "xid": usr.Xid,