Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(users): Prevent TOTP secret from being cleared on status update (#11596)
Grovy-31703ebfb39291b3
diff --git a/crates/diesel_models/src/user.rs b/crates/diesel_models/src/user.rsindex 30c9e68758..d28cb773e6 100644--- a/crates/diesel_models/src/user.rs+++ b/crates/diesel_models/src/user.rs@@ -72,8 +72,8 @@ pub enum UserUpdate {},TotpUpdate {totp_status: Option<TotpStatus>,- totp_secret: Option<Encryption>,- totp_recovery_codes: Option<Vec<Secret<String>>>,+ totp_secret: Option<Option<Encryption>>,+ totp_recovery_codes: Option<Option<Vec<Secret<String>>>>,},PasswordUpdate {password: Secret<String>,@@ -129,8 +129,8 @@ impl From<UserUpdate> for UserUpdateInternal {is_verified: None,last_modified_at,totp_status,- totp_secret: Some(totp_secret),- totp_recovery_codes: Some(totp_recovery_codes),+ totp_secret,+ totp_recovery_codes,last_password_modified_at: None,lineage_context: None,is_active: None,diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rsindex 1a80f6ae67..f0822761a5 100644--- a/crates/router/src/core/user.rs+++ b/crates/router/src/core/user.rs@@ -2407,7 +2407,7 @@ pub async fn update_totp(&user_token.user_id,storage_user::UserUpdate::TotpUpdate {totp_status: None,- totp_secret: Some(+ totp_secret: Some(Some(// TODO: Impl conversion trait for User and move this theredomain::types::crypto_operation::<String, hyperswitch_masking::WithType>(&(&state).into(),@@ -2420,7 +2420,7 @@ pub async fn update_totp(.and_then(|val| val.try_into_operation()).change_context(UserErrors::InternalServerError)?.into(),- ),+ )),totp_recovery_codes: None,},@@ -2459,11 +2459,11 @@ pub async fn generate_recovery_codes(storage_user::UserUpdate::TotpUpdate {totp_status: None,totp_secret: None,- totp_recovery_codes: Some(+ totp_recovery_codes: Some(Some(recovery_codes.get_hashed().change_context(UserErrors::InternalServerError)?,- ),+ )),},).await@@ -2550,7 +2550,7 @@ pub async fn verify_recovery_code(storage_user::UserUpdate::TotpUpdate {totp_status: None,totp_secret: None,- totp_recovery_codes: Some(recovery_codes),+ totp_recovery_codes: Some(Some(recovery_codes)),},).awaitdiff --git a/crates/router/src/db/user.rs b/crates/router/src/db/user.rsindex 9f96835d76..976cc47785 100644--- a/crates/router/src/db/user.rs+++ b/crates/router/src/db/user.rs@@ -329,8 +329,9 @@ impl UserInterface for MockDb {} => storage::User {last_modified_at,totp_status: totp_status.unwrap_or(user.totp_status),- totp_secret: totp_secret.or(user.totp_secret.clone()),- totp_recovery_codes: totp_recovery_codes.or(user.totp_recovery_codes.clone()),+ totp_secret: totp_secret.unwrap_or(user.totp_secret.clone()),+ totp_recovery_codes: totp_recovery_codes+ .unwrap_or(user.totp_recovery_codes.clone()),..user.to_owned()},@@ -402,9 +403,9 @@ impl UserInterface for MockDb {} => storage::User {last_modified_at,totp_status: totp_status.unwrap_or(user.totp_status),- totp_secret: totp_secret.or_else(|| user.totp_secret.clone()),+ totp_secret: totp_secret.unwrap_or(user.totp_secret.clone()),totp_recovery_codes: totp_recovery_codes- .or_else(|| user.totp_recovery_codes.clone()),+ .unwrap_or(user.totp_recovery_codes.clone()),..user.to_owned()},