mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-04-19 19:59:13 +03:00
Rename last_update to updated_at
This commit is contained in:
parent
99ac9b176e
commit
9f527d18ac
2 changed files with 10 additions and 10 deletions
|
@ -115,7 +115,7 @@ func Login(db store.IStore) echo.HandlerFunc {
|
||||||
sess.Values["admin"] = dbuser.Admin
|
sess.Values["admin"] = dbuser.Admin
|
||||||
sess.Values["session_token"] = tokenUID
|
sess.Values["session_token"] = tokenUID
|
||||||
sess.Values["max_age"] = ageMax
|
sess.Values["max_age"] = ageMax
|
||||||
sess.Values["last_update"] = time.Now().UTC().Unix()
|
sess.Values["updated_at"] = time.Now().UTC().Unix()
|
||||||
sess.Save(c.Request(), c.Response())
|
sess.Save(c.Request(), c.Response())
|
||||||
|
|
||||||
// set session_token in cookie
|
// set session_token in cookie
|
||||||
|
|
|
@ -53,16 +53,16 @@ func isValidSession(c echo.Context) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check time bounds
|
// Check time bounds
|
||||||
lastUpdate := getLastUpdate(sess)
|
updatedAt := getUpdatedAt(sess)
|
||||||
maxAge := getMaxAge(sess)
|
maxAge := getMaxAge(sess)
|
||||||
// Temporary session is considered valid within 24h if browser is not closed before
|
// Temporary session is considered valid within 24h if browser is not closed before
|
||||||
// This value is not saved and is used as virtual expiration
|
// This value is not saved and is used as virtual expiration
|
||||||
if maxAge == 0 {
|
if maxAge == 0 {
|
||||||
maxAge = 86400
|
maxAge = 86400
|
||||||
}
|
}
|
||||||
expiration := lastUpdate + int64(maxAge)
|
expiration := updatedAt + int64(maxAge)
|
||||||
now := time.Now().UTC().Unix()
|
now := time.Now().UTC().Unix()
|
||||||
if lastUpdate > now || expiration < now {
|
if updatedAt > now || expiration < now {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,16 +96,16 @@ func doRefreshSession(c echo.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh no sooner than 24h
|
// Refresh no sooner than 24h
|
||||||
lastUpdate := getLastUpdate(sess)
|
updatedAt := getUpdatedAt(sess)
|
||||||
expiration := lastUpdate + int64(getMaxAge(sess))
|
expiration := updatedAt + int64(getMaxAge(sess))
|
||||||
now := time.Now().UTC().Unix()
|
now := time.Now().UTC().Unix()
|
||||||
if expiration < now || now-lastUpdate < 86400 {
|
if expiration < now || now-updatedAt < 86400 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cookiePath := util.GetCookiePath()
|
cookiePath := util.GetCookiePath()
|
||||||
|
|
||||||
sess.Values["last_update"] = now
|
sess.Values["updated_at"] = now
|
||||||
sess.Options = &sessions.Options{
|
sess.Options = &sessions.Options{
|
||||||
Path: cookiePath,
|
Path: cookiePath,
|
||||||
MaxAge: maxAge,
|
MaxAge: maxAge,
|
||||||
|
@ -141,12 +141,12 @@ func getMaxAge(sess *sessions.Session) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a timestamp in seconds of the last session update
|
// Get a timestamp in seconds of the last session update
|
||||||
func getLastUpdate(sess *sessions.Session) int64 {
|
func getUpdatedAt(sess *sessions.Session) int64 {
|
||||||
if util.DisableLogin {
|
if util.DisableLogin {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
lastUpdate := sess.Values["last_update"]
|
lastUpdate := sess.Values["updated_at"]
|
||||||
|
|
||||||
switch typedLastUpdate := lastUpdate.(type) {
|
switch typedLastUpdate := lastUpdate.(type) {
|
||||||
case int64:
|
case int64:
|
||||||
|
|
Loading…
Add table
Reference in a new issue