Remove useless module.
parent
a51b943f84
commit
d668f297dc
|
@ -1,68 +0,0 @@
|
||||||
module App.Messages where
|
|
||||||
|
|
||||||
import Prelude
|
|
||||||
|
|
||||||
import Effect (Effect)
|
|
||||||
import Effect.Console (log)
|
|
||||||
|
|
||||||
import Data.Argonaut.Core as J
|
|
||||||
import Data.Codec.Argonaut as CA
|
|
||||||
import Data.Maybe
|
|
||||||
import Data.Either
|
|
||||||
import Data.Codec.Argonaut.Record as CAR
|
|
||||||
|
|
||||||
-- Base types.
|
|
||||||
type AuthDError = { reason :: Maybe String }
|
|
||||||
type AuthDToken = { uid :: Int, token :: String }
|
|
||||||
type AuthDContacts = { user :: Int, email :: Maybe String, phone :: Maybe String }
|
|
||||||
|
|
||||||
type Email = String
|
|
||||||
type Password = String
|
|
||||||
type Login = { email :: Email, password :: Password }
|
|
||||||
|
|
||||||
-- Their related JSON codecs.
|
|
||||||
authd_codec_error ∷ CA.JsonCodec AuthDError
|
|
||||||
authd_codec_error = CA.object "AuthDError" (CAR.record { reason: CAR.optional CA.string })
|
|
||||||
authd_codec_token ∷ CA.JsonCodec AuthDToken
|
|
||||||
authd_codec_token = CA.object "AuthDToken" (CAR.record { uid: CA.int, token: CA.string })
|
|
||||||
authd_codec_contacts ∷ CA.JsonCodec AuthDContacts
|
|
||||||
authd_codec_contacts = CA.object "AuthDContacts" (CAR.record { user: CA.int, email: CAR.optional CA.string, phone: CAR.optional CA.string })
|
|
||||||
codec_login ∷ CA.JsonCodec Login
|
|
||||||
codec_login = CA.object "Login" (CAR.record { email: CA.string, password: CA.string })
|
|
||||||
|
|
||||||
-- All possible requests.
|
|
||||||
data RequestMessage
|
|
||||||
= MessageLogin Login
|
|
||||||
|
|
||||||
-- All possible answers from the authentication daemon (authd).
|
|
||||||
data AuthDAnswerMessage
|
|
||||||
= AuthenticationDaemonError AuthDError
|
|
||||||
| Logged AuthDToken
|
|
||||||
| Contact AuthDContacts
|
|
||||||
|
|
||||||
encodeRequest ∷ RequestMessage → J.Json
|
|
||||||
encodeRequest m = case m of
|
|
||||||
(MessageLogin login) -> CA.encode codec_login login
|
|
||||||
|
|
||||||
-- TODO
|
|
||||||
--rawSerialize :: RequestMessage -> ArrayBuffer
|
|
||||||
--rawDeserialize :: ArrayBuffer -> AuthDAnswerMessage
|
|
||||||
|
|
||||||
data DecodeError
|
|
||||||
= JSONERROR CA.JsonDecodeError
|
|
||||||
| UnknownNumber
|
|
||||||
|
|
||||||
decodeAuthDAnswer :: Int -> J.Json -> Either DecodeError AuthDAnswerMessage
|
|
||||||
decodeAuthDAnswer number json
|
|
||||||
= case number of
|
|
||||||
0 -> error_management authd_codec_error AuthenticationDaemonError
|
|
||||||
10 -> error_management authd_codec_token Logged
|
|
||||||
12 -> error_management authd_codec_contacts Contact
|
|
||||||
_ -> Left UnknownNumber
|
|
||||||
where
|
|
||||||
-- Signature is required since the compiler's guess is wrong.
|
|
||||||
error_management :: forall a. CA.JsonCodec a -> (a -> AuthDAnswerMessage) -> Either DecodeError AuthDAnswerMessage
|
|
||||||
error_management codec f
|
|
||||||
= case (CA.decode codec json) of
|
|
||||||
(Left err) -> Left (JSONERROR err)
|
|
||||||
(Right v) -> Right (f v)
|
|
Loading…
Reference in New Issue