Successful authentication removes authentication form rendering.
parent
361558f9f1
commit
dc523d0c5f
|
@ -324,6 +324,7 @@ handleAction = case _ of
|
||||||
handleAction $ WebSocketParseError ("JSON parsing error: " <> jerr <> " JSON is: " <> jerr)
|
handleAction $ WebSocketParseError ("JSON parsing error: " <> jerr <> " JSON is: " <> jerr)
|
||||||
(AuthD.UnknownError unerr) -> handleAction $ WebSocketParseError ("Parsing error: AuthD.UnknownError" <> (show unerr))
|
(AuthD.UnknownError unerr) -> handleAction $ WebSocketParseError ("Parsing error: AuthD.UnknownError" <> (show unerr))
|
||||||
(AuthD.UnknownNumber ) -> handleAction $ WebSocketParseError ("Parsing error: AuthD.UnknownNumber")
|
(AuthD.UnknownNumber ) -> handleAction $ WebSocketParseError ("Parsing error: AuthD.UnknownNumber")
|
||||||
|
|
||||||
-- Cases where we understood the message.
|
-- Cases where we understood the message.
|
||||||
Right response -> do
|
Right response -> do
|
||||||
case response of
|
case response of
|
||||||
|
@ -331,8 +332,9 @@ handleAction = case _ of
|
||||||
(AuthD.GotError _) -> do
|
(AuthD.GotError _) -> do
|
||||||
appendMessage $ "[😈] Failed! (TODO: put the reason)"
|
appendMessage $ "[😈] Failed! (TODO: put the reason)"
|
||||||
-- The authentication was a success!
|
-- The authentication was a success!
|
||||||
(AuthD.GotToken msg) ->
|
(AuthD.GotToken msg) -> do
|
||||||
appendMessage $ "[😈] Success! user " <> (show msg.uid) <> " has token: " <> msg.token
|
appendMessage $ "[😈] Success! user " <> (show msg.uid) <> " has token: " <> msg.token
|
||||||
|
H.raise $ AuthToken msg.token
|
||||||
-- WTH?!
|
-- WTH?!
|
||||||
_ -> do
|
_ -> do
|
||||||
appendMessage $ "[😈] Failed! Don't understand the answer received!"
|
appendMessage $ "[😈] Failed! Don't understand the answer received!"
|
||||||
|
|
|
@ -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 :: forall m. MonadAff m => State -> H.ComponentHTML Action ChildSlots m
|
||||||
render state = HH.div_ $
|
render state = HH.div_ $
|
||||||
[ HH.div
|
[ render_auth_form
|
||||||
[ HP.class_ (H.ClassName "box") ]
|
, div_token
|
||||||
[ HH.h1_ [ HH.text "Component A" ]
|
, render_original_interface
|
||||||
, HH.slot_ _a unit CA.component unit
|
--, useless_stuff
|
||||||
]
|
|
||||||
, 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"
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
where
|
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
|
render_auth_form = case state.token of
|
||||||
Nothing -> HH.div
|
Nothing -> HH.div
|
||||||
[ HP.class_ (H.ClassName "box") ]
|
[ HP.class_ (H.ClassName "box") ]
|
||||||
[ HH.h1_ [ HH.text "Authentication form" ]
|
[ 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
|
Just current_token -> HH.div
|
||||||
[ HP.class_ (H.ClassName "box") ]
|
[ HP.class_ (H.ClassName "box") ]
|
||||||
[ HH.p_ [ HH.text ("Token is: " <> current_token) ] ]
|
[ 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
|
handleAction = case _ of
|
||||||
Authenticated authaction -> case authaction of
|
Authenticated authaction -> case authaction of
|
||||||
AF.AuthToken newtoken -> do
|
AF.AuthToken newtoken -> do
|
||||||
|
|
Loading…
Reference in New Issue