Users can now change their email address.
parent
14341b2953
commit
35f4bfa9ab
|
@ -431,6 +431,14 @@ handleAction = case _ of
|
|||
-- Once the user has been deleted, just act like it was just a disconnection.
|
||||
handleAction $ Disconnection
|
||||
|
||||
SetupInterface.ChangeEmailAddress email_address -> do
|
||||
message <- H.liftEffect $ AuthD.serialize $ AuthD.MkModUser { user: Nothing
|
||||
, admin: Nothing
|
||||
, password: Nothing
|
||||
, email: Just email_address
|
||||
}
|
||||
H.tell _ws_auth unit (WS.ToSend message)
|
||||
|
||||
SetupInterface.ChangePassword pass -> do
|
||||
message <- H.liftEffect $ AuthD.serialize $ AuthD.MkModUser { user: Nothing
|
||||
, admin: Nothing
|
||||
|
|
|
@ -187,7 +187,7 @@ string_error_login = case _ of
|
|||
|
||||
show_error_email :: E.Error -> String
|
||||
show_error_email = case _ of
|
||||
E.ParsingError {error} -> maybe "" string_error_email error
|
||||
E.ParsingError {error} -> maybe "invalid email address" string_error_email error
|
||||
|
||||
string_error_email :: E.EmailParsingError -> String
|
||||
string_error_email = case _ of
|
||||
|
|
|
@ -16,14 +16,18 @@ import Web.Event.Event (Event)
|
|||
|
||||
import Bulma as Bulma
|
||||
|
||||
import App.Type.Email as Email
|
||||
import App.Validation.Email as E
|
||||
import App.Validation.Password as P
|
||||
|
||||
import App.Type.LogMessage
|
||||
import App.Message.AuthenticationDaemon as AuthD
|
||||
import App.DisplayErrors (show_error_email)
|
||||
|
||||
data Output
|
||||
= Log LogMessage
|
||||
| ChangePassword String
|
||||
| ChangeEmailAddress Email.Email
|
||||
| DeleteUserAccount
|
||||
|
||||
-- | The component's parent provides received messages.
|
||||
|
@ -43,9 +47,14 @@ data NewPasswordInput
|
|||
| NEWPASS_INP_confirmation String
|
||||
|
||||
data Action
|
||||
= HandleNewPassword NewPasswordInput
|
||||
| ChangePasswordAttempt Event
|
||||
| SendChangePasswordMessage
|
||||
= HandleNewPassword NewPasswordInput -- user input
|
||||
| ChangePasswordAttempt Event -- validation
|
||||
| SendChangePasswordMessage -- sends the message
|
||||
|
||||
| HandleNewEmail String -- user input
|
||||
| ChangeEmailAttempt Event -- validation
|
||||
| SendChangeEmailAddressMessage -- sends the message
|
||||
|
||||
| CancelModal
|
||||
| DeleteAccountPopup
|
||||
| DeleteAccount
|
||||
|
@ -58,6 +67,7 @@ data Modal
|
|||
|
||||
type State =
|
||||
{ newPasswordForm :: StateNewPasswordForm
|
||||
, new_email_address :: String
|
||||
, token :: String
|
||||
, modal :: Modal
|
||||
}
|
||||
|
@ -76,16 +86,18 @@ component =
|
|||
initialState :: Input -> State
|
||||
initialState token =
|
||||
{ newPasswordForm: { password: "", confirmation: "" }
|
||||
, new_email_address: ""
|
||||
, token
|
||||
, modal: NoModal
|
||||
}
|
||||
|
||||
render :: forall m. State -> H.ComponentHTML Action () m
|
||||
render { modal, newPasswordForm } =
|
||||
render { modal, newPasswordForm, new_email_address } =
|
||||
Bulma.section_small
|
||||
[ case modal of
|
||||
DeleteAccountModal -> render_delete_account_modal
|
||||
NoModal -> Bulma.columns_ [ b [ Bulma.h3 "Change password", render_new_password_form ]
|
||||
NoModal -> Bulma.columns_ [ b [ Bulma.h3 "Change email address", render_new_email_form ]
|
||||
, b [ Bulma.h3 "Change password", render_new_password_form ]
|
||||
, b [ Bulma.h3 "Delete account", render_delete_account ]
|
||||
]
|
||||
]
|
||||
|
@ -94,6 +106,13 @@ render { modal, newPasswordForm } =
|
|||
b e = Bulma.column_ e
|
||||
|
||||
render_delete_account = Bulma.alert_btn "Delete my account" DeleteAccountPopup
|
||||
|
||||
render_new_email_form = HH.form
|
||||
[ HE.onSubmit ChangeEmailAttempt ]
|
||||
[ Bulma.box_input "emailAddress" "New email address" "foo@bar.com" HandleNewEmail new_email_address
|
||||
, Bulma.btn_validation
|
||||
]
|
||||
|
||||
render_new_password_form = HH.form
|
||||
[ HE.onSubmit ChangePasswordAttempt ]
|
||||
[ Bulma.box_password "passwordNEWPASS" "New Password" "password"
|
||||
|
@ -120,6 +139,9 @@ handleAction = case _ of
|
|||
NEWPASS_INP_password v -> H.modify_ _ { newPasswordForm { password = v } }
|
||||
NEWPASS_INP_confirmation v -> H.modify_ _ { newPasswordForm { confirmation = v } }
|
||||
|
||||
HandleNewEmail email_address -> do
|
||||
H.modify_ _ { new_email_address = email_address }
|
||||
|
||||
CancelModal -> do
|
||||
H.modify_ _ { modal = NoModal }
|
||||
DeleteAccountPopup -> do
|
||||
|
@ -128,6 +150,17 @@ handleAction = case _ of
|
|||
H.raise $ DeleteUserAccount
|
||||
handleAction $ CancelModal
|
||||
|
||||
ChangeEmailAttempt ev -> do
|
||||
H.liftEffect $ Event.preventDefault ev
|
||||
|
||||
{ new_email_address } <- H.get
|
||||
case new_email_address of
|
||||
"" -> H.raise $ Log $ UnableToSend "Write your new email address!"
|
||||
email_address -> do
|
||||
case E.email email_address of
|
||||
Left errors -> H.raise $ Log $ UnableToSend $ A.fold $ map show_error_email errors
|
||||
Right _ -> handleAction SendChangeEmailAddressMessage
|
||||
|
||||
ChangePasswordAttempt ev -> do
|
||||
H.liftEffect $ Event.preventDefault ev
|
||||
|
||||
|
@ -142,6 +175,11 @@ handleAction = case _ of
|
|||
Right _ -> handleAction SendChangePasswordMessage
|
||||
else H.raise $ Log $ UnableToSend "Confirmation differs from password"
|
||||
|
||||
SendChangeEmailAddressMessage -> do
|
||||
state <- H.get
|
||||
H.raise $ Log $ SystemLog "Changing the email address"
|
||||
H.raise $ ChangeEmailAddress (Email.Email state.new_email_address)
|
||||
|
||||
SendChangePasswordMessage -> do
|
||||
state <- H.get
|
||||
H.raise $ Log $ SystemLog "Changing the password"
|
||||
|
|
Loading…
Reference in New Issue