From 609ef3f3b4d4cb355d80b19df1e91db258b0bbe0 Mon Sep 17 00:00:00 2001 From: sanine-a Date: Wed, 10 May 2023 15:17:18 -0500 Subject: log out after 1 hour of inactivity --- db/session.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'db') diff --git a/db/session.go b/db/session.go index da081f9..7ebb6df 100644 --- a/db/session.go +++ b/db/session.go @@ -22,8 +22,8 @@ func (p *Phlox) CreateSession(user User) (Session, error) { nowStr := now.Format(time.RFC3339) _, err = p.db.Exec( - "insert into sessions (sessionid, userid, created, modified) values (?, ?, ?, ?);", - sessionid, + "insert into sessions (sessionid, userid, created, modified) values (?, ?, ?, ?);", + sessionid, userid, nowStr, nowStr, ) @@ -107,6 +107,11 @@ func (p *Phlox) TouchSession(session Session) error { } +func (p *Phlox) TouchSessionId(id string) error { + return p.TouchSession(Session{ Id: id }) +} + + func (p *Phlox) CleanSessions(maxIdle time.Duration) error { expire := time.Now().UTC().Add(-maxIdle).Format(time.RFC3339) _, err := p.db.Exec("delete from sessions where modified < ?;", expire) -- cgit v1.2.1