Specific input functions.

This commit is contained in:
Philippe Pittoli 2024-11-16 17:15:05 +01:00
parent 61f7ef65bd
commit 0ab978e231
5 changed files with 105 additions and 64 deletions

View file

@ -158,7 +158,7 @@ render { current_tab, authenticationForm, passwordRecoveryForm, newPasswordForm,
show_error :: Error -> String show_error :: Error -> String
show_error = case _ of show_error = case _ of
Login arr -> "Error with the login: " <> (A.fold $ map show_error_login arr) Login arr -> "Error with the login: " <> (A.fold $ map show_error_login arr)
Email arr -> "Error with the email: " <> (A.fold $ map show_error_email arr) Email arr -> "Error with the email: " <> (A.fold $ map show_error_email arr)
Password arr -> "Error with the password: " <> (A.fold $ map show_error_password arr) Password arr -> "Error with the password: " <> (A.fold $ map show_error_password arr)
@ -221,41 +221,26 @@ render { current_tab, authenticationForm, passwordRecoveryForm, newPasswordForm,
render_auth_form = HH.form render_auth_form = HH.form
[ HE.onSubmit AuthenticationAttempt ] [ HE.onSubmit AuthenticationAttempt ]
[ Bulma.box_input "loginLOGIN" "Login" "login" -- title, placeholder [ Bulma.username_input "Username" authenticationForm.login (HandleAuthenticationInput <<< AUTH_INP_login)
(HandleAuthenticationInput <<< AUTH_INP_login) -- action , Bulma.password_input "Password" authenticationForm.pass (HandleAuthenticationInput <<< AUTH_INP_pass)
authenticationForm.login -- value
, Bulma.box_password "passwordLOGIN" "Password" "password" -- title, placeholder
(HandleAuthenticationInput <<< AUTH_INP_pass) -- action
authenticationForm.pass -- value
, Bulma.btn_validation , Bulma.btn_validation
] ]
render_password_recovery_form = HH.form render_password_recovery_form = HH.form
[ HE.onSubmit PasswordRecoveryAttempt ] [ HE.onSubmit PasswordRecoveryAttempt ]
[ Bulma.box_input "loginPASSR" "Login" "login" -- title, placeholder [ Bulma.username_input "Username" passwordRecoveryForm.login (HandlePasswordRecovery <<< PASSR_INP_login)
(HandlePasswordRecovery <<< PASSR_INP_login) -- action , Bulma.email_input "Email" passwordRecoveryForm.email (HandlePasswordRecovery <<< PASSR_INP_email)
passwordRecoveryForm.login -- value
, Bulma.box_input "emailPASSR" "Email" "email" -- title, placeholder
(HandlePasswordRecovery <<< PASSR_INP_email) -- action
passwordRecoveryForm.email -- value
, Bulma.btn_validation , Bulma.btn_validation
] ]
render_new_password_form = HH.form render_new_password_form = HH.form
[ HE.onSubmit NewPasswordAttempt ] [ HE.onSubmit NewPasswordAttempt ]
[ Bulma.box_input "loginNEWPASS" "Login" "login" [ Bulma.username_input "Username" newPasswordForm.login (HandleNewPassword <<< NEWPASS_INP_login)
(HandleNewPassword <<< NEWPASS_INP_login) , Bulma.token_input "Token" newPasswordForm.token (HandleNewPassword <<< NEWPASS_INP_token)
newPasswordForm.login , Bulma.password_input_new "Password" newPasswordForm.password (HandleNewPassword <<< NEWPASS_INP_password)
, Bulma.box_input "tokenNEWPASS" "Token" "token"
(HandleNewPassword <<< NEWPASS_INP_token) , Bulma.password_input_confirmation "Confirmation" newPasswordForm.confirmation
newPasswordForm.token (HandleNewPassword <<< NEWPASS_INP_confirmation)
, Bulma.box_password "passwordNEWPASS" "Password" "password"
(HandleNewPassword <<< NEWPASS_INP_password)
newPasswordForm.password
, Bulma.box_password "confirmationNEWPASS" "Confirmation" "confirmation"
(HandleNewPassword <<< NEWPASS_INP_confirmation)
newPasswordForm.confirmation
, Bulma.btn_validation , Bulma.btn_validation
] ]

View file

@ -88,20 +88,14 @@ render { mailValidationForm }
b e = Bulma.column_ [ Bulma.box e ] b e = Bulma.column_ [ Bulma.box e ]
mail_validation_form mail_validation_form
= [ Bulma.h3 "Verify your account" = [ Bulma.h3 "Verify your account"
, Bulma.div_content [] [Bulma.explanation [Bulma.p """ , Bulma.div_content [] [Bulma.explanation [Bulma.p "Email addresses must be validated within 30 minutes."]]
Email addresses must be validated within 2 days.
"""]]
, render_register_form , render_register_form
] ]
render_register_form = HH.form render_register_form = HH.form
[ HE.onSubmit ValidateInputs ] [ HE.onSubmit ValidateInputs ]
[ Bulma.box_input "loginValidation" "Login" "login" -- title, placeholder [ Bulma.username_input "Username" mailValidationForm.login (HandleValidationInput <<< VALIDATION_INP_login)
(HandleValidationInput <<< VALIDATION_INP_login) -- action , Bulma.token_input "Token" mailValidationForm.token (HandleValidationInput <<< VALIDATION_INP_token)
mailValidationForm.login -- value
, Bulma.box_input "tokenValidation" "Token" "token" -- title, placeholder
(HandleValidationInput <<< VALIDATION_INP_token) -- action
mailValidationForm.token -- value
, Bulma.btn_validation , Bulma.btn_validation
] ]
@ -121,11 +115,8 @@ handleAction = case _ of
let { login, token } = mailValidationForm let { login, token } = mailValidationForm
case login, token of case login, token of
"", _ -> "", _ -> H.raise $ Log $ UnableToSend "Please, write your login."
H.raise $ Log $ UnableToSend "Please, write your login." _, "" -> H.raise $ Log $ UnableToSend "Please, write your token."
_, "" ->
H.raise $ Log $ UnableToSend "Please, write your token."
_, _ -> do _, _ -> do
case L.login login, T.token token of case L.login login, T.token token of

View file

@ -104,24 +104,20 @@ render { registrationForm }
render_register_form = HH.form render_register_form = HH.form
[ HE.onSubmit ValidateInputs ] [ HE.onSubmit ValidateInputs ]
(login_input <> login_error <> (username_input <> username_error <>
email_input <> email_error <> email_input <> email_error <>
password_input <> password_error <> password_input <> password_error <>
legal_mentions <> validation_btn) legal_mentions <> validation_btn)
login_input = [ Bulma.login_input "Login" registrationForm.login (HandleRegisterInput <<< REG_INP_login) ] username_input = [ Bulma.username_input "Username" registrationForm.login (HandleRegisterInput <<< REG_INP_login) ]
login_error username_error
= case between 0 1 (S.length registrationForm.login), L.login registrationForm.login of = case between 0 1 (S.length registrationForm.login), L.login registrationForm.login of
true, _ -> [] true, _ -> []
_, Left errors -> [ Bulma.error_box "loginREGISTER" "Login error" (show_error $ Login errors) ] _, Left errors -> [ Bulma.error_box "loginREGISTER" "Login error" (show_error $ Login errors) ]
_, Right _ -> [] _, Right _ -> []
email_input email_input = [ Bulma.email_input "Email" registrationForm.email (HandleRegisterInput <<< REG_INP_email) ]
= [ Bulma.box_input "emailREGISTER" "Email" "email@example.com" -- title, placeholder
(HandleRegisterInput <<< REG_INP_email) -- action
registrationForm.email -- value
]
email_error email_error
= case between 0 5 (S.length registrationForm.email), E.email registrationForm.email of = case between 0 5 (S.length registrationForm.email), E.email registrationForm.email of
@ -129,11 +125,7 @@ render { registrationForm }
_, Left errors -> [ Bulma.error_box "emailREGISTER" "Email error" (show_error $ Email errors) ] _, Left errors -> [ Bulma.error_box "emailREGISTER" "Email error" (show_error $ Email errors) ]
_, Right _ -> [] _, Right _ -> []
password_input password_input = [ Bulma.password_input "Password" registrationForm.pass (HandleRegisterInput <<< REG_INP_pass) ]
= [ Bulma.box_password "passwordREGISTER" "Password" "password" -- title, placeholder
(HandleRegisterInput <<< REG_INP_pass) -- action
registrationForm.pass -- value
]
password_error password_error
= case between 0 15 (S.length registrationForm.pass), P.password registrationForm.pass of = case between 0 15 (S.length registrationForm.pass), P.password registrationForm.pass of

View file

@ -8,7 +8,6 @@ import Halogen.HTML as HH
import DOM.HTML.Indexed as DHI import DOM.HTML.Indexed as DHI
import Halogen.HTML.Properties as HP import Halogen.HTML.Properties as HP
import Halogen.HTML.Events as HE import Halogen.HTML.Events as HE
import MissingHTMLProperties as MissingProperties
import DOM.HTML.Indexed.AutocompleteType (AutocompleteType(..)) import DOM.HTML.Indexed.AutocompleteType (AutocompleteType(..))
import CSSClasses as C import CSSClasses as C
@ -20,7 +19,7 @@ import Halogen.HTML.Core (AttrName(..))
checkbox :: forall w i. Array (HH.HTML w i) -> i -> HH.HTML w i checkbox :: forall w i. Array (HH.HTML w i) -> i -> HH.HTML w i
checkbox content_ action checkbox content_ action
= HH.label = HH.label
[ HP.classes [C.label] ] $ [ HH.input [ HE.onValueInput \ _ -> action, MissingProperties.ty "checkbox" ] ] <> content_ [ HP.classes [C.label] ] $ [ HH.input [ HE.onValueInput \ _ -> action, HP.type_ HP.InputCheckbox ] ] <> content_
-- <label class="checkbox"> -- <label class="checkbox">
-- <input type="checkbox" /> -- <input type="checkbox" />
-- I agree to the <a href="#">terms and conditions</a> -- I agree to the <a href="#">terms and conditions</a>
@ -543,13 +542,13 @@ box_password_ = field_inner true
box_input :: forall w i. String -> String -> String -> (String -> i) -> String -> HH.HTML w i box_input :: forall w i. String -> String -> String -> (String -> i) -> String -> HH.HTML w i
box_input = box_input_ (HP.enabled true) box_input = box_input_ (HP.enabled true)
login_input :: forall w i. String -> String -> (String -> i) -> HH.HTML w i username_input :: forall w i. String -> String -> (String -> i) -> HH.HTML w i
login_input title value action username_input title value action
= div_field [] = div_field []
[ div_field_label "username" title [ div_field_label "username" title
, div_field_content $ HH.input , div_field_content $ HH.input
[ HE.onValueInput action [ HE.onValueInput action
, MissingProperties.ty "text" , HP.type_ HP.InputText
, HP.value value , HP.value value
, HP.name "username" , HP.name "username"
, HP.autocomplete AutocompleteUsername , HP.autocomplete AutocompleteUsername
@ -559,6 +558,86 @@ login_input title value action
] ]
] ]
email_input :: forall w i. String -> String -> (String -> i) -> HH.HTML w i
email_input title value action
= div_field []
[ div_field_label "email" title
, div_field_content $ HH.input
[ HE.onValueInput action
, HP.type_ HP.InputEmail
, HP.value value
, HP.name "email"
, HP.autocomplete AutocompleteEmail
, HP.placeholder "email@example.com"
, HP.id "email"
, HP.classes input_classes
]
]
password_input :: forall w i. String -> String -> (String -> i) -> HH.HTML w i
password_input title value action
= div_field []
[ div_field_label "password" title
, div_field_content $ HH.input
[ HE.onValueInput action
, HP.type_ HP.InputPassword
, HP.value value
, HP.name "password"
, HP.autocomplete AutocompleteCurrentPassword
, HP.placeholder ""
, HP.id "password"
, HP.classes input_classes
]
]
password_input_new :: forall w i. String -> String -> (String -> i) -> HH.HTML w i
password_input_new title value action
= div_field []
[ div_field_label "password" title
, div_field_content $ HH.input
[ HE.onValueInput action
, HP.type_ HP.InputPassword
, HP.value value
, HP.name "password"
, HP.autocomplete AutocompleteNewPassword
, HP.placeholder ""
, HP.id "password"
, HP.classes input_classes
]
]
password_input_confirmation :: forall w i. String -> String -> (String -> i) -> HH.HTML w i
password_input_confirmation title value action
= div_field []
[ div_field_label "password_confirmation" title
, div_field_content $ HH.input
[ HE.onValueInput action
, HP.type_ HP.InputPassword
, HP.value value
, HP.name "password_confirmation"
, HP.autocomplete AutocompleteOff
, HP.placeholder ""
, HP.id "password_confirmation"
, HP.classes input_classes
]
]
token_input :: forall w i. String -> String -> (String -> i) -> HH.HTML w i
token_input title value action
= div_field []
[ div_field_label "token" title
, div_field_content $ HH.input
[ HE.onValueInput action
, HP.type_ HP.InputText
, HP.value value
, HP.name "token"
, HP.autocomplete AutocompleteOff
, HP.placeholder ""
, HP.id "token"
, HP.classes input_classes
]
]
box_password :: forall w i. String -> String -> String -> (String -> i) -> String -> HH.HTML w i box_password :: forall w i. String -> String -> String -> (String -> i) -> String -> HH.HTML w i
box_password = box_password_ (HP.enabled true) box_password = box_password_ (HP.enabled true)

View file

@ -10,9 +10,3 @@ aria_current = HP.attr (AttrName "aria-current")
size :: forall r i. Int -> HP.IProp (size :: Int | r) i size :: forall r i. Int -> HP.IProp (size :: Int | r) i
size = HP.prop (PropName "size") size = HP.prop (PropName "size")
-- ty :: forall r i. Int -> HP.IProp (ty :: String | r) i
-- ty = HP.prop (PropName "type")
ty :: forall r i. String -> HP.IProp r i
ty = HP.attr (AttrName "type")