自动更新cookie
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user