Revert to old page when reloading without being logged, clean logs.
This commit is contained in:
parent
041546279e
commit
de039e5e6c
@ -93,8 +93,10 @@ type Password = String
|
||||
type LogInfo = Tuple Login Password
|
||||
|
||||
data Action
|
||||
= Initialize
|
||||
|
||||
-- | Handle events from `AuthenticationInterface`.
|
||||
= AuthenticationInterfaceEvent AI.Output
|
||||
| AuthenticationInterfaceEvent AI.Output
|
||||
|
||||
-- | Handle events from `RegistrationInterface`.
|
||||
| RegistrationInterfaceEvent RI.Output
|
||||
@ -209,7 +211,9 @@ component =
|
||||
H.mkComponent
|
||||
{ initialState
|
||||
, render
|
||||
, eval: H.mkEval $ H.defaultEval { handleAction = handleAction }
|
||||
, eval: H.mkEval $ H.defaultEval { initialize = Just Initialize
|
||||
, handleAction = handleAction
|
||||
}
|
||||
}
|
||||
|
||||
-- | Initial state is simple: the user is on the home page, nothing else is stored.
|
||||
@ -287,6 +291,14 @@ render state
|
||||
|
||||
handleAction :: forall o monad. MonadAff monad => Action -> H.HalogenM State Action ChildSlots o monad Unit
|
||||
handleAction = case _ of
|
||||
Initialize -> do
|
||||
handleAction $ Log $ SystemLog "Hello, welcome to this application! 🥳"
|
||||
sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window
|
||||
token <- H.liftEffect $ Storage.getItem "user-authd-token" sessionstorage
|
||||
case token of
|
||||
Nothing -> revert_old_page
|
||||
Just _ -> pure unit -- Authentication will happen when web sockets are up!
|
||||
|
||||
Routing page -> do
|
||||
-- Store the current page we are on and restore it when we reload.
|
||||
sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window
|
||||
@ -335,7 +347,7 @@ handleAction = case _ of
|
||||
sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window
|
||||
token <- H.liftEffect $ Storage.getItem "user-authd-token" sessionstorage
|
||||
case token of
|
||||
Nothing -> handleAction $ Log $ ErrorLog "no token!"
|
||||
Nothing -> pure unit
|
||||
Just t -> do
|
||||
H.modify_ _ { token = Just t }
|
||||
handleAction AuthenticateToDNSManager
|
||||
@ -442,7 +454,7 @@ handleAction = case _ of
|
||||
sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window
|
||||
token <- H.liftEffect $ Storage.getItem "user-authd-token" sessionstorage
|
||||
case token of
|
||||
Nothing -> handleAction $ Log $ ErrorLog "no token!"
|
||||
Nothing -> pure unit
|
||||
Just t -> do
|
||||
handleAction $ Log $ SystemLog "Let's authenticate to authd"
|
||||
handleAction $ AuthenticateToAuthd (Left t)
|
||||
@ -587,7 +599,6 @@ handleAction = case _ of
|
||||
WS.MessageReceived (Tuple _ message) -> do
|
||||
handleAction $ DecodeDNSMessage message
|
||||
WS.WSJustConnected -> do
|
||||
handleAction $ Log $ SystemLog "Connection with dnsmanagerd was closed, let's re-authenticate"
|
||||
handleAction AuthenticateToDNSManager
|
||||
H.tell _dli unit DomainListInterface.ConnectionIsUp
|
||||
WS.WSJustClosed -> H.tell _dli unit DomainListInterface.ConnectionIsDown
|
||||
|
@ -2,7 +2,7 @@
|
||||
-- | TODO: token validation.
|
||||
module App.Page.Authentication where
|
||||
|
||||
import Prelude (Unit, bind, discard, pure, ($), (<<<), (=<<), (<>), (>), (==), map, show)
|
||||
import Prelude (Unit, bind, discard, pure, ($), (<<<), (=<<), (<>), (>), (==), map, show, unit)
|
||||
|
||||
import Data.Array as A
|
||||
import Data.ArrayBuffer.Types (ArrayBuffer)
|
||||
@ -289,7 +289,7 @@ handleAction = case _ of
|
||||
sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window
|
||||
old_tab <- H.liftEffect $ Storage.getItem "current-auth-tab" sessionstorage
|
||||
case old_tab of
|
||||
Nothing -> H.raise $ Log $ ErrorLog "We hadn't changed tab before reload apparently."
|
||||
Nothing -> pure unit
|
||||
Just current_tab -> case current_tab of
|
||||
"Auth" -> handleAction $ ChangeTab Auth
|
||||
"TabPasswordRecovery" -> handleAction $ ChangeTab TabPasswordRecovery
|
||||
|
Loading…
Reference in New Issue
Block a user