自动更新cookie

This commit is contained in:
2025-11-14 20:10:55 +08:00
parent c6c7496449
commit 710d72aefe
14 changed files with 221 additions and 39 deletions
+26
View File
@@ -4,6 +4,7 @@ import (
"crypto/md5"
"crypto/rand"
"encoding/hex"
"time"
)
@@ -55,3 +56,28 @@ func HashUserPass(user *TabUser_) {
}
}
func IsExpired(expireTime time.Time) bool {
return expireTime.Before(time.Now())
}
func CheckCookiesAndUpdate(cookie *TabCookie_) bool {
if !IsExpired(cookie.ExpiresAt) {
if cookie.Remember {
cookiewhere := TabCookie_{
ID: cookie.ID,
}
cookieupdata := TabCookie_{
UpdatedAt: time.Now(),
ExpiresAt: time.Now().Add(time.Duration(ConfigsUser.CookieTimeout) * time.Second),
}
DB.Where(&cookiewhere).Updates(&cookieupdata)
}
return true
} else {
//以过期
return false
}
//return false
}