-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(users): add 2FA with email (#238)
- Loading branch information
Showing
28 changed files
with
459 additions
and
106 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
mango3-accounts/src/components/login_confirmation_modal.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use leptos::prelude::*; | ||
|
||
use mango3_leptos_utils::components::forms::ActionFormErrorAlert; | ||
use mango3_leptos_utils::components::{Modal, SubmitButton, TextField}; | ||
use mango3_leptos_utils::i18n::{t, use_i18n}; | ||
use mango3_leptos_utils::icons::InformationCircleOutlined; | ||
use mango3_leptos_utils::models::ActionFormResp; | ||
|
||
use crate::server_functions::AttemptToConfirmLogin; | ||
|
||
#[component] | ||
pub fn LoginConfirmationModal(is_open: RwSignal<bool>, #[prop(into)] on_success: Callback<()>) -> impl IntoView { | ||
let i18n = use_i18n(); | ||
let server_action = ServerAction::<AttemptToConfirmLogin>::new(); | ||
let action_value = server_action.value(); | ||
let error_alert_is_active = RwSignal::new(false); | ||
let error_code = RwSignal::new(None); | ||
|
||
Effect::new(move || { | ||
let response = ActionFormResp::from(action_value); | ||
|
||
if response.is_success() { | ||
is_open.set(false); | ||
on_success.run(()); | ||
} | ||
|
||
error_alert_is_active.set(response.is_invalid()); | ||
error_code.set(response.error("code")); | ||
}); | ||
|
||
view! { | ||
<Modal is_open=is_open> | ||
<h4 class="text-lg font-bold">{t!(i18n, accounts.confirm_login)}</h4> | ||
|
||
<div role="alert" class="alert mt-4"> | ||
<InformationCircleOutlined class="self-start my-2" /> | ||
|
||
<div>{t!(i18n, accounts.a_confirmation_code_has_been_sent_to_your_email_address)}"."</div> | ||
</div> | ||
|
||
<ActionForm action=server_action attr:autocomplete="off" attr:novalidate="true" attr:class="form"> | ||
<ActionFormErrorAlert | ||
is_active=error_alert_is_active | ||
message=move || t!(i18n, accounts.failed_to_confirm_login) | ||
/> | ||
|
||
<TextField label=move || t!(i18n, shared.code) name="code" error=error_code /> | ||
|
||
<SubmitButton is_loading=server_action.pending() /> | ||
</ActionForm> | ||
</Modal> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod invitation_code_modal; | ||
mod login_confirmation_modal; | ||
mod reset_password_modal; | ||
|
||
pub use invitation_code_modal::InvitationCodeModal; | ||
pub use login_confirmation_modal::LoginConfirmationModal; | ||
pub use reset_password_modal::ResetPasswordModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod app; | ||
pub mod components; | ||
pub mod models; | ||
pub mod pages; | ||
pub mod server_functions; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[cfg(feature = "ssr")] | ||
use mango3_core::models::UserSession; | ||
|
||
#[derive(Clone, Default, Deserialize, Serialize)] | ||
pub struct UserSessionResp { | ||
pub is_confirmed: bool, | ||
} | ||
|
||
#[cfg(feature = "ssr")] | ||
impl From<&UserSession> for UserSessionResp { | ||
fn from(value: &UserSession) -> Self { | ||
UserSessionResp { | ||
is_confirmed: value.is_confirmed(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.