Password recovery (draft).

This commit is contained in:
Philippe Pittoli 2023-07-15 19:44:41 +02:00
parent b059b42bfc
commit c168c36dd0

View File

@ -53,19 +53,27 @@ data RegisterInput
| REG_INP_email String
| REG_INP_pass String
data PasswordRecoveryInput
= PASSR_INP_login String
| PASSR_INP_email String
data Action
= HandleAuthenticationInput AuthenticationInput
| HandleRegisterInput RegisterInput
| HandlePasswordRecovery PasswordRecoveryInput
--
| AuthenticationAttempt Event
| RegisterAttempt Event
| PasswordRecoveryAttempt Event
type StateAuthenticationForm = { login :: String, pass :: String }
type StateRegistrationForm = { login :: String, email :: String, pass :: String }
type StatePasswordRecoveryForm = { login :: String, email :: String }
type State =
{ authenticationForm :: StateAuthenticationForm
, registrationForm :: StateRegistrationForm
, passwordRecoveryForm :: StatePasswordRecoveryForm
, wsUp :: Boolean
}
@ -84,28 +92,25 @@ initialState :: Input -> State
initialState _ =
{ authenticationForm: { login: "", pass: "" }
, registrationForm: { login: "", email: "", pass: "" }
, passwordRecoveryForm: { login: "", email: "" }
, wsUp: true
}
render :: forall m. State -> H.ComponentHTML Action () m
render { wsUp, authenticationForm, registrationForm }
render { wsUp, authenticationForm, registrationForm, passwordRecoveryForm}
= Bulma.section_small
[ case wsUp of
false -> Bulma.p "You are disconnected."
true -> Bulma.columns_ [ Bulma.column_ auth_form, Bulma.column_ register_form ]
true -> Bulma.columns_ [ b auth_form, b register_form, b passrecovery_form ]
]
where
b e = Bulma.column_ [ Bulma.box e ]
auth_form
= [ Bulma.h3 "Authentication"
, render_auth_form
]
register_form
= [ Bulma.h3 "Register!"
, render_register_form
]
auth_form = [ Bulma.h3 "Authentication" , render_auth_form ]
register_form = [ Bulma.h3 "Register!" , render_register_form ]
passrecovery_form = [ Bulma.h3 "Password Recovery", render_password_recovery_form ]
should_be_disabled = (if wsUp then (HP.enabled true) else (HP.disabled true))
@ -156,6 +161,26 @@ render { wsUp, authenticationForm, registrationForm }
]
]
render_password_recovery_form = HH.form
[ HE.onSubmit PasswordRecoveryAttempt ]
[ Bulma.box_input "loginPASSR" "Login" "login" -- title, placeholder
(HandlePasswordRecovery <<< PASSR_INP_login) -- action
passwordRecoveryForm.login -- value
true -- validity (TODO)
should_be_disabled -- condition
, Bulma.box_input "emailPASSR" "Email" "email" -- title, placeholder
(HandlePasswordRecovery <<< PASSR_INP_email) -- action
passwordRecoveryForm.login -- value
true -- validity (TODO)
should_be_disabled -- condition
, HH.button
[ HP.style "padding: 0.5rem 1.25rem;"
, HP.type_ HP.ButtonSubmit
, (if wsUp then (HP.enabled true) else (HP.disabled true))
]
[ HH.text "Send Message to Server" ]
]
handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit
handleAction = case _ of
HandleAuthenticationInput authinp -> do
@ -169,6 +194,11 @@ handleAction = case _ of
REG_INP_email v -> H.modify_ _ { registrationForm { email = v } }
REG_INP_pass v -> H.modify_ _ { registrationForm { pass = v } }
HandlePasswordRecovery authinp -> do
case authinp of
PASSR_INP_login v -> H.modify_ _ { passwordRecoveryForm { login = v } }
PASSR_INP_email v -> H.modify_ _ { passwordRecoveryForm { email = v } }
RegisterAttempt ev -> do
H.liftEffect $ Event.preventDefault ev
@ -212,6 +242,23 @@ handleAction = case _ of
H.raise $ MessageToSend message
H.raise $ Log $ SimpleLog $ "[😇] Trying to authenticate (login: " <> login <> ")"
PasswordRecoveryAttempt ev -> do
H.liftEffect $ Event.preventDefault ev
{ registrationForm } <- H.get
let login = registrationForm.login
email = registrationForm.email
case login, email of
"", "" ->
H.raise $ Log $ UnableToSend "Write at least either your login or your email!"
_, _ -> do
H.raise $ Log $ UnableToSend "Currently not implemented."
--message <- H.liftEffect $ AuthD.serialize $
-- AuthD.Mk { login: (Just login), email: Just (Email.Email email) }
--H.raise $ MessageToSend message
handleQuery :: forall a m. MonadAff m => Query a -> H.HalogenM State Action () Output m (Maybe a)
handleQuery = case _ of
MessageReceived message a -> do