From 9e925816e4ce608c5ffb9458d3de4daae8bab0d3 Mon Sep 17 00:00:00 2001 From: nek0 Date: Thu, 18 Jul 2019 16:10:18 +0200 Subject: [PATCH] a little cleaning --- src/Main.hs | 12 ++++++------ src/Model/Auth.hs | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 8459501..89f6a23 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -126,9 +126,9 @@ users = -- void $ liftIO $ runUpdate_ conn (updateUser id us (utctDay now)) userDetailsSelect conn id else - throwError $ err403 - { errBody = "Wrong Authorization present" - } + throwError $ err403 + { errBody = "Wrong Authorization present" + } userPostUpdate :: Maybe Int -> Int -> UserDetailsSubmit -> MateHandler () userPostUpdate Nothing _ _ = @@ -142,9 +142,9 @@ users = conn <- rsConnection <$> ask void $ liftIO $ runUpdate_ conn (updateUserDetails id uds (utctDay now)) else - throwError $ err403 - { errBody = "Wrong Authorization present" - } + throwError $ err403 + { errBody = "Wrong Authorization present" + } beverages = list :<|> diff --git a/src/Model/Auth.hs b/src/Model/Auth.hs index 5425253..461cd75 100644 --- a/src/Model/Auth.hs +++ b/src/Model/Auth.hs @@ -47,6 +47,7 @@ import Types.Reader import Model.User + initToken :: PGS.Query initToken = "create table if not exists \"token\" (token_string bytea not null primary key, token_user integer references \"user\"(user_id) not null, token_expiry timestamptz not null)" @@ -67,6 +68,7 @@ tokenTable = table "token" ( ) ) + getUserAuthInfo :: Int -> MateHandler AuthInfo @@ -99,6 +101,7 @@ getUserAuthInfo ident = do ) users + validateToken :: PGS.Connection -> ByteString @@ -131,6 +134,7 @@ validateToken conn header = do { errBody = "No valid token found!" } + generateToken :: Ticket -> AuthHash @@ -164,6 +168,7 @@ generateToken (Ticket _ ident exp) (AuthHash hash) = do else return Denied + insertToken :: Token -> Insert [ByteString] @@ -180,6 +185,7 @@ insertToken (Token tString tUser tExpiry) = Insert , iOnConflict = Nothing } + deleteToken :: ByteString -> Opaleye.Delete Int64 @@ -213,6 +219,7 @@ newTicket ident = do liftIO $ atomically $ modifyTVar store (\s -> S.insert ticket s) return (AuthTicket rand) + processAuthRequest :: AuthRequest -> MateHandler AuthResult