From ab12be784068c19f3e8dd00494b83a510c602e9c Mon Sep 17 00:00:00 2001 From: William Carroll Date: Wed, 29 Jul 2020 20:21:56 +0100 Subject: [PATCH] Support looking up a session by its UUID We need to read a session from the session table using its UUID. --- src/Sessions.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Sessions.hs b/src/Sessions.hs index 12b641b92..b03de6eee 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