Increase Session LifeTime

This commit is contained in:
Samuel Lorch 2023-03-26 19:26:30 +02:00
parent 92246048e6
commit bdbbae825a

View file

@ -13,6 +13,7 @@ type SessionKeyType string
const SessionKey SessionKeyType = "session" const SessionKey SessionKeyType = "session"
const SessionCookieName string = "session" const SessionCookieName string = "session"
const SessionLifeTime = time.Minute * 15
type Session struct { type Session struct {
Username string Username string
@ -42,7 +43,7 @@ func ExtendSession(s *Session) {
sessionsSync.Lock() sessionsSync.Lock()
defer sessionsSync.Unlock() defer sessionsSync.Unlock()
if s != nil { if s != nil {
s.Expires = time.Now().Add(time.Minute * 5) s.Expires = time.Now().Add(SessionLifeTime)
} }
} }
@ -60,7 +61,7 @@ func GetSession(r *http.Request) (string, *Session) {
func GenerateSession(w http.ResponseWriter, username string) { func GenerateSession(w http.ResponseWriter, username string) {
id := uuid.New().String() id := uuid.New().String()
expires := time.Now().Add(time.Minute * 5) expires := time.Now().Add(SessionLifeTime)
sessionsSync.Lock() sessionsSync.Lock()
defer sessionsSync.Unlock() defer sessionsSync.Unlock()
sessions[id] = &Session{ sessions[id] = &Session{