From 8573cd2dbf07c52e6c634268734ce6d8852fba85 Mon Sep 17 00:00:00 2001 From: zhangchenhao Date: Thu, 15 May 2025 15:01:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=AA=8C=E8=AF=81=E7=A0=81co?= =?UTF-8?q?okie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/login.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/backend/app/api/login.go b/backend/app/api/login.go index 2a89917..c412b5d 100644 --- a/backend/app/api/login.go +++ b/backend/app/api/login.go @@ -24,7 +24,7 @@ func Sign(c *gin.Context) { } form.Username = strings.TrimSpace(form.Username) form.Code = strings.TrimSpace(form.Code) - + // 从数据库拿用户 s, err := public.NewSqlite("data/data.db", "") if err != nil { @@ -41,10 +41,10 @@ func Sign(c *gin.Context) { public.FailMsg(c, err.Error()) return } - + session := sessions.Default(c) now := time.Now() - + loginErrCount := session.Get("__loginErrCount") loginErrEnd := session.Get("__loginErrEnd") ErrCount := 0 @@ -57,9 +57,9 @@ func Sign(c *gin.Context) { if __loginErrEnd, ok := loginErrEnd.(time.Time); ok { ErrEnd = __loginErrEnd } - + // fmt.Println(ErrCount, ErrEnd) - + // 判断登录错误次数 switch { case ErrCount >= 5: @@ -91,7 +91,7 @@ func Sign(c *gin.Context) { } } } - + // 判断用户是否存在 if len(res) == 0 { session.Set("__loginErrCount", ErrCount+1) @@ -99,7 +99,7 @@ func Sign(c *gin.Context) { _ = session.Save() // c.JSON(http.StatusBadRequest, public.ResERR("用户不存在")) // 设置cookie - c.SetCookie("must_code", "1", 0, "/", "", false, true) + c.SetCookie("must_code", "1", 0, "/", "", false, false) public.FailMsg(c, "用户不存在") return } @@ -117,7 +117,7 @@ func Sign(c *gin.Context) { keyMd5 := md5.Sum([]byte(passwd)) passwdMd5 := hex.EncodeToString(keyMd5[:]) // fmt.Println(passwdMd5) - + if res[0]["password"] != passwdMd5 { session.Set("__loginErrCount", ErrCount+1) session.Set("__loginErrEnd", now) @@ -128,7 +128,7 @@ func Sign(c *gin.Context) { public.FailMsg(c, "密码错误") return } - + // session := sessions.Default(c) session.Set("__loginErrCount", 0) session.Delete("__loginErrEnd") @@ -137,7 +137,7 @@ func Sign(c *gin.Context) { _ = session.Save() // c.JSON(http.StatusOK, public.ResOK(0, nil, "登录成功")) // 设置cookie - c.SetCookie("must_code", "1", -1, "/", "", false, true) + c.SetCookie("must_code", "1", 0, "/", "", false, false) public.SuccessMsg(c, "登录成功") return } @@ -145,7 +145,7 @@ func Sign(c *gin.Context) { func GetCode(c *gin.Context) { _, bs64, code, _ := public.GenerateCode() session := sessions.Default(c) - + session.Set("_verifyCode", code) _ = session.Save() public.SuccessData(c, bs64, 0)