chore(tfstated): refactor setting last login date time on successful HTTP basic auth

This commit is contained in:
Julien Dessaux 2024-12-28 23:16:09 +01:00
parent 6d00e12097
commit 1dbb1b9ee7
Signed by: adyxax
GPG key ID: F92E51B86E07177E
2 changed files with 39 additions and 32 deletions

View file

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"time"
"git.adyxax.org/adyxax/tfstated/pkg/database"
"git.adyxax.org/adyxax/tfstated/pkg/helpers"
@ -29,9 +28,7 @@ func Middleware(db *database.DB) func(http.Handler) http.Handler {
helpers.ErrorResponse(w, http.StatusForbidden, fmt.Errorf("Forbidden"))
return
}
now := time.Now().UTC()
_, err = db.Exec(`UPDATE accounts SET last_login = ? WHERE id = ?`, now.Unix(), account.Id)
if err != nil {
if err := db.TouchAccount(account); err != nil {
helpers.ErrorResponse(w, http.StatusInternalServerError, err)
return
}