mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
refactor(users): Use domain email type in user DB functions (#6699)
This commit is contained in:
@ -166,7 +166,7 @@ pub async fn signin_token_only_flow(
|
||||
) -> UserResponse<user_api::TokenResponse> {
|
||||
let user_from_db: domain::UserFromStorage = state
|
||||
.global_store
|
||||
.find_user_by_email(&request.email)
|
||||
.find_user_by_email(&domain::UserEmail::from_pii_email(request.email)?)
|
||||
.await
|
||||
.to_not_found_response(UserErrors::InvalidCredentials)?
|
||||
.into();
|
||||
@ -191,7 +191,10 @@ pub async fn connect_account(
|
||||
request: user_api::ConnectAccountRequest,
|
||||
auth_id: Option<String>,
|
||||
) -> UserResponse<user_api::ConnectAccountResponse> {
|
||||
let find_user = state.global_store.find_user_by_email(&request.email).await;
|
||||
let find_user = state
|
||||
.global_store
|
||||
.find_user_by_email(&domain::UserEmail::from_pii_email(request.email.clone())?)
|
||||
.await;
|
||||
|
||||
if let Ok(found_user) = find_user {
|
||||
let user_from_db: domain::UserFromStorage = found_user.into();
|
||||
@ -369,7 +372,7 @@ pub async fn forgot_password(
|
||||
|
||||
let user_from_db = state
|
||||
.global_store
|
||||
.find_user_by_email(&user_email.into_inner())
|
||||
.find_user_by_email(&user_email)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
if e.current_context().is_db_not_found() {
|
||||
@ -453,11 +456,7 @@ pub async fn reset_password_token_only_flow(
|
||||
|
||||
let user_from_db: domain::UserFromStorage = state
|
||||
.global_store
|
||||
.find_user_by_email(
|
||||
&email_token
|
||||
.get_email()
|
||||
.change_context(UserErrors::InternalServerError)?,
|
||||
)
|
||||
.find_user_by_email(&email_token.get_email()?)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)?
|
||||
.into();
|
||||
@ -564,10 +563,7 @@ async fn handle_invitation(
|
||||
}
|
||||
|
||||
let invitee_email = domain::UserEmail::from_pii_email(request.email.clone())?;
|
||||
let invitee_user = state
|
||||
.global_store
|
||||
.find_user_by_email(&invitee_email.into_inner())
|
||||
.await;
|
||||
let invitee_user = state.global_store.find_user_by_email(&invitee_email).await;
|
||||
|
||||
if let Ok(invitee_user) = invitee_user {
|
||||
handle_existing_user_invitation(
|
||||
@ -958,7 +954,7 @@ pub async fn resend_invite(
|
||||
let invitee_email = domain::UserEmail::from_pii_email(request.email)?;
|
||||
let user: domain::UserFromStorage = state
|
||||
.global_store
|
||||
.find_user_by_email(&invitee_email.clone().into_inner())
|
||||
.find_user_by_email(&invitee_email)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
if e.current_context().is_db_not_found() {
|
||||
@ -1065,11 +1061,7 @@ pub async fn accept_invite_from_email_token_only_flow(
|
||||
|
||||
let user_from_db: domain::UserFromStorage = state
|
||||
.global_store
|
||||
.find_user_by_email(
|
||||
&email_token
|
||||
.get_email()
|
||||
.change_context(UserErrors::InternalServerError)?,
|
||||
)
|
||||
.find_user_by_email(&email_token.get_email()?)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)?
|
||||
.into();
|
||||
@ -1525,11 +1517,7 @@ pub async fn verify_email_token_only_flow(
|
||||
|
||||
let user_from_email = state
|
||||
.global_store
|
||||
.find_user_by_email(
|
||||
&email_token
|
||||
.get_email()
|
||||
.change_context(UserErrors::InternalServerError)?,
|
||||
)
|
||||
.find_user_by_email(&email_token.get_email()?)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)?;
|
||||
|
||||
@ -1572,7 +1560,7 @@ pub async fn send_verification_mail(
|
||||
let user_email = domain::UserEmail::try_from(req.email)?;
|
||||
let user = state
|
||||
.global_store
|
||||
.find_user_by_email(&user_email.into_inner())
|
||||
.find_user_by_email(&user_email)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
if e.current_context().is_db_not_found() {
|
||||
@ -1669,11 +1657,7 @@ pub async fn user_from_email(
|
||||
|
||||
let user_from_db: domain::UserFromStorage = state
|
||||
.global_store
|
||||
.find_user_by_email(
|
||||
&email_token
|
||||
.get_email()
|
||||
.change_context(UserErrors::InternalServerError)?,
|
||||
)
|
||||
.find_user_by_email(&email_token.get_email()?)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)?
|
||||
.into();
|
||||
@ -2379,7 +2363,7 @@ pub async fn sso_sign(
|
||||
// TODO: Use config to handle not found error
|
||||
let user_from_db: domain::UserFromStorage = state
|
||||
.global_store
|
||||
.find_user_by_email(&email.into_inner())
|
||||
.find_user_by_email(&email)
|
||||
.await
|
||||
.map(Into::into)
|
||||
.to_not_found_response(UserErrors::UserNotFound)?;
|
||||
|
||||
Reference in New Issue
Block a user