Commit d788eb8a authored by Allele Dev's avatar Allele Dev

fix: simplify session management

parent c9e414f5
module API.Controllers.Common (
getSessionKey,
setSessionKey,
getSession,
setSession,
deleteSession,
ok,
created,
......@@ -20,12 +21,18 @@ import qualified Network.HTTP.Types.Status as HTTP
import API.Errors
setSessionKey :: MonadIO m => UUID -> ActionT m ()
setSessionKey skey =
setCookie "SessionKey" (toText skey) 120000
sessionKey :: Text
sessionKey = "SessionKey"
getSessionKey :: MonadIO m => ActionT m (Maybe Text)
getSessionKey = cookie "SessionKey"
setSession :: MonadIO m => UUID -> ActionT m ()
setSession skey =
setCookie sessionKey (toText skey) 120000
getSession :: MonadIO m => ActionT m (Maybe Text)
getSession = cookie sessionKey
deleteSession :: MonadIO m => ActionT m ()
deleteSession = deleteCookie sessionKey
ok :: (ToJSON a, MonadIO m) => a -> ActionT m b
ok a = setStatus HTTP.status200 >> json a
......
......@@ -46,7 +46,7 @@ login sqlC redisC logger = do
AuthError -> errorResponse AuthenticationDown
(AuthOkay (Email n) _) -> do
skey <- liftIO $ makeSession redisC logger
setSessionKey skey
setSession skey
liftIO $ info logger Login Post $ n <> " has logged in"
-- TODO: update last_login field for users
noContent
......@@ -67,7 +67,7 @@ checkAuth _ Nothing = return AuthMissing
checkSession :: R.Connection -> ActionT IO SessionCheck
checkSession redisC = do
key <- getSessionKey
key <- getSession
case key of
Nothing -> return InvalidSession
(Just k) -> do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment