make a unique session id
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
09215bc616
commit
569d2788eb
|
@ -5,6 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.hatecomputers.club/hatecomputers/hatecomputers.club/utils"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "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)
|
log.Println("making session for user", user.ID)
|
||||||
|
|
||||||
expireAt := time.Now().Add(time.Hour * 12)
|
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 {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
@ -71,7 +73,7 @@ func MakeUserSessionFor(dbConn *sql.DB, user *User) (*UserSession, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &UserSession{
|
return &UserSession{
|
||||||
ID: user.ID,
|
ID: sessionId,
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
ExpireAt: expireAt,
|
ExpireAt: expireAt,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
Loading…
Reference in New Issue