aboutsummaryrefslogtreecommitdiff
path: root/pkg/database/sessions.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--pkg/database/sessions.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/database/sessions.go b/pkg/database/sessions.go
index 72930f0..2db05c8 100644
--- a/pkg/database/sessions.go
+++ b/pkg/database/sessions.go
@@ -31,3 +31,28 @@ func (env *DBEnv) CreateSession(user *model.User) (*string, error) {
}
return &token, nil
}
+
+func (env *DBEnv) ResumeSession(token string) (*model.User, error) {
+ user := model.User{}
+ query := `
+ SELECT
+ id, username, email
+ FROM
+ users
+ INNER JOIN
+ sessions ON users.id = sessions.user_id
+ WHERE
+ sessions.token = $1;`
+ err := env.db.QueryRow(
+ query,
+ token,
+ ).Scan(
+ &user.Id,
+ &user.Username,
+ &user.Email,
+ )
+ if err != nil {
+ return nil, newQueryError("Could not run database query, most likely the token is invalid", err)
+ }
+ return &user, nil
+}