修复验证码cookie

pull/79/head
zhangchenhao 2025-05-15 15:01:19 +08:00
parent 1b8994a63c
commit 8573cd2dbf
1 changed files with 11 additions and 11 deletions

View File

@ -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)