From f9e49e1145b42e4859ade528b98799e6dcf85dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Sat, 3 Feb 2024 10:53:12 +0100 Subject: [PATCH] Update user login time --- database/pkg.go | 4 ++++ go.sum | 1 + pkg.go | 1 + session.go | 1 + 4 files changed, 7 insertions(+) diff --git a/database/pkg.go b/database/pkg.go index 6fd929e..50695a5 100644 --- a/database/pkg.go +++ b/database/pkg.go @@ -231,6 +231,10 @@ func (db *T) SetSessionUser(uuid string, userID int) (err error) { // {{{ } return } // }}} +func (db *T) UpdateUserTime(userID int) (err error) {// {{{ + _, err = db.Conn.Exec(`UPDATE _webservice.user SET last_login=NOW() WHERE id=$1`, userID) + return +}// }}} func (db *T) CreateUser(username, password, name string) (err error) {// {{{ _, err = db.Conn.Exec(` diff --git a/go.sum b/go.sum index fe5e738..722e995 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,6 @@ git.gibonuddevalla.se/go/dbschema v1.2.0 h1:VhHFfkn/4UnlGy2Ax35Po8vb8E/x6DggtvNUKlGGQyY= git.gibonuddevalla.se/go/dbschema v1.2.0/go.mod h1:BNw3q/574nXbGoeWyK+tLhRfggVkw2j2aXZzrBKC3ig= +git.gibonuddevalla.se/go/dbschema v1.3.0/go.mod h1:BNw3q/574nXbGoeWyK+tLhRfggVkw2j2aXZzrBKC3ig= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= diff --git a/pkg.go b/pkg.go index e03e81e..a8efe5a 100644 --- a/pkg.go +++ b/pkg.go @@ -207,6 +207,7 @@ func (service *Service) Register(path string, requireSession, requireAuthenticat } } + service.logger.Info("webserver", "op", "request", "path", r.URL.String()) handler(w, r, sess) }) } // }}} diff --git a/session.go b/session.go index f69f0e5..a2d2251 100644 --- a/session.go +++ b/session.go @@ -118,6 +118,7 @@ func (service *Service) sessionAuthenticate(w http.ResponseWriter, r *http.Reque service.errorHandler(err, "001-A003", w) return } + service.Db.UpdateUserTime(userID) } authResp, _ := json.Marshal(authResponse)