Revert to old page when reloading without being logged, clean logs.

This commit is contained in:
Philippe Pittoli 2024-03-21 01:59:27 +01:00
parent 041546279e
commit de039e5e6c
2 changed files with 18 additions and 7 deletions

View File

@ -93,8 +93,10 @@ type Password = String
type LogInfo = Tuple Login Password type LogInfo = Tuple Login Password
data Action data Action
= Initialize
-- | Handle events from `AuthenticationInterface`. -- | Handle events from `AuthenticationInterface`.
= AuthenticationInterfaceEvent AI.Output | AuthenticationInterfaceEvent AI.Output
-- | Handle events from `RegistrationInterface`. -- | Handle events from `RegistrationInterface`.
| RegistrationInterfaceEvent RI.Output | RegistrationInterfaceEvent RI.Output
@ -209,7 +211,9 @@ component =
H.mkComponent H.mkComponent
{ initialState { initialState
, render , 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. -- | 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 :: forall o monad. MonadAff monad => Action -> H.HalogenM State Action ChildSlots o monad Unit
handleAction = case _ of 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 Routing page -> do
-- Store the current page we are on and restore it when we reload. -- Store the current page we are on and restore it when we reload.
sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window
@ -335,7 +347,7 @@ handleAction = case _ of
sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window
token <- H.liftEffect $ Storage.getItem "user-authd-token" sessionstorage token <- H.liftEffect $ Storage.getItem "user-authd-token" sessionstorage
case token of case token of
Nothing -> handleAction $ Log $ ErrorLog "no token!" Nothing -> pure unit
Just t -> do Just t -> do
H.modify_ _ { token = Just t } H.modify_ _ { token = Just t }
handleAction AuthenticateToDNSManager handleAction AuthenticateToDNSManager
@ -442,7 +454,7 @@ handleAction = case _ of
sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window
token <- H.liftEffect $ Storage.getItem "user-authd-token" sessionstorage token <- H.liftEffect $ Storage.getItem "user-authd-token" sessionstorage
case token of case token of
Nothing -> handleAction $ Log $ ErrorLog "no token!" Nothing -> pure unit
Just t -> do Just t -> do
handleAction $ Log $ SystemLog "Let's authenticate to authd" handleAction $ Log $ SystemLog "Let's authenticate to authd"
handleAction $ AuthenticateToAuthd (Left t) handleAction $ AuthenticateToAuthd (Left t)
@ -587,7 +599,6 @@ handleAction = case _ of
WS.MessageReceived (Tuple _ message) -> do WS.MessageReceived (Tuple _ message) -> do
handleAction $ DecodeDNSMessage message handleAction $ DecodeDNSMessage message
WS.WSJustConnected -> do WS.WSJustConnected -> do
handleAction $ Log $ SystemLog "Connection with dnsmanagerd was closed, let's re-authenticate"
handleAction AuthenticateToDNSManager handleAction AuthenticateToDNSManager
H.tell _dli unit DomainListInterface.ConnectionIsUp H.tell _dli unit DomainListInterface.ConnectionIsUp
WS.WSJustClosed -> H.tell _dli unit DomainListInterface.ConnectionIsDown WS.WSJustClosed -> H.tell _dli unit DomainListInterface.ConnectionIsDown

View File

@ -2,7 +2,7 @@
-- | TODO: token validation. -- | TODO: token validation.
module App.Page.Authentication where 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.Array as A
import Data.ArrayBuffer.Types (ArrayBuffer) import Data.ArrayBuffer.Types (ArrayBuffer)
@ -289,7 +289,7 @@ handleAction = case _ of
sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window sessionstorage <- H.liftEffect $ Window.sessionStorage =<< HTML.window
old_tab <- H.liftEffect $ Storage.getItem "current-auth-tab" sessionstorage old_tab <- H.liftEffect $ Storage.getItem "current-auth-tab" sessionstorage
case old_tab of 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 Just current_tab -> case current_tab of
"Auth" -> handleAction $ ChangeTab Auth "Auth" -> handleAction $ ChangeTab Auth
"TabPasswordRecovery" -> handleAction $ ChangeTab TabPasswordRecovery "TabPasswordRecovery" -> handleAction $ ChangeTab TabPasswordRecovery