Minor changes (mostly comments).
parent
0d99e00e93
commit
ce57643cec
|
@ -23,6 +23,7 @@
|
|||
, "prelude"
|
||||
, "strings"
|
||||
, "transformers"
|
||||
, "tuples"
|
||||
, "uint"
|
||||
, "web-encoding"
|
||||
, "web-events"
|
||||
|
|
|
@ -13,7 +13,7 @@ module App.IPC (toIPC, fromIPC, toTypedIPC, fromTypedIPC) where
|
|||
Actual message formats can be found in the App.Messages folder.
|
||||
-}
|
||||
|
||||
import Prelude (bind, (<$>), discard, ($), (>>>))
|
||||
import Prelude (bind, (<$>), discard, ($), (>>>), (+))
|
||||
|
||||
import Effect (Effect)
|
||||
import Effect.Class (liftEffect)
|
||||
|
@ -64,7 +64,7 @@ toTypedIPC n s = Builder.execPutM do
|
|||
textEncoder <- liftEffect TextEncoder.new
|
||||
let stringbuf = Typed.buffer $ TextEncoder.encode s textEncoder
|
||||
-- Put a 32-bit big-endian length for the utf8 string, in bytes.
|
||||
Builder.putUint32be $ fromInt $ ArrayBuffer.byteLength stringbuf
|
||||
Builder.putUint32be $ fromInt $ (ArrayBuffer.byteLength stringbuf) + 1 -- 1 for message type
|
||||
Builder.putUint8 n
|
||||
Builder.putArrayBuffer stringbuf
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module App.Messages where
|
||||
module App.Messages.AuthenticationDaemon where
|
||||
|
||||
import Prelude
|
||||
|
||||
|
@ -11,34 +11,37 @@ import Data.Maybe
|
|||
import Data.Either
|
||||
import Data.Codec.Argonaut.Record as CAR
|
||||
|
||||
import App.IPC (toTypedIPC, fromTypedIPC)
|
||||
|
||||
{- TODO:
|
||||
|
||||
Possible requests:
|
||||
- 0 type GetToken = { login :: String, password :: String }
|
||||
- 1 type AddUser = { shared_key :: String, login :: String, password :: String, email :: String?, phone :: String?, profile :: Hash(String, JSON::Any)? }
|
||||
- 2 type ValidateUser = { login :: String, activation_key :: String }
|
||||
- 3 type GetUser = { user :: Int32 | String }
|
||||
- 4 type GetUserByCredentials = { login :: String, password :: String }
|
||||
- 6 type Register = { login :: String, password :: String, email :: String?, phone :: String? , profile :: Hash(String, JSON::Any)? }
|
||||
- 7 type UpdatePassword = { login :: String, old_password :: String, new_password :: String }
|
||||
- 8 type ListUsers = { token :: String?, key :: String? }
|
||||
- 9 type CheckPermission = { shared_key :: String?, token :: String?, user :: Int32 | String, service :: String, resource :: String }
|
||||
- 10 type SetPermission = { shared_key :: String, user :: Int32 | String, service :: String, resource :: String, permission :: ::AuthD::User::PermissionLevel }
|
||||
- 11 type PasswordRecovery = { user :: Int32 | String, password_renew_key :: String, new_password :: String }
|
||||
- 12 type AskPasswordRecovery = { user :: Int32 | String, email :: String }
|
||||
- 13 type SearchUser = { user :: String }
|
||||
- 14 type EditProfile = { token :: String, new_profile :: Hash(String, JSON::Any) }
|
||||
- 15 type EditProfileContent = { token :: String?, shared_key :: String?, user :: Int32 | String | Nil, new_profile :: Hash(String, JSON::Any) }
|
||||
- 16 type EditContacts = { token :: String, email :: String?, phone :: String? }
|
||||
- 17 type Delete = { shared_key :: String?, login :: String?, password :: String?, user :: String | Int32 }
|
||||
- 18 type GetContacts = { token :: String }
|
||||
Possible requests:
|
||||
- 0 type GetToken = { login :: String, password :: String }
|
||||
- 1 type AddUser = { shared_key :: String, login :: String, password :: String, email :: Maybe String, phone :: Maybe String, profile :: Maybe Hash(String, JSON::Any) }
|
||||
- 2 type ValidateUser = { login :: String, activation_key :: String }
|
||||
- 3 type GetUser = { user :: Int32 | String }
|
||||
- 4 type GetUserByCredentials = { login :: String, password :: String }
|
||||
- 6 type Register = { login :: String, password :: String, email :: Maybe String, phone :: Maybe String , profile :: Maybe Hash(String, JSON::Any) }
|
||||
- 7 type UpdatePassword = { login :: String, old_password :: String, new_password :: String }
|
||||
- 8 type ListUsers = { token :: Maybe String, key :: Maybe String }
|
||||
- 9 type CheckPermission = { shared_key :: Maybe String, token :: Maybe String, user :: Int32 | String, service :: String, resource :: String }
|
||||
- 10 type SetPermission = { shared_key :: String, user :: Int32 | String, service :: String, resource :: String, permission :: ::AuthD::User::PermissionLevel }
|
||||
- 11 type PasswordRecovery = { user :: Int32 | String, password_renew_key :: String, new_password :: String }
|
||||
- 12 type AskPasswordRecovery = { user :: Int32 | String, email :: String }
|
||||
- 13 type SearchUser = { user :: String }
|
||||
- 14 type EditProfile = { token :: String, new_profile :: Hash(String, JSON::Any) }
|
||||
- 15 type EditProfileContent = { token :: Maybe String, shared_key :: Maybe String, user :: Int32 | String | Nil, new_profile :: Hash(String, JSON::Any) }
|
||||
- 16 type EditContacts = { token :: String, email :: Maybe String, phone :: Maybe String }
|
||||
- 17 type Delete = { shared_key :: Maybe String, login :: Maybe String, password :: Maybe String, user :: String | Int32 }
|
||||
- 18 type GetContacts = { token :: String }
|
||||
|
||||
-- Deletion can be triggered by either an admin or the user.
|
||||
|
||||
Possible answers:
|
||||
- PasswordRecoverySent and PasswordRecovered,
|
||||
- PermissionCheck and PermissionSet,
|
||||
- User, UserAdded, UserEdited, UserValidated, UsersList, MatchingUsers
|
||||
Possible answers:
|
||||
- PasswordRecoverySent and PasswordRecovered,
|
||||
- PermissionCheck and PermissionSet,
|
||||
- User, UserAdded, UserEdited, UserValidated, UsersList, MatchingUsers
|
||||
|
||||
-}
|
||||
|
||||
-- Basic message types.
|
||||
|
@ -48,11 +51,28 @@ type Contacts = { user :: Int, email :: Maybe String, phone :: Maybe String }
|
|||
|
||||
type Email = String
|
||||
type Password = String
|
||||
type Login = { email :: Email, password :: Password }
|
||||
type GetToken = { login :: String, password :: String }
|
||||
|
||||
-- All possible requests.
|
||||
data RequestMessage
|
||||
= MessageLogin Login
|
||||
= MkGetToken GetToken -- 0 GetToken
|
||||
-- 1 AddUser
|
||||
-- 2 ValidateUser
|
||||
-- 3 GetUser
|
||||
-- 4 GetUserByCredentials
|
||||
-- 6 Register
|
||||
-- 7 UpdatePassword
|
||||
-- 8 ListUsers
|
||||
-- 9 CheckPermission
|
||||
-- 10 SetPermission
|
||||
-- 11 PasswordRecovery
|
||||
-- 12 AskPasswordRecovery
|
||||
-- 13 SearchUser
|
||||
-- 14 EditProfile
|
||||
-- 15 EditProfileContent
|
||||
-- 16 EditContacts
|
||||
-- 17 Delete
|
||||
-- 18 GetContacts
|
||||
|
||||
-- All possible answers from the authentication daemon (authd).
|
||||
data AnswerMessage
|
||||
|
@ -62,7 +82,7 @@ data AnswerMessage
|
|||
|
||||
encode ∷ RequestMessage → J.Json
|
||||
encode m = case m of
|
||||
(MessageLogin login) -> CA.encode codec_login login
|
||||
(MkGetToken token) -> CA.encode codec_token token
|
||||
-- 0 GetToken
|
||||
-- 1 AddUser
|
||||
-- 2 ValidateUser
|
||||
|
@ -82,6 +102,10 @@ encode m = case m of
|
|||
-- 17 Delete
|
||||
-- 18 GetContacts
|
||||
|
||||
where
|
||||
codec_token ∷ CA.JsonCodec GetToken
|
||||
codec_token = CA.object "GetToken" (CAR.record { login: CA.string, password: CA.string })
|
||||
|
||||
data DecodeError
|
||||
= JSONERROR CA.JsonDecodeError
|
||||
| UnknownNumber
|
||||
|
@ -109,9 +133,9 @@ decode number json
|
|||
codec_contacts ∷ CA.JsonCodec Contacts
|
||||
codec_contacts = CA.object "Contacts" (CAR.record { user: CA.int, email: CAR.optional CA.string, phone: CAR.optional CA.string })
|
||||
|
||||
-- login_serialize :: Login -> String
|
||||
-- login_serialize :: GetToken -> String
|
||||
-- login_serialize = J.stringify <<< login_encode
|
||||
-- login_decode ∷ J.Json → Either CA.JsonDecodeError Login
|
||||
-- login_decode ∷ J.Json → Either CA.JsonDecodeError GetToken
|
||||
-- login_decode = CA.decode codec_login
|
||||
--
|
||||
-- example_login_deserialize :: J.Json -> Effect Unit
|
||||
|
|
Loading…
Reference in New Issue