diff options
Diffstat (limited to 'src/server/Model')
-rw-r--r-- | src/server/Model/Init.hs | 31 | ||||
-rw-r--r-- | src/server/Model/Json/Init.hs | 33 | ||||
-rw-r--r-- | src/server/Model/Message/Key.hs | 1 | ||||
-rw-r--r-- | src/server/Model/Message/Translations.hs | 5 |
4 files changed, 70 insertions, 0 deletions
diff --git a/src/server/Model/Init.hs b/src/server/Model/Init.hs new file mode 100644 index 0000000..167eead --- /dev/null +++ b/src/server/Model/Init.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Model.Init + ( getInit + ) where + +import Control.Monad.IO.Class (liftIO) + +import Database.Persist + +import Model.Database + +import Model.Json.Init (Init, Init(Init)) +import Model.Payment (getPayments) +import Model.User (getUsers, getJsonUser) +import Model.Income (getIncomes, getJsonIncome) + +import qualified Model.Json.Init as Init + +getInit :: Entity User -> Persist Init +getInit user = + liftIO . runDb $ do + users <- getUsers + payments <- getPayments + incomes <- getIncomes + return $ Init + { Init.users = map getJsonUser users + , Init.me = entityKey user + , Init.payments = payments + , Init.incomes = map getJsonIncome incomes + } diff --git a/src/server/Model/Json/Init.hs b/src/server/Model/Json/Init.hs new file mode 100644 index 0000000..5e6d2a2 --- /dev/null +++ b/src/server/Model/Json/Init.hs @@ -0,0 +1,33 @@ +{-# LANGUAGE DeriveGeneric #-} + +module Model.Json.Init + ( Init(..) + , InitResult(..) + ) where + +import GHC.Generics + +import Data.Aeson + +import Model.Database (UserId) +import Model.Json.User (User) +import Model.Json.Payment (Payment) +import Model.Json.Income (Income) +import Model.Message.Key (Key) + +data Init = Init + { users :: [User] + , me :: UserId + , payments :: [Payment] + , incomes :: [Income] + } deriving (Show, Generic) + +instance ToJSON Init + +data InitResult = + InitEmpty + | InitSuccess Init + | InitError Key + deriving (Show, Generic) + +instance ToJSON InitResult diff --git a/src/server/Model/Message/Key.hs b/src/server/Model/Message/Key.hs index 6f29f43..8f5cf2a 100644 --- a/src/server/Model/Message/Key.hs +++ b/src/server/Model/Message/Key.hs @@ -20,6 +20,7 @@ data Key = | SendEmailFail | InvalidEmail | UnauthorizedSignIn + | Forbidden | EnterValidEmail | SignInUsed | SignInExpired diff --git a/src/server/Model/Message/Translations.hs b/src/server/Model/Message/Translations.hs index b7d9b4f..f41a417 100644 --- a/src/server/Model/Message/Translations.hs +++ b/src/server/Model/Message/Translations.hs @@ -44,6 +44,11 @@ m l UnauthorizedSignIn = English -> "You are not authorized to sign in." French -> "Tu n'es pas autorisé à te connecter." +m l Forbidden = + case l of + English -> "You need to be logged in to perform this action" + French -> "Tu dois te connecter pour effectuer cette action" + m l SendEmailFail = case l of English -> "You are authorized to sign in, but we failed to send you the sign up email." |