Decode a few other message types.

This commit is contained in:
Philippe Pittoli 2023-05-27 00:58:18 +02:00
parent e80b71c0cd
commit d17e29c1f5

View File

@ -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.
type Error = { reason :: Maybe String }
type Token = { uid :: Int, token :: String }
-- 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 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
@ -107,12 +118,12 @@ data RequestMessage
-- All possible answers from the authentication daemon (authd).
data AnswerMessage
= GotError Error -- 0
| GotToken Token -- 1
-- | GotUser User -- 2
-- | GotUserAdded UserAdded -- 3
-- | GotUserEdited UserEdited -- 4
-- | GotUserValidated UserValidated -- 5
= GotError Error -- 0
| GotToken Token -- 1
| GotUser User -- 2
| GotUserAdded UserAdded -- 3
| GotUserEdited UserEdited -- 4
| GotUserValidated UserValidated -- 5
-- | GotUsersList UsersList -- 6
-- | GotPermissionCheck PermissionCheck -- 7
-- | GotPermissionSet PermissionSet -- 8
@ -150,16 +161,16 @@ data DecodeError
decode :: Int -> String -> Either DecodeError AnswerMessage
decode number string
= case number of
0 -> error_management codecGotError GotError
1 -> error_management codecGotToken GotToken
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
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 }