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.
|
-- Once the user has been deleted, just act like it was just a disconnection.
|
||||||
handleAction $ 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
|
SetupInterface.ChangePassword pass -> do
|
||||||
message <- H.liftEffect $ AuthD.serialize $ AuthD.MkModUser { user: Nothing
|
message <- H.liftEffect $ AuthD.serialize $ AuthD.MkModUser { user: Nothing
|
||||||
, admin: Nothing
|
, admin: Nothing
|
||||||
|
|
|
@ -187,7 +187,7 @@ string_error_login = case _ of
|
||||||
|
|
||||||
show_error_email :: E.Error -> String
|
show_error_email :: E.Error -> String
|
||||||
show_error_email = case _ of
|
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 :: E.EmailParsingError -> String
|
||||||
string_error_email = case _ of
|
string_error_email = case _ of
|
||||||
|
|
|
@ -16,14 +16,18 @@ import Web.Event.Event (Event)
|
||||||
|
|
||||||
import Bulma as Bulma
|
import Bulma as Bulma
|
||||||
|
|
||||||
|
import App.Type.Email as Email
|
||||||
|
import App.Validation.Email as E
|
||||||
import App.Validation.Password as P
|
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
|
||||||
|
import App.DisplayErrors (show_error_email)
|
||||||
|
|
||||||
data Output
|
data Output
|
||||||
= Log LogMessage
|
= Log LogMessage
|
||||||
| ChangePassword String
|
| ChangePassword String
|
||||||
|
| ChangeEmailAddress Email.Email
|
||||||
| DeleteUserAccount
|
| DeleteUserAccount
|
||||||
|
|
||||||
-- | The component's parent provides received messages.
|
-- | The component's parent provides received messages.
|
||||||
|
@ -43,9 +47,14 @@ data NewPasswordInput
|
||||||
| NEWPASS_INP_confirmation String
|
| NEWPASS_INP_confirmation String
|
||||||
|
|
||||||
data Action
|
data Action
|
||||||
= HandleNewPassword NewPasswordInput
|
= HandleNewPassword NewPasswordInput -- user input
|
||||||
| ChangePasswordAttempt Event
|
| ChangePasswordAttempt Event -- validation
|
||||||
| SendChangePasswordMessage
|
| SendChangePasswordMessage -- sends the message
|
||||||
|
|
||||||
|
| HandleNewEmail String -- user input
|
||||||
|
| ChangeEmailAttempt Event -- validation
|
||||||
|
| SendChangeEmailAddressMessage -- sends the message
|
||||||
|
|
||||||
| CancelModal
|
| CancelModal
|
||||||
| DeleteAccountPopup
|
| DeleteAccountPopup
|
||||||
| DeleteAccount
|
| DeleteAccount
|
||||||
|
@ -58,6 +67,7 @@ data Modal
|
||||||
|
|
||||||
type State =
|
type State =
|
||||||
{ newPasswordForm :: StateNewPasswordForm
|
{ newPasswordForm :: StateNewPasswordForm
|
||||||
|
, new_email_address :: String
|
||||||
, token :: String
|
, token :: String
|
||||||
, modal :: Modal
|
, modal :: Modal
|
||||||
}
|
}
|
||||||
|
@ -76,16 +86,18 @@ component =
|
||||||
initialState :: Input -> State
|
initialState :: Input -> State
|
||||||
initialState token =
|
initialState token =
|
||||||
{ newPasswordForm: { password: "", confirmation: "" }
|
{ newPasswordForm: { password: "", confirmation: "" }
|
||||||
|
, new_email_address: ""
|
||||||
, token
|
, token
|
||||||
, modal: NoModal
|
, modal: NoModal
|
||||||
}
|
}
|
||||||
|
|
||||||
render :: forall m. State -> H.ComponentHTML Action () m
|
render :: forall m. State -> H.ComponentHTML Action () m
|
||||||
render { modal, newPasswordForm } =
|
render { modal, newPasswordForm, new_email_address } =
|
||||||
Bulma.section_small
|
Bulma.section_small
|
||||||
[ case modal of
|
[ case modal of
|
||||||
DeleteAccountModal -> render_delete_account_modal
|
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 ]
|
, b [ Bulma.h3 "Delete account", render_delete_account ]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
@ -94,6 +106,13 @@ render { modal, newPasswordForm } =
|
||||||
b e = Bulma.column_ e
|
b e = Bulma.column_ e
|
||||||
|
|
||||||
render_delete_account = Bulma.alert_btn "Delete my account" DeleteAccountPopup
|
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
|
render_new_password_form = HH.form
|
||||||
[ HE.onSubmit ChangePasswordAttempt ]
|
[ HE.onSubmit ChangePasswordAttempt ]
|
||||||
[ Bulma.box_password "passwordNEWPASS" "New Password" "password"
|
[ 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_password v -> H.modify_ _ { newPasswordForm { password = v } }
|
||||||
NEWPASS_INP_confirmation v -> H.modify_ _ { newPasswordForm { confirmation = v } }
|
NEWPASS_INP_confirmation v -> H.modify_ _ { newPasswordForm { confirmation = v } }
|
||||||
|
|
||||||
|
HandleNewEmail email_address -> do
|
||||||
|
H.modify_ _ { new_email_address = email_address }
|
||||||
|
|
||||||
CancelModal -> do
|
CancelModal -> do
|
||||||
H.modify_ _ { modal = NoModal }
|
H.modify_ _ { modal = NoModal }
|
||||||
DeleteAccountPopup -> do
|
DeleteAccountPopup -> do
|
||||||
|
@ -128,6 +150,17 @@ handleAction = case _ of
|
||||||
H.raise $ DeleteUserAccount
|
H.raise $ DeleteUserAccount
|
||||||
handleAction $ CancelModal
|
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
|
ChangePasswordAttempt ev -> do
|
||||||
H.liftEffect $ Event.preventDefault ev
|
H.liftEffect $ Event.preventDefault ev
|
||||||
|
|
||||||
|
@ -142,6 +175,11 @@ handleAction = case _ of
|
||||||
Right _ -> handleAction SendChangePasswordMessage
|
Right _ -> handleAction SendChangePasswordMessage
|
||||||
else H.raise $ Log $ UnableToSend "Confirmation differs from password"
|
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
|
SendChangePasswordMessage -> do
|
||||||
state <- H.get
|
state <- H.get
|
||||||
H.raise $ Log $ SystemLog "Changing the password"
|
H.raise $ Log $ SystemLog "Changing the password"
|
||||||
|
|
Loading…
Reference in New Issue