about summary refs log tree commit diff
path: root/src/Sessions.hs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-07-29T19·21+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-07-29T19·21+0100
commitab12be784068c19f3e8dd00494b83a510c602e9c (patch)
treed5a0c6fa41fc0a2350e7aa9dad71c4b666085de7 /src/Sessions.hs
parent16f50e33bc20cfd1010d22c8533c0e6666a41f4c (diff)
Support looking up a session by its UUID
We need to read a session from the session table using its UUID.
Diffstat (limited to 'src/Sessions.hs')
-rw-r--r--src/Sessions.hs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/Sessions.hs b/src/Sessions.hs
index 12b641b92ff6..b03de6eee6b4 100644
--- a/src/Sessions.hs
+++ b/src/Sessions.hs
@@ -17,6 +17,14 @@ isValid session = do
   let t0 = T.storedSessionTsCreated session in
     pure $ Clock.diffUTCTime t1 t0 <= 3 * 60 * 60
 
+-- | Lookup the session by UUID.
+get :: FilePath -> T.SessionUUID -> IO (Maybe T.StoredSession)
+get dbFile uuid = withConnection dbFile $ \conn -> do
+  res <- query conn "SELECT * FROM Session WHERE uuid = ?" (Only uuid)
+  case res of
+    [x] -> pure (Just x)
+    _ -> pure Nothing
+
 -- | Lookup the session stored under `username` in `dbFile`.
 find :: FilePath -> T.Username -> IO (Maybe T.StoredSession)
 find dbFile username = withConnection dbFile $ \conn -> do