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
refactor(user): remove password from internal signup and gate it on signup with merchant id (#15348)
Susritha4239ba6efd8d
diff --git a/config/config.example.toml b/config/config.example.tomlindex 90077efabd..b189e5137b 100644--- a/config/config.example.toml+++ b/config/config.example.toml@@ -683,6 +683,7 @@ totp_issuer_name = "Hyperswitch" # Name of the issuer for TOTPbase_url = "" # Base url used for user specific redirects and emailsforce_two_factor_auth = false # Whether to force two factor authentication for all usersforce_cookies = false # Whether to use only cookies for JWT extraction and authentication+accept_password_on_signup_with_merchant_id = false # Whether signup_with_merchant_id accepts a password from the request (otherwise the user is created without one)internal_merchant_id = "juspay000" # Merchant id of the internal merchant that internal users are created under# idle_session_timeout_in_secs = 900 # When set, signs Dashboard users out after this many seconds without a requestemail_token_expiry_in_secs = 86400 # Number of seconds for which email links (verify, reset password, invite, etc.) stay validdiff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.tomlindex 42da4c74b6..0985ae9fcb 100644--- a/config/deployments/integration_test.toml+++ b/config/deployments/integration_test.toml@@ -253,6 +253,7 @@ totp_issuer_name = "Hyperswitch Integ"base_url = "https://integ.hyperswitch.io"force_two_factor_auth = falseforce_cookies = false+accept_password_on_signup_with_merchant_id = falseinternal_merchant_id = "juspay000"[frm]diff --git a/config/deployments/production.toml b/config/deployments/production.tomlindex 4b4a639e62..b82ebec00d 100644--- a/config/deployments/production.toml+++ b/config/deployments/production.toml@@ -266,6 +266,7 @@ totp_issuer_name = "Hyperswitch Production"base_url = "https://live.hyperswitch.io"force_two_factor_auth = trueforce_cookies = false+accept_password_on_signup_with_merchant_id = falseinternal_merchant_id = "juspay000"[frm]diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.tomlindex e17aae1668..7d840700e4 100644--- a/config/deployments/sandbox.toml+++ b/config/deployments/sandbox.toml@@ -262,6 +262,7 @@ totp_issuer_name = "Hyperswitch Sandbox"base_url = "https://app.hyperswitch.io"force_two_factor_auth = falseforce_cookies = false+accept_password_on_signup_with_merchant_id = falseinternal_merchant_id = "juspay000"[debit_routing_config]diff --git a/config/development.toml b/config/development.tomlindex fa06700278..dec412b126 100644--- a/config/development.toml+++ b/config/development.toml@@ -585,6 +585,7 @@ totp_issuer_name = "Hyperswitch Dev"base_url = "http://localhost:8080"force_two_factor_auth = falseforce_cookies = false+accept_password_on_signup_with_merchant_id = trueinternal_merchant_id = "juspay000"[oidc.key.k1]diff --git a/config/docker_compose.toml b/config/docker_compose.tomlindex 56e130393b..47d0d29ab0 100644--- a/config/docker_compose.toml+++ b/config/docker_compose.toml@@ -130,6 +130,7 @@ totp_issuer_name = "Hyperswitch"base_url = "http://localhost:9000"force_two_factor_auth = falseforce_cookies = false+accept_password_on_signup_with_merchant_id = trueinternal_merchant_id = "juspay000"[oidc.key.k1]diff --git a/crates/api_models/src/user.rs b/crates/api_models/src/user.rsindex daec50fb22..75ef6679b9 100644--- a/crates/api_models/src/user.rs+++ b/crates/api_models/src/user.rs@@ -16,7 +16,7 @@ pub mod theme;pub struct SignUpWithMerchantIdRequest {pub name: Secret<String>,pub email: pii::Email,- pub password: Secret<String>,+ pub password: Option<Secret<String>>,pub company_name: String,pub organization_type: Option<common_enums::OrganizationType>,}@@ -139,7 +139,6 @@ pub struct CloneConnectorRequest {pub struct CreateInternalUserRequest {pub name: Secret<String>,pub email: pii::Email,- pub password: Secret<String>,pub role_id: String,}diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rsindex 8f5614e66e..96503bf69f 100644--- a/crates/router/src/configs/settings.rs+++ b/crates/router/src/configs/settings.rs@@ -1021,7 +1021,9 @@ pub struct UserSettings {pub force_two_factor_auth: bool,pub force_cookies: bool,pub idle_session_timeout_in_secs: Option<u32>,- pub internal_merchant_id: common_utils::id_type::MerchantId,+ #[serde(default)]+ pub accept_password_on_signup_with_merchant_id: bool,+ pub internal_merchant_id: id_type::MerchantId,pub email_token_expiry_in_secs: u64,pub password_max_attempts: u16,pub password_lock_duration_in_secs: i64,diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rsindex 6abb7ece55..6ace815e0f 100644--- a/crates/router/src/core/user.rs+++ b/crates/router/src/core/user.rs@@ -82,7 +82,10 @@ pub async fn signup_with_merchant_id(},)?;- let new_user = domain::NewUser::try_from(request.clone())?;+ let new_user = domain::NewUser::try_from((+ request,+ state.conf.user.accept_password_on_signup_with_merchant_id,+ ))?;new_user.get_new_merchant().get_new_organization()@@ -1742,6 +1745,30 @@ pub async fn create_internal_user(.await.change_context(UserErrors::InternalServerError)?;+ // Internal users are created without a password, so send them a link to set one+ #[cfg(feature = "email")]+ {+ let email_contents = email_types::ResetPassword {+ recipient_email: user_from_storage.get_email().try_into()?,+ user_name: domain::UserName::new(user_from_storage.get_name())?,+ settings: state.conf.clone(),+ auth_id: None,+ theme_id: None,+ theme_config: state.conf.theme.email_config.clone(),+ };++ let send_email_result = state+ .email_client+ .compose_and_send_email(+ user_utils::get_base_url(&state),+ Box::new(email_contents),+ state.conf.proxy.https_url.as_ref(),+ )+ .await;++ logger::info!(?send_email_result);+ }+Ok(ApplicationResponse::StatusOk)}diff --git a/crates/router/src/types/domain/user.rs b/crates/router/src/types/domain/user.rsindex cb17d4daf1..9c82348b97 100644--- a/crates/router/src/types/domain/user.rs+++ b/crates/router/src/types/domain/user.rs@@ -1041,22 +1041,31 @@ impl TryFrom<NewUser> for storage_user::UserNew {}}-impl TryFrom<user_api::SignUpWithMerchantIdRequest> for NewUser {+impl TryFrom<(user_api::SignUpWithMerchantIdRequest, bool)> for NewUser {type Error = error_stack::Report<UserErrors>;- fn try_from(value: user_api::SignUpWithMerchantIdRequest) -> UserResult<Self> {+ fn try_from(+ (value, accept_password): (user_api::SignUpWithMerchantIdRequest, bool),+ ) -> UserResult<Self> {let email = value.email.clone().try_into()?;let name = UserName::new(value.name.clone())?;- let password = NewUserPassword {- password: UserPassword::new(value.password.clone())?,- is_temporary: false,- };+ let password = value+ .password+ .clone()+ .filter(|_| accept_password)+ .map(|password| {+ UserPassword::new(password).map(|password| NewUserPassword {+ password,+ is_temporary: false,+ })+ })+ .transpose()?;let new_merchant = NewUserMerchant::try_from(value)?;Ok(Self {name,email,- password: Some(password),+ password,new_merchant,})}@@ -1118,16 +1127,12 @@ impl) -> UserResult<Self> {let email = value.email.clone().try_into()?;let name = UserName::new(value.name.clone())?;- let password = NewUserPassword {- password: UserPassword::new(value.password.clone())?,- is_temporary: false,- };let new_merchant = NewUserMerchant::try_from((value, org_id, merchant_id))?;Ok(Self {name,email,- password: Some(password),+ password: None,new_merchant,})}