From dc523d0c5fd561149fa8ffa292884122178d84e6 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Fri, 2 Jun 2023 00:10:08 +0200 Subject: [PATCH] Successful authentication removes authentication form rendering. --- src/App/AuthenticationForm.purs | 4 +- src/App/Container.purs | 84 ++++++++++++++++++++------------- 2 files changed, 53 insertions(+), 35 deletions(-) diff --git a/src/App/AuthenticationForm.purs b/src/App/AuthenticationForm.purs index 5558fd1..0c96fe1 100644 --- a/src/App/AuthenticationForm.purs +++ b/src/App/AuthenticationForm.purs @@ -324,6 +324,7 @@ handleAction = case _ of handleAction $ WebSocketParseError ("JSON parsing error: " <> jerr <> " JSON is: " <> jerr) (AuthD.UnknownError unerr) -> handleAction $ WebSocketParseError ("Parsing error: AuthD.UnknownError" <> (show unerr)) (AuthD.UnknownNumber ) -> handleAction $ WebSocketParseError ("Parsing error: AuthD.UnknownNumber") + -- Cases where we understood the message. Right response -> do case response of @@ -331,8 +332,9 @@ handleAction = case _ of (AuthD.GotError _) -> do appendMessage $ "[😈] Failed! (TODO: put the reason)" -- The authentication was a success! - (AuthD.GotToken msg) -> + (AuthD.GotToken msg) -> do appendMessage $ "[😈] Success! user " <> (show msg.uid) <> " has token: " <> msg.token + H.raise $ AuthToken msg.token -- WTH?! _ -> do appendMessage $ "[😈] Failed! Don't understand the answer received!" diff --git a/src/App/Container.purs b/src/App/Container.purs index 19a5d57..52d63a2 100644 --- a/src/App/Container.purs +++ b/src/App/Container.purs @@ -51,51 +51,67 @@ initialState _ = { a: Nothing, b: Nothing, c: Nothing, token: Nothing } render :: forall m. MonadAff m => State -> H.ComponentHTML Action ChildSlots m render state = HH.div_ $ - [ HH.div - [ HP.class_ (H.ClassName "box") ] - [ HH.h1_ [ HH.text "Component A" ] - , HH.slot_ _a unit CA.component unit - ] - , HH.div - [ HP.class_ (H.ClassName "box") ] - [ HH.h1_ [ HH.text "Component B" ] - , HH.slot_ _b unit CB.component unit - ] - , HH.div - [ HP.class_ (H.ClassName "box") ] - [ HH.h1_ [ HH.text "Component C" ] - , HH.slot_ _c unit CC.component unit - ] - , HH.p_ - [ HH.text "Last observed states:" ] - , HH.ul_ - [ HH.li_ [ HH.text ("Component A: " <> show state.a) ] - , HH.li_ [ HH.text ("Component B: " <> show state.b) ] - , HH.li_ [ HH.text ("Component C: " <> show state.c) ] - ] - , HH.button - [ HE.onClick \_ -> ReadStates ] - [ HH.text "Check states now" ] - ] <> [ render_auth_form ] <> - [ HH.div - [ HP.class_ (H.ClassName "box") ] - [ HH.h1_ [ HH.text "Original interface" ] - , HH.slot_ _oi unit OI.component "ws://127.0.0.1:8080" - ] + [ render_auth_form + , div_token + , render_original_interface + --, useless_stuff ] where - render_auth_form :: forall m. MonadAff m => H.ComponentHTML Action ChildSlots m + div_token :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad + div_token = + HH.div_ [ + HH.p_ [ HH.text ("Token is: " <> show state.token) ] + ] + + render_auth_form :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad render_auth_form = case state.token of Nothing -> HH.div [ HP.class_ (H.ClassName "box") ] [ HH.h1_ [ HH.text "Authentication form" ] - , HH.slot_ _af unit AF.component "ws://127.0.0.1:8081" + , HH.slot _af unit AF.component "ws://127.0.0.1:8081" Authenticated ] Just current_token -> HH.div [ HP.class_ (H.ClassName "box") ] [ HH.p_ [ HH.text ("Token is: " <> current_token) ] ] -handleAction :: forall o m. MonadAff m => Action -> H.HalogenM State Action ChildSlots o m Unit + render_original_interface = + HH.div + [ HP.class_ (H.ClassName "box") ] + [ HH.h1_ [ HH.text "Original interface" ] + , HH.slot_ _oi unit OI.component "ws://127.0.0.1:8080" + ] + + -- useless_stuff :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad + -- useless_stuff = + -- HH.div_ [ + -- HH.div + -- [ HP.class_ (H.ClassName "box") ] + -- [ HH.h1_ [ HH.text "Component A" ] + -- , HH.slot_ _a unit CA.component unit + -- ] + -- , HH.div + -- [ HP.class_ (H.ClassName "box") ] + -- [ HH.h1_ [ HH.text "Component B" ] + -- , HH.slot_ _b unit CB.component unit + -- ] + -- , HH.div + -- [ HP.class_ (H.ClassName "box") ] + -- [ HH.h1_ [ HH.text "Component C" ] + -- , HH.slot_ _c unit CC.component unit + -- ] + -- , HH.p_ + -- [ HH.text "Last observed states:" ] + -- , HH.ul_ + -- [ HH.li_ [ HH.text ("Component A: " <> show state.a) ] + -- , HH.li_ [ HH.text ("Component B: " <> show state.b) ] + -- , HH.li_ [ HH.text ("Component C: " <> show state.c) ] + -- ] + -- , HH.button + -- [ HE.onClick \_ -> ReadStates ] + -- [ HH.text "Check states now" ] + -- ] + +handleAction :: forall o monad. MonadAff monad => Action -> H.HalogenM State Action ChildSlots o monad Unit handleAction = case _ of Authenticated authaction -> case authaction of AF.AuthToken newtoken -> do