67 lines
2.2 KiB
Plaintext
67 lines
2.2 KiB
Plaintext
module App.Container where
|
|
|
|
import Prelude
|
|
|
|
import Bulma as Bulma
|
|
|
|
import Data.Maybe (Maybe(..))
|
|
import Data.Tuple (Tuple(..))
|
|
import App.AuthenticationForm as AF
|
|
import App.AuthenticationDaemonAdminInterface as AAI
|
|
import Halogen as H
|
|
import Halogen.HTML as HH
|
|
import Type.Proxy (Proxy(..))
|
|
import Effect.Aff.Class (class MonadAff)
|
|
|
|
data Action
|
|
= Authenticated AF.Output -- User has been authenticated.
|
|
|
|
type State = { token :: Maybe String, uid :: Maybe Int }
|
|
|
|
type ChildSlots =
|
|
( af :: AF.Slot Unit
|
|
, aai :: AAI.Slot Unit
|
|
)
|
|
|
|
_af = Proxy :: Proxy "af"
|
|
_aai = Proxy :: Proxy "aai"
|
|
|
|
component :: forall q i o m. MonadAff m => H.Component q i o m
|
|
component =
|
|
H.mkComponent
|
|
{ initialState
|
|
, render
|
|
, eval: H.mkEval $ H.defaultEval { handleAction = handleAction }
|
|
}
|
|
|
|
initialState :: forall i. i -> State
|
|
initialState _ = { token: Nothing, uid: Nothing }
|
|
|
|
render :: forall m. MonadAff m => State -> H.ComponentHTML Action ChildSlots m
|
|
render state
|
|
= HH.div_ $
|
|
[ render_auth_form
|
|
, render_authd_admin_interface
|
|
, div_token
|
|
]
|
|
where
|
|
div_token :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad
|
|
div_token = Bulma.box [ Bulma.p ("User [" <> show state.uid <> "] has token: " <> show state.token) ]
|
|
|
|
render_auth_form :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad
|
|
render_auth_form = Bulma.box $ case state.token of
|
|
Nothing -> [ HH.slot _af unit AF.component "ws://127.0.0.1:8081" Authenticated ]
|
|
Just current_token -> [ Bulma.p ("Token is: " <> current_token) ]
|
|
|
|
render_authd_admin_interface :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad
|
|
render_authd_admin_interface = Bulma.box $ case state.token of
|
|
Just _ ->
|
|
[ Bulma.h1 "Administrative interface for authd"
|
|
, HH.slot_ _aai unit AAI.component "ws://127.0.0.1:8081"
|
|
]
|
|
Nothing -> [ Bulma.p "Here will be the administrative box." ]
|
|
|
|
handleAction :: forall o monad. MonadAff monad => Action -> H.HalogenM State Action ChildSlots o monad Unit
|
|
handleAction = case _ of
|
|
Authenticated (AF.AuthToken (Tuple uid token)) -> H.modify_ _ { uid = Just uid, token = Just token }
|