aboutsummaryrefslogtreecommitdiff
path: root/src/server/Secure.hs
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-07-21 23:25:58 +0200
committerJoris Guyonvarch2015-07-21 23:25:58 +0200
commit2a53fe50c62d4b7aec0f422998c743f68aa523c1 (patch)
treead32464c99668b477c4006146ec218c947bc9c8f /src/server/Secure.hs
parenta271d6034bc4cc631a64476d25d21c83a701fa39 (diff)
downloadbudget-2a53fe50c62d4b7aec0f422998c743f68aa523c1.tar.gz
budget-2a53fe50c62d4b7aec0f422998c743f68aa523c1.tar.bz2
budget-2a53fe50c62d4b7aec0f422998c743f68aa523c1.zip
Adding the payment without reloading the page
Diffstat (limited to 'src/server/Secure.hs')
-rw-r--r--src/server/Secure.hs23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/server/Secure.hs b/src/server/Secure.hs
index 94ee8a9..1fef713 100644
--- a/src/server/Secure.hs
+++ b/src/server/Secure.hs
@@ -8,16 +8,31 @@ import Web.Scotty
import Network.HTTP.Types.Status (forbidden403)
-import Data.Text (Text)
+import Database.Persist (Entity)
+
+import Model.Database (User, runDb)
+import Model.User (getUser)
+
+import Control.Monad.IO.Class (liftIO)
+
+import qualified Data.Text as T
+import qualified Data.Text.IO as TIO
import qualified LoginSession
-loggedAction :: (Text -> ActionM ()) -> ActionM ()
+loggedAction :: (Entity User -> ActionM ()) -> ActionM ()
loggedAction action = do
maybeLogin <- LoginSession.get
case maybeLogin of
- Just login ->
- action login
+ Just login -> do
+ maybeUser <- liftIO . runDb $ getUser login
+ case maybeUser of
+ Just user ->
+ action user
+ Nothing -> do
+ status forbidden403
+ liftIO . TIO.putStrLn . T.concat $ ["Could not find the user which login is ", login]
+ html "Could not find a user from your login"
Nothing -> do
status forbidden403
html "You need to be logged in to perform this action"