diff options
| author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-04-03 09:57:50 -0600 |
|---|---|---|
| committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-04-03 09:57:50 -0600 |
| commit | 569d2788ebfb90774faf361f62bfe7968e091465 (patch) | |
| tree | dac7e1dccb38df15908a22de4b50e48e3a68ec9d /database/users.go | |
| parent | 09215bc6164296a4f4178e603e01e651700997f2 (diff) | |
| download | hatecomputers.club-569d2788ebfb90774faf361f62bfe7968e091465.tar.gz hatecomputers.club-569d2788ebfb90774faf361f62bfe7968e091465.zip | |
make a unique session id
Diffstat (limited to 'database/users.go')
| -rw-r--r-- | database/users.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/database/users.go b/database/users.go index 63e7957..5cebb8f 100644 --- a/database/users.go +++ b/database/users.go @@ -5,6 +5,7 @@ import ( "log" "time" + "git.hatecomputers.club/hatecomputers/hatecomputers.club/utils" _ "github.com/mattn/go-sqlite3" ) @@ -62,8 +63,9 @@ func MakeUserSessionFor(dbConn *sql.DB, user *User) (*UserSession, error) { log.Println("making session for user", user.ID) expireAt := time.Now().Add(time.Hour * 12) + sessionId := utils.RandomId() - _, err := dbConn.Exec(`INSERT OR REPLACE INTO user_sessions (id, user_id, expire_at) VALUES (?, ?, ?);`, user.ID, user.ID, time.Now().Add(ExpiryDuration)) + _, err := dbConn.Exec(`INSERT OR REPLACE INTO user_sessions (id, user_id, expire_at) VALUES (?, ?, ?);`, sessionId, user.ID, time.Now().Add(ExpiryDuration)) if err != nil { log.Println(err) @@ -71,7 +73,7 @@ func MakeUserSessionFor(dbConn *sql.DB, user *User) (*UserSession, error) { } return &UserSession{ - ID: user.ID, + ID: sessionId, UserID: user.ID, ExpireAt: expireAt, }, nil |
