mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 11:24:45 +08:00
refactor(users): Changes for Home and Signout APIs for TOTP Redis flows (#4851)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -165,7 +165,10 @@ pub struct GetUserDetailsResponse {
|
||||
#[serde(skip_serializing)]
|
||||
pub user_id: String,
|
||||
pub org_id: String,
|
||||
pub is_two_factor_auth_setup: bool,
|
||||
pub recovery_codes_left: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct GetUserRoleDetailsRequest {
|
||||
pub email: pii::Email,
|
||||
|
||||
@ -94,6 +94,8 @@ pub async fn get_user_details(
|
||||
verification_days_left,
|
||||
role_id: user_from_token.role_id,
|
||||
org_id: user_from_token.org_id,
|
||||
is_two_factor_auth_setup: user.get_totp_status() == TotpStatus::Set,
|
||||
recovery_codes_left: user.get_recovery_codes().map(|codes| codes.len()),
|
||||
},
|
||||
))
|
||||
}
|
||||
@ -328,6 +330,10 @@ pub async fn signout(
|
||||
state: SessionState,
|
||||
user_from_token: auth::UserFromToken,
|
||||
) -> UserResponse<()> {
|
||||
tfa_utils::delete_totp_from_redis(&state, &user_from_token.user_id).await?;
|
||||
tfa_utils::delete_recovery_code_from_redis(&state, &user_from_token.user_id).await?;
|
||||
tfa_utils::delete_totp_secret_from_redis(&state, &user_from_token.user_id).await?;
|
||||
|
||||
auth::blacklist::insert_user_in_blacklist(&state, &user_from_token.user_id).await?;
|
||||
auth::cookies::remove_cookie_response()
|
||||
}
|
||||
|
||||
@ -116,3 +116,26 @@ pub async fn insert_recovery_code_in_redis(state: &SessionState, user_id: &str)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)
|
||||
}
|
||||
|
||||
pub async fn delete_totp_from_redis(state: &SessionState, user_id: &str) -> UserResult<()> {
|
||||
let redis_conn = super::get_redis_connection(state)?;
|
||||
let key = format!("{}{}", consts::user::REDIS_TOTP_PREFIX, user_id);
|
||||
redis_conn
|
||||
.delete_key(&key)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
pub async fn delete_recovery_code_from_redis(
|
||||
state: &SessionState,
|
||||
user_id: &str,
|
||||
) -> UserResult<()> {
|
||||
let redis_conn = super::get_redis_connection(state)?;
|
||||
let key = format!("{}{}", consts::user::REDIS_RECOVERY_CODE_PREFIX, user_id);
|
||||
redis_conn
|
||||
.delete_key(&key)
|
||||
.await
|
||||
.change_context(UserErrors::InternalServerError)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user