From e4eefaa5b418780e6fb63e929f826b927bbeac68 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sun, 19 Jul 2015 00:54:37 +0200 Subject: Authorizing only existing users --- src/server/Application.hs | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) (limited to 'src/server/Application.hs') diff --git a/src/server/Application.hs b/src/server/Application.hs index e480533..28ad3cd 100644 --- a/src/server/Application.hs +++ b/src/server/Application.hs @@ -1,21 +1,19 @@ {-# LANGUAGE OverloadedStrings #-} module Application - ( getIndexAction + ( signIn + , signOut + , getIndexAction , getUsersAction , getPaymentsAction , addUserAction , deleteUserAction , insertPaymentAction - - , signIn - , checkConnection - , signOut ) where import Web.Scotty -import Network.HTTP.Types.Status (badRequest400) +import Network.HTTP.Types.Status (ok200, badRequest400) import Database.Persist @@ -54,12 +52,12 @@ getPaymentsAction = addUserAction :: Text -> Text -> ActionM () addUserAction email name = do _ <- liftIO . runDb $ insertUser email name - html "Ok" + status ok200 deleteUserAction :: Text -> ActionM () deleteUserAction email = do _ <- liftIO . runDb $ deleteUser email - html "Ok" + status ok200 insertPaymentAction :: Text -> Text -> Int -> ActionM () insertPaymentAction email name cost = do @@ -70,29 +68,19 @@ insertPaymentAction email name cost = do return () Nothing -> do status badRequest400 - html "Not found" + status ok200 signIn :: Text -> ActionM () signIn login = do - LoginSession.put login - html "Ok" - -checkConnection :: ActionM () -checkConnection = do - maybeLogin <- LoginSession.get - case maybeLogin of - Just login -> - html . TL.fromStrict $ - T.intercalate - " " - [ "You are connected with the following login:" - , login - ] - Nothing -> do + maybeUser <- liftIO . runDb $ getUser login + case maybeUser of + Just _ -> do + LoginSession.put login + status ok200 + Nothing -> status badRequest400 - html "You are not connected" signOut :: ActionM () signOut = do LoginSession.delete - html "Ok" + status ok200 -- cgit v1.2.3