refactor(users): Separate signup and signin (#2921)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Mani Chandra
2023-12-04 17:03:44 +05:30
committed by GitHub
parent 9d93533219
commit 80efeb76b1
9 changed files with 453 additions and 109 deletions

View File

@ -1,11 +1,13 @@
use diesel_models::enums::UserStatus;
use api_models::user as user_api;
use diesel_models::{enums::UserStatus, user_role::UserRole};
use error_stack::ResultExt;
use masking::Secret;
use crate::{
core::errors::{UserErrors, UserResult},
routes::AppState,
services::authentication::UserFromToken,
types::domain::MerchantAccount,
services::authentication::{AuthToken, UserFromToken},
types::domain::{MerchantAccount, UserFromStorage},
};
pub mod dashboard_metadata;
@ -68,3 +70,52 @@ pub async fn get_merchant_ids_for_user(state: AppState, user_id: &str) -> UserRe
})
.collect())
}
pub async fn generate_jwt_auth_token(
state: AppState,
user: &UserFromStorage,
user_role: &UserRole,
) -> UserResult<Secret<String>> {
let token = AuthToken::new_token(
user.get_user_id().to_string(),
user_role.merchant_id.clone(),
user_role.role_id.clone(),
&state.conf,
user_role.org_id.clone(),
)
.await?;
Ok(Secret::new(token))
}
pub async fn generate_jwt_auth_token_with_custom_merchant_id(
state: AppState,
user: &UserFromStorage,
user_role: &UserRole,
merchant_id: String,
) -> UserResult<Secret<String>> {
let token = AuthToken::new_token(
user.get_user_id().to_string(),
merchant_id,
user_role.role_id.clone(),
&state.conf,
user_role.org_id.to_owned(),
)
.await?;
Ok(Secret::new(token))
}
pub fn get_dashboard_entry_response(
user: UserFromStorage,
user_role: UserRole,
token: Secret<String>,
) -> user_api::DashboardEntryResponse {
user_api::DashboardEntryResponse {
merchant_id: user_role.merchant_id,
token,
name: user.get_name(),
email: user.get_email(),
user_id: user.get_user_id().to_string(),
verification_days_left: None,
user_role: user_role.role_id,
}
}