aboutsummaryrefslogtreecommitdiff
path: root/server/src/Controller
diff options
context:
space:
mode:
authorJoris2017-11-19 00:20:25 +0100
committerJoris2017-11-19 00:20:25 +0100
commit7194cddb28656c721342c2ef604f9f9fb0692960 (patch)
tree5b8c8562c9a1680aa315b4b7e10a3a7c22900863 /server/src/Controller
parent42e94a45e26f40edc3ad71b1e77a4bf47c13fd3d (diff)
Show payment count and partition
- Also fixes exceedingPayer in back by using only punctual payments
Diffstat (limited to 'server/src/Controller')
-rw-r--r--server/src/Controller/Category.hs7
-rw-r--r--server/src/Controller/Income.hs7
-rw-r--r--server/src/Controller/Index.hs15
-rw-r--r--server/src/Controller/Payment.hs2
-rw-r--r--server/src/Controller/SignIn.hs15
5 files changed, 17 insertions, 29 deletions
diff --git a/server/src/Controller/Category.hs b/server/src/Controller/Category.hs
index a646496..5565b43 100644
--- a/server/src/Controller/Category.hs
+++ b/server/src/Controller/Category.hs
@@ -1,5 +1,3 @@
-{-# LANGUAGE OverloadedStrings #-}
-
module Controller.Category
( create
, edit
@@ -11,10 +9,9 @@ import qualified Data.Text.Lazy as TL
import Network.HTTP.Types.Status (badRequest400, ok200)
import Web.Scotty hiding (delete)
-import qualified Common.Message as Message
-import qualified Common.Message.Key as Key
import Common.Model (CategoryId, CreateCategory (..),
EditCategory (..))
+import qualified Common.Msg as Msg
import Json (jsonId)
import qualified Model.Category as Category
@@ -50,5 +47,5 @@ delete categoryId =
status ok200
else do
status badRequest400
- text . TL.fromStrict $ Message.get Key.Category_NotDeleted
+ text . TL.fromStrict $ Msg.get Msg.Category_NotDeleted
)
diff --git a/server/src/Controller/Income.hs b/server/src/Controller/Income.hs
index c42f6a7..19f0cfc 100644
--- a/server/src/Controller/Income.hs
+++ b/server/src/Controller/Income.hs
@@ -1,5 +1,3 @@
-{-# LANGUAGE OverloadedStrings #-}
-
module Controller.Income
( create
, editOwn
@@ -11,10 +9,9 @@ import qualified Data.Text.Lazy as TL
import Network.HTTP.Types.Status (badRequest400, ok200)
import Web.Scotty
-import qualified Common.Message as Message
-import qualified Common.Message.Key as Key
import Common.Model (CreateIncome (..), EditIncome (..),
IncomeId, User (..))
+import qualified Common.Msg as Msg
import Json (jsonId)
import qualified Model.Income as Income
@@ -45,5 +42,5 @@ deleteOwn incomeId =
status ok200
else do
status badRequest400
- text . TL.fromStrict $ Message.get Key.Income_NotDeleted
+ text . TL.fromStrict $ Msg.get Msg.Income_NotDeleted
)
diff --git a/server/src/Controller/Index.hs b/server/src/Controller/Index.hs
index bf4859d..f05ce6f 100644
--- a/server/src/Controller/Index.hs
+++ b/server/src/Controller/Index.hs
@@ -10,10 +10,9 @@ import Network.HTTP.Types.Status (ok200)
import Prelude hiding (error)
import Web.Scotty hiding (get)
-import qualified Common.Message as Message
-import Common.Message.Key (Key)
-import qualified Common.Message.Key as Key
import Common.Model (InitResult (..), User (..))
+import Common.Msg (Key)
+import qualified Common.Msg as Msg
import Conf (Conf (..))
import qualified LoginSession
@@ -31,7 +30,7 @@ get conf mbToken = do
userOrError <- validateSignIn conf token
case userOrError of
Left errorKey ->
- return . InitEmpty . Left . Message.get $ errorKey
+ return . InitEmpty . Left . Msg.get $ errorKey
Right user ->
liftIO . Query.run . fmap InitSuccess $ getInit user conf
Nothing -> do
@@ -54,23 +53,23 @@ validateSignIn conf textToken = do
now <- liftIO getCurrentTime
case mbSignIn of
Nothing ->
- return . Left $ Key.SignIn_LinkInvalid
+ return . Left $ Msg.SignIn_LinkInvalid
Just signIn ->
if SignIn.isUsed signIn
then
- return . Left $ Key.SignIn_LinkUsed
+ return . Left $ Msg.SignIn_LinkUsed
else
let diffTime = now `diffUTCTime` (SignIn.creation signIn)
in if diffTime > signInExpiration conf
then
- return . Left $ Key.SignIn_LinkExpired
+ return . Left $ Msg.SignIn_LinkExpired
else do
LoginSession.put conf (SignIn.token signIn)
mbUser <- liftIO . Query.run $ do
SignIn.signInTokenToUsed . SignIn.id $ signIn
User.get . SignIn.email $ signIn
return $ case mbUser of
- Nothing -> Left Key.Secure_Unauthorized
+ Nothing -> Left Msg.Secure_Unauthorized
Just user -> Right user
getLoggedUser :: ActionM (Maybe User)
diff --git a/server/src/Controller/Payment.hs b/server/src/Controller/Payment.hs
index e4104eb..c6c874a 100644
--- a/server/src/Controller/Payment.hs
+++ b/server/src/Controller/Payment.hs
@@ -1,5 +1,3 @@
-{-# LANGUAGE OverloadedStrings #-}
-
module Controller.Payment
( list
, create
diff --git a/server/src/Controller/SignIn.hs b/server/src/Controller/SignIn.hs
index 5552781..cf92c9f 100644
--- a/server/src/Controller/SignIn.hs
+++ b/server/src/Controller/SignIn.hs
@@ -1,5 +1,3 @@
-{-# LANGUAGE OverloadedStrings #-}
-
module Controller.SignIn
( signIn
) where
@@ -11,9 +9,8 @@ import qualified Data.Text.Lazy as TL
import Network.HTTP.Types.Status (badRequest400, ok200)
import Web.Scotty
-import qualified Common.Message as Message
-import qualified Common.Message.Key as Key
import Common.Model (SignIn (..))
+import qualified Common.Msg as Msg
import Conf (Conf)
import qualified Conf
@@ -40,8 +37,8 @@ signIn conf (SignIn email) =
]
maybeSentMail <- liftIO . SendMail.sendMail $ SignIn.mail conf user url [email]
case maybeSentMail of
- Right _ -> textKey ok200 Key.SignIn_EmailSent
- Left _ -> textKey badRequest400 Key.SignIn_EmailSendFail
- Nothing -> textKey badRequest400 Key.Secure_Unauthorized
- else textKey badRequest400 Key.SignIn_EmailInvalid
- where textKey st key = status st >> (text . TL.fromStrict $ Message.get key)
+ Right _ -> textKey ok200 Msg.SignIn_EmailSent
+ Left _ -> textKey badRequest400 Msg.SignIn_EmailSendFail
+ Nothing -> textKey badRequest400 Msg.Secure_Unauthorized
+ else textKey badRequest400 Msg.SignIn_EmailInvalid
+ where textKey st key = status st >> (text . TL.fromStrict $ Msg.get key)