2019-04-17 14:14:44 +00:00
|
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Types.User where
|
|
|
|
|
|
|
|
import GHC.Generics
|
|
|
|
|
|
|
|
import Data.Time.Calendar (Day)
|
|
|
|
|
|
|
|
import Data.Aeson
|
|
|
|
|
|
|
|
import qualified Data.Text as T
|
|
|
|
|
|
|
|
-- internal imports
|
|
|
|
|
|
|
|
import Types.Auth
|
|
|
|
|
|
|
|
data User
|
|
|
|
= User
|
|
|
|
{ userId :: Int
|
|
|
|
, userIdent :: T.Text
|
|
|
|
, userBalance :: Int
|
|
|
|
, userTimeStamp :: Day
|
|
|
|
, userEmail :: Maybe T.Text
|
|
|
|
, userAvatar :: Maybe Int
|
|
|
|
, userSalt :: AuthSalt
|
|
|
|
, userHash :: Maybe AuthHash
|
|
|
|
, userAlgo :: Maybe Int
|
|
|
|
}
|
|
|
|
deriving (Generic, Show)
|
|
|
|
|
|
|
|
instance ToJSON User where
|
|
|
|
toEncoding (User id ident balance ts email avatar _ _ _) =
|
|
|
|
pairs
|
|
|
|
( "userId" .= id
|
|
|
|
<> "userIdent" .= ident
|
|
|
|
<> "userAvatar" .= avatar
|
|
|
|
)
|
|
|
|
|
|
|
|
instance FromJSON User
|
|
|
|
|
2019-05-16 16:37:04 +00:00
|
|
|
|
2019-04-17 14:14:44 +00:00
|
|
|
data UserSubmit = UserSubmit
|
|
|
|
{ userSubmitIdent :: T.Text
|
|
|
|
, userSubmitEmail :: Maybe T.Text
|
|
|
|
--, userSubmitPin :: Maybe T.Text
|
|
|
|
}
|
|
|
|
deriving (Generic, Show)
|
|
|
|
|
|
|
|
instance ToJSON UserSubmit where
|
2019-05-16 16:37:04 +00:00
|
|
|
toEncoding = genericToEncoding defaultOptions
|
2019-04-17 14:14:44 +00:00
|
|
|
|
|
|
|
instance FromJSON UserSubmit
|
2019-05-16 16:37:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
data UserDetails = UserDetails
|
|
|
|
{ userDetailsIdent :: T.Text
|
|
|
|
, userDetailsBalance :: Int
|
|
|
|
, userDetailsEmail :: Maybe T.Text
|
|
|
|
, userDetailsAvatar :: Maybe Int
|
|
|
|
, userDetailsSalt :: AuthSalt
|
|
|
|
, userDetailsAlgo :: Maybe AuthAlgorithm
|
|
|
|
}
|
|
|
|
deriving (Generic, Show)
|
|
|
|
|
|
|
|
instance ToJSON UserDetails where
|
|
|
|
toEncoding = genericToEncoding defaultOptions
|
|
|
|
|
|
|
|
instance FromJSON UserDetails
|
|
|
|
|
|
|
|
|
|
|
|
data UserDetailsSubmit = UserDetailsSubmit
|
|
|
|
{ userDetailsSubmitIdent :: T.Text
|
|
|
|
, userDetailsSubmitEmail :: Maybe T.Text
|
|
|
|
, userDetailsSubmitAvatar :: Maybe Int
|
|
|
|
, userDetailsSubmitHash :: Maybe AuthHash
|
|
|
|
, userDetailsSubmitAlgo :: Maybe AuthAlgorithm
|
|
|
|
}
|
|
|
|
deriving (Generic, Show)
|
|
|
|
|
|
|
|
instance ToJSON UserDetailsSubmit where
|
|
|
|
toEncoding = genericToEncoding defaultOptions
|
|
|
|
|
|
|
|
instance FromJSON UserDetailsSubmit
|
2019-08-14 16:03:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
data UserRecharge = UserRecharge
|
|
|
|
{ userRechargeId :: Int
|
|
|
|
, userRechargeAmount :: Int
|
|
|
|
}
|
|
|
|
deriving (Generic, Show)
|
|
|
|
|
|
|
|
instance ToJSON UserRecharge where
|
|
|
|
toEncoding = genericToEncoding defaultOptions
|
|
|
|
|
|
|
|
instance FromJSON UserRecharge
|