Password recovery (draft).
This commit is contained in:
parent
b059b42bfc
commit
c168c36dd0
@ -53,19 +53,27 @@ data RegisterInput
|
|||||||
| REG_INP_email String
|
| REG_INP_email String
|
||||||
| REG_INP_pass String
|
| REG_INP_pass String
|
||||||
|
|
||||||
|
data PasswordRecoveryInput
|
||||||
|
= PASSR_INP_login String
|
||||||
|
| PASSR_INP_email String
|
||||||
|
|
||||||
data Action
|
data Action
|
||||||
= HandleAuthenticationInput AuthenticationInput
|
= HandleAuthenticationInput AuthenticationInput
|
||||||
| HandleRegisterInput RegisterInput
|
| HandleRegisterInput RegisterInput
|
||||||
|
| HandlePasswordRecovery PasswordRecoveryInput
|
||||||
--
|
--
|
||||||
| AuthenticationAttempt Event
|
| AuthenticationAttempt Event
|
||||||
| RegisterAttempt Event
|
| RegisterAttempt Event
|
||||||
|
| PasswordRecoveryAttempt Event
|
||||||
|
|
||||||
type StateAuthenticationForm = { login :: String, pass :: String }
|
type StateAuthenticationForm = { login :: String, pass :: String }
|
||||||
type StateRegistrationForm = { login :: String, email :: String, pass :: String }
|
type StateRegistrationForm = { login :: String, email :: String, pass :: String }
|
||||||
|
type StatePasswordRecoveryForm = { login :: String, email :: String }
|
||||||
|
|
||||||
type State =
|
type State =
|
||||||
{ authenticationForm :: StateAuthenticationForm
|
{ authenticationForm :: StateAuthenticationForm
|
||||||
, registrationForm :: StateRegistrationForm
|
, registrationForm :: StateRegistrationForm
|
||||||
|
, passwordRecoveryForm :: StatePasswordRecoveryForm
|
||||||
, wsUp :: Boolean
|
, wsUp :: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,28 +92,25 @@ initialState :: Input -> State
|
|||||||
initialState _ =
|
initialState _ =
|
||||||
{ authenticationForm: { login: "", pass: "" }
|
{ authenticationForm: { login: "", pass: "" }
|
||||||
, registrationForm: { login: "", email: "", pass: "" }
|
, registrationForm: { login: "", email: "", pass: "" }
|
||||||
|
, passwordRecoveryForm: { login: "", email: "" }
|
||||||
|
|
||||||
, wsUp: true
|
, wsUp: true
|
||||||
}
|
}
|
||||||
|
|
||||||
render :: forall m. State -> H.ComponentHTML Action () m
|
render :: forall m. State -> H.ComponentHTML Action () m
|
||||||
render { wsUp, authenticationForm, registrationForm }
|
render { wsUp, authenticationForm, registrationForm, passwordRecoveryForm}
|
||||||
= Bulma.section_small
|
= Bulma.section_small
|
||||||
[ case wsUp of
|
[ case wsUp of
|
||||||
false -> Bulma.p "You are disconnected."
|
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
|
where
|
||||||
|
b e = Bulma.column_ [ Bulma.box e ]
|
||||||
|
|
||||||
auth_form
|
auth_form = [ Bulma.h3 "Authentication" , render_auth_form ]
|
||||||
= [ Bulma.h3 "Authentication"
|
register_form = [ Bulma.h3 "Register!" , render_register_form ]
|
||||||
, render_auth_form
|
passrecovery_form = [ Bulma.h3 "Password Recovery", render_password_recovery_form ]
|
||||||
]
|
|
||||||
|
|
||||||
register_form
|
|
||||||
= [ Bulma.h3 "Register!"
|
|
||||||
, render_register_form
|
|
||||||
]
|
|
||||||
|
|
||||||
should_be_disabled = (if wsUp then (HP.enabled true) else (HP.disabled true))
|
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 :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit
|
||||||
handleAction = case _ of
|
handleAction = case _ of
|
||||||
HandleAuthenticationInput authinp -> do
|
HandleAuthenticationInput authinp -> do
|
||||||
@ -169,6 +194,11 @@ handleAction = case _ of
|
|||||||
REG_INP_email v -> H.modify_ _ { registrationForm { email = v } }
|
REG_INP_email v -> H.modify_ _ { registrationForm { email = v } }
|
||||||
REG_INP_pass v -> H.modify_ _ { registrationForm { pass = 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
|
RegisterAttempt ev -> do
|
||||||
H.liftEffect $ Event.preventDefault ev
|
H.liftEffect $ Event.preventDefault ev
|
||||||
|
|
||||||
@ -212,6 +242,23 @@ handleAction = case _ of
|
|||||||
H.raise $ MessageToSend message
|
H.raise $ MessageToSend message
|
||||||
H.raise $ Log $ SimpleLog $ "[😇] Trying to authenticate (login: " <> login <> ")"
|
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 :: forall a m. MonadAff m => Query a -> H.HalogenM State Action () Output m (Maybe a)
|
||||||
handleQuery = case _ of
|
handleQuery = case _ of
|
||||||
MessageReceived message a -> do
|
MessageReceived message a -> do
|
||||||
|
Loading…
Reference in New Issue
Block a user