aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Login.hs
blob: 5e0ff0d421e22df75f6f8ec30880336c96da91d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DuplicateRecordFields #-}

module Model.Login (LoginRequest (..), LoginResponse (..), LoginFlowsResponse (..), LoginFlow (..), PasswordIdentifier (..)) where

import Data.Aeson
import GHC.Generics
import Data.Text (Text)

import Util (Normalisable(..))

type UserId = Text

----------------------------------------------------------------------------------------------------
data PasswordIdentifier = PasswordIdentifier
  { user :: UserId
  }
  deriving (Show, Eq, Generic)

instance FromJSON PasswordIdentifier

data LoginRequest = LoginRequest
  { identifier :: PasswordIdentifier
  , password :: Text
  , type' :: Text
  , initial_device_display_name :: Maybe Text
  , refresh_token :: Maybe Bool
  , device_id :: Maybe Text
  }
  deriving (Show, Eq, Generic)

instance FromJSON LoginRequest where
  parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = normaliseVariant }

----------------------------------------------------------------------------------------------------
data LoginResponse = LoginResponse
  { user_id :: UserId
  , access_token :: Text
  , home_server :: Text
  , device_id :: Text
  }
  deriving (Show, Eq, Generic)

instance ToJSON LoginResponse

----------------------------------------------------------------------------------------------------
newtype LoginFlowsResponse = LoginFlowsResponse
  { flows :: [LoginFlow] -- TODO: Enum?
  }
  deriving (Show, Eq, Generic)

instance ToJSON LoginFlowsResponse

newtype LoginFlow = LoginFlow -- TODO: Maybe type LoginFlow = ... easier?
  { type' :: Text
  }
  deriving (Show, Eq, Generic)

instance ToJSON LoginFlow where
  toJSON (LoginFlow t) = object ["type" .= t]