aboutsummaryrefslogtreecommitdiff
path: root/src/server/Controller
diff options
context:
space:
mode:
authorJoris2015-09-05 13:53:36 +0200
committerJoris2015-09-05 13:53:36 +0200
commit3b738e0d4cc65f314da7389d4542ec826ba0f454 (patch)
treeee99236117ad698974c5a6e40ab170f617cb06f3 /src/server/Controller
parent139d4a103a6a48880e5f12a796033956f223563c (diff)
downloadbudget-3b738e0d4cc65f314da7389d4542ec826ba0f454.tar.gz
budget-3b738e0d4cc65f314da7389d4542ec826ba0f454.tar.bz2
budget-3b738e0d4cc65f314da7389d4542ec826ba0f454.zip
Using UserId instead of UserName to indentify users
Diffstat (limited to 'src/server/Controller')
-rw-r--r--src/server/Controller/Index.hs38
-rw-r--r--src/server/Controller/User.hs25
2 files changed, 25 insertions, 38 deletions
diff --git a/src/server/Controller/Index.hs b/src/server/Controller/Index.hs
index 2d8c40c..17f5ae9 100644
--- a/src/server/Controller/Index.hs
+++ b/src/server/Controller/Index.hs
@@ -1,58 +1,20 @@
module Controller.Index
( getIndexAction
- , getUserName
, signOutAction
- , getUsersAction
- , addUserAction
- , deleteUserAction
) where
import Web.Scotty
import Network.HTTP.Types.Status (ok200)
-import Database.Persist
-
-import Control.Monad.IO.Class (liftIO)
-
-import Data.Text (Text)
-import Data.String (fromString)
-
import qualified LoginSession
-import qualified Secure
-
-import Model.Database
-import Model.User
-import Model.Json.Message
-
import View.Page (page)
getIndexAction :: ActionM ()
getIndexAction = html page
-getUserName :: ActionM ()
-getUserName =
- Secure.loggedAction (\user -> do
- json . Message . userName . entityVal $ user
- )
-
signOutAction :: ActionM ()
signOutAction = do
LoginSession.delete
status ok200
-
-getUsersAction :: ActionM ()
-getUsersAction = do
- users <- liftIO $ runDb getUsers
- html . fromString . show $ users
-
-addUserAction :: Text -> Text -> ActionM ()
-addUserAction email name = do
- _ <- liftIO . runDb $ createUser email name
- status ok200
-
-deleteUserAction :: Text -> ActionM ()
-deleteUserAction email = do
- _ <- liftIO . runDb $ deleteUser email
- status ok200
diff --git a/src/server/Controller/User.hs b/src/server/Controller/User.hs
new file mode 100644
index 0000000..95e5fa8
--- /dev/null
+++ b/src/server/Controller/User.hs
@@ -0,0 +1,25 @@
+module Controller.User
+ ( getUsersAction
+ , whoAmIAction
+ ) where
+
+import Web.Scotty
+
+import Control.Monad.IO.Class (liftIO)
+
+import qualified Secure
+
+import Model.Database
+import Model.User
+
+getUsersAction :: ActionM ()
+getUsersAction =
+ Secure.loggedAction (\_ -> do
+ (liftIO $ map getJsonUser <$> runDb getUsers) >>= json
+ )
+
+whoAmIAction :: ActionM ()
+whoAmIAction =
+ Secure.loggedAction (\user -> do
+ json (getJsonUser user)
+ )