Decode a few other message types.
parent
e80b71c0cd
commit
d17e29c1f5
|
@ -49,10 +49,6 @@ import App.IPC as IPC
|
|||
-- Deletion can be triggered by either an admin or the user.
|
||||
|
||||
Possible answers:
|
||||
- 2 type User = { user :: UserPublic.UserPublic }
|
||||
- 3 type UserAdded = { user :: UserPublic.UserPublic }
|
||||
- 4 type UserEdited = { uid :: Int32 }
|
||||
- 5 type UserValidated = { user :: UserPublic.UserPublic }
|
||||
- 6 type UsersList = { users :: Array(UserPublic.UserPublic) }
|
||||
- 7 type PermissionCheck = { user :: Int32, service :: String, resource :: String, permission :: AuthD::User::PermissionLevel }
|
||||
- 8 type PermissionSet = { user :: Int32, service :: String, resource :: String, permission :: AuthD::User::PermissionLevel }
|
||||
|
@ -60,11 +56,16 @@ import App.IPC as IPC
|
|||
-}
|
||||
|
||||
-- Basic message types.
|
||||
-- TODO: note to myself: messages seem chaotic. Could be simpler. Should be simpler.
|
||||
type Error = { reason :: Maybe String }
|
||||
type Token = { uid :: Int, token :: String }
|
||||
type PasswordRecoverySent = { user :: UserPublic.UserPublic }
|
||||
type PasswordRecovered = { user :: UserPublic.UserPublic }
|
||||
type Contacts = { user :: Int, email :: Maybe Email.Email, phone :: Maybe Phone.Phone }
|
||||
type User = { user :: UserPublic.UserPublic }
|
||||
type UserAdded = { user :: UserPublic.UserPublic }
|
||||
type UserEdited = { uid :: Int }
|
||||
type UserValidated = { user :: UserPublic.UserPublic }
|
||||
|
||||
type Password = String
|
||||
type GetToken = { login :: String, password :: String }
|
||||
|
@ -79,10 +80,20 @@ codecGotToken ∷ CA.JsonCodec Token
|
|||
codecGotToken = CA.object "Token" (CAR.record { "uid": CA.int, "token": CA.string })
|
||||
codecGotPasswordRecoverySent ∷ CA.JsonCodec PasswordRecoverySent
|
||||
codecGotPasswordRecoverySent = CA.object "PasswordRecoverySent" (CAR.record { user: UserPublic.codec })
|
||||
codecGotUser ∷ CA.JsonCodec User
|
||||
codecGotUser = CA.object "User" (CAR.record { user: UserPublic.codec })
|
||||
codecGotUserAdded ∷ CA.JsonCodec UserAdded
|
||||
codecGotUserAdded = CA.object "UserAdded" (CAR.record { user: UserPublic.codec })
|
||||
codecGotUserEdited ∷ CA.JsonCodec UserEdited
|
||||
codecGotUserEdited = CA.object "UserEdited" (CAR.record { "uid": CA.int })
|
||||
codecGotUserValidated ∷ CA.JsonCodec UserValidated
|
||||
codecGotUserValidated = CA.object "UserValidated" (CAR.record { user: UserPublic.codec })
|
||||
codecGotPasswordRecovered ∷ CA.JsonCodec PasswordRecovered
|
||||
codecGotPasswordRecovered = CA.object "PasswordRecovered" (CAR.record { user: UserPublic.codec })
|
||||
codecGotContacts ∷ CA.JsonCodec Contacts
|
||||
codecGotContacts = CA.object "Contacts" (CAR.record { user: CA.int, email: CAR.optional Email.codec, phone: CAR.optional Phone.codec })
|
||||
codecGotContacts = CA.object "Contacts" (CAR.record { user: CA.int
|
||||
, email: CAR.optional Email.codec
|
||||
, phone: CAR.optional Phone.codec })
|
||||
|
||||
-- All possible requests.
|
||||
data RequestMessage
|
||||
|
@ -109,10 +120,10 @@ data RequestMessage
|
|||
data AnswerMessage
|
||||
= GotError Error -- 0
|
||||
| GotToken Token -- 1
|
||||
-- | GotUser User -- 2
|
||||
-- | GotUserAdded UserAdded -- 3
|
||||
-- | GotUserEdited UserEdited -- 4
|
||||
-- | GotUserValidated UserValidated -- 5
|
||||
| GotUser User -- 2
|
||||
| GotUserAdded UserAdded -- 3
|
||||
| GotUserEdited UserEdited -- 4
|
||||
| GotUserValidated UserValidated -- 5
|
||||
-- | GotUsersList UsersList -- 6
|
||||
-- | GotPermissionCheck PermissionCheck -- 7
|
||||
-- | GotPermissionSet PermissionSet -- 8
|
||||
|
@ -152,14 +163,14 @@ decode number string
|
|||
= case number of
|
||||
0 -> error_management codecGotError GotError
|
||||
1 -> error_management codecGotToken GotToken
|
||||
2 -> error_management codecGotUser GotUser
|
||||
3 -> error_management codecGotUserAdded GotUserAdded
|
||||
4 -> error_management codecGotUserEdited GotUserEdited
|
||||
5 -> error_management codecGotUserValidated GotUserValidated
|
||||
9 -> error_management codecGotPasswordRecoverySent GotPasswordRecoverySent
|
||||
10 -> error_management codecGotPasswordRecovered GotPasswordRecovered
|
||||
12 -> error_management codecGotContacts GotContacts
|
||||
_ -> Left UnknownNumber
|
||||
-- 2 type User = { user :: UserPublic.UserPublic }
|
||||
-- 3 type UserAdded = { user :: UserPublic.UserPublic }
|
||||
-- 4 type UserEdited = { uid :: Int32 }
|
||||
-- 5 type UserValidated = { user :: UserPublic.UserPublic }
|
||||
-- 6 type UsersList = { users :: Array(UserPublic.UserPublic) }
|
||||
-- 7 type PermissionCheck = { user :: Int32, service :: String, resource :: String, permission :: AuthD::User::PermissionLevel }
|
||||
-- 8 type PermissionSet = { user :: Int32, service :: String, resource :: String, permission :: AuthD::User::PermissionLevel }
|
||||
|
|
Loading…
Reference in New Issue