Setup: verify the password.

This commit is contained in:
Philippe Pittoli 2024-03-25 00:31:09 +01:00
parent ac4f8469ce
commit 044578a501

View File

@ -2,9 +2,11 @@
-- | Users can also erase their account. -- | Users can also erase their account.
module App.Page.Setup where module App.Page.Setup where
import Prelude (Unit, bind, discard, pure, ($), (<<<), (==)) import Prelude (Unit, bind, discard, pure, ($), (<<<), (==), (<>), show, map)
import Data.Maybe (Maybe(..)) import Data.Array as A
import Data.Maybe (Maybe(..), maybe)
import Data.Either (Either(..))
import Effect.Aff.Class (class MonadAff) import Effect.Aff.Class (class MonadAff)
import Halogen as H import Halogen as H
import Halogen.HTML as HH import Halogen.HTML as HH
@ -15,6 +17,8 @@ import Web.Event.Event (Event)
import Bulma as Bulma import Bulma as Bulma
import App.Validation.Password as P
import App.Type.LogMessage import App.Type.LogMessage
import App.Message.AuthenticationDaemon as AuthD import App.Message.AuthenticationDaemon as AuthD
@ -46,6 +50,7 @@ data NewPasswordInput
data Action data Action
= HandleNewPassword NewPasswordInput = HandleNewPassword NewPasswordInput
| ChangePasswordAttempt Event | ChangePasswordAttempt Event
| SendChangePasswordMessage
| CancelModal | CancelModal
| DeleteAccountPopup | DeleteAccountPopup
| DeleteAccount | DeleteAccount
@ -142,10 +147,31 @@ handleAction = case _ of
_ , "" -> H.raise $ Log $ UnableToSend "Confirm your password!" _ , "" -> H.raise $ Log $ UnableToSend "Confirm your password!"
pass, confirmation -> do pass, confirmation -> do
if pass == confirmation if pass == confirmation
then do H.raise $ Log $ SystemLog "Changing the password" then case P.password pass of
H.raise $ ChangePassword pass Left errors -> H.raise $ Log $ UnableToSend $ A.fold $ map show_error_password errors
Right _ -> handleAction SendChangePasswordMessage
else H.raise $ Log $ UnableToSend "Confirmation differs from password" else H.raise $ Log $ UnableToSend "Confirmation differs from password"
SendChangePasswordMessage -> do
state <- H.get
H.raise $ Log $ SystemLog "Changing the password"
H.raise $ ChangePassword state.newPasswordForm.password
where
show_error_password :: P.Error -> String
show_error_password = case _ of
P.ParsingError {error, position} ->
"position " <> show position <> " " <> maybe "" string_error_password error
string_error_password :: P.PasswordParsingError -> String
string_error_password = case _ of
P.CannotParse -> "cannot parse the password"
P.CannotEntirelyParse -> "cannot entirely parse the password"
P.Size min max n -> "password size should be between "
<> show min <> " and " <> show max
<> " (currently: " <> show n <> ")"
handleQuery :: forall a m. MonadAff m => Query a -> H.HalogenM State Action () Output m (Maybe a) handleQuery :: forall a m. MonadAff m => Query a -> H.HalogenM State Action () Output m (Maybe a)
handleQuery = case _ of handleQuery = case _ of
-- For now, no message actually needs to be handled here. -- For now, no message actually needs to be handled here.