mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 13:30:39 +08:00
fix(user): add checks for change password (#3078)
Co-authored-by: Rachit Naithani <81706961+racnan@users.noreply.github.com>
This commit is contained in:
@ -48,6 +48,8 @@ pub enum UserErrors {
|
||||
InvalidMetadataRequest,
|
||||
#[error("MerchantIdParsingError")]
|
||||
MerchantIdParsingError,
|
||||
#[error("ChangePasswordError")]
|
||||
ChangePasswordError,
|
||||
}
|
||||
|
||||
impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorResponse> for UserErrors {
|
||||
@ -136,6 +138,12 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorRespon
|
||||
Self::MerchantIdParsingError => {
|
||||
AER::BadRequest(ApiError::new(sub_code, 28, "Invalid Merchant Id", None))
|
||||
}
|
||||
Self::ChangePasswordError => AER::BadRequest(ApiError::new(
|
||||
sub_code,
|
||||
29,
|
||||
"Old and new password cannot be same",
|
||||
None,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,10 +10,6 @@ pub enum SampleDataError {
|
||||
InternalServerError,
|
||||
#[error("Data Does Not Exist")]
|
||||
DataDoesNotExist,
|
||||
#[error("Server Error")]
|
||||
DatabaseError,
|
||||
#[error("Merchant Id Not Found")]
|
||||
MerchantIdNotFound,
|
||||
#[error("Invalid Parameters")]
|
||||
InvalidParameters,
|
||||
#[error["Invalid Records"]]
|
||||
@ -29,33 +25,21 @@ impl ErrorSwitch<ApiErrorResponse> for SampleDataError {
|
||||
"Something went wrong",
|
||||
None,
|
||||
)),
|
||||
Self::DatabaseError => ApiErrorResponse::InternalServerError(ApiError::new(
|
||||
"SD",
|
||||
1,
|
||||
"Server Error(DB is down)",
|
||||
None,
|
||||
)),
|
||||
Self::DataDoesNotExist => ApiErrorResponse::NotFound(ApiError::new(
|
||||
"SD",
|
||||
2,
|
||||
1,
|
||||
"Sample Data not present for given request",
|
||||
None,
|
||||
)),
|
||||
Self::MerchantIdNotFound => ApiErrorResponse::BadRequest(ApiError::new(
|
||||
"SD",
|
||||
3,
|
||||
"Merchant ID not provided",
|
||||
None,
|
||||
)),
|
||||
Self::InvalidParameters => ApiErrorResponse::BadRequest(ApiError::new(
|
||||
"SD",
|
||||
4,
|
||||
2,
|
||||
"Invalid parameters to generate Sample Data",
|
||||
None,
|
||||
)),
|
||||
Self::InvalidRange => ApiErrorResponse::BadRequest(ApiError::new(
|
||||
"SD",
|
||||
5,
|
||||
3,
|
||||
"Records to be generated should be between range 10 and 100",
|
||||
None,
|
||||
)),
|
||||
@ -67,7 +51,7 @@ impl ErrorSwitchFrom<StorageError> for SampleDataError {
|
||||
fn switch_from(error: &StorageError) -> Self {
|
||||
match matches!(error, StorageError::ValueNotFound(_)) {
|
||||
true => Self::DataDoesNotExist,
|
||||
false => Self::DatabaseError,
|
||||
false => Self::InternalServerError,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,10 +232,16 @@ pub async fn change_password(
|
||||
.change_context(UserErrors::InternalServerError)?
|
||||
.into();
|
||||
|
||||
user.compare_password(request.old_password)
|
||||
user.compare_password(request.old_password.to_owned())
|
||||
.change_context(UserErrors::InvalidOldPassword)?;
|
||||
|
||||
let new_password_hash = utils::user::password::generate_password_hash(request.new_password)?;
|
||||
if request.old_password == request.new_password {
|
||||
return Err(UserErrors::ChangePasswordError.into());
|
||||
}
|
||||
let new_password = domain::UserPassword::new(request.new_password)?;
|
||||
|
||||
let new_password_hash =
|
||||
utils::user::password::generate_password_hash(new_password.get_secret())?;
|
||||
|
||||
let _ = UserInterface::update_user_by_user_id(
|
||||
&*state.store,
|
||||
|
||||
@ -34,7 +34,7 @@ pub async fn generate_sample_data(
|
||||
&state.store.get_master_key().to_vec().into(),
|
||||
)
|
||||
.await
|
||||
.change_context(SampleDataError::DatabaseError)?;
|
||||
.change_context(SampleDataError::InternalServerError)?;
|
||||
|
||||
let merchant_from_db = state
|
||||
.store
|
||||
|
||||
Reference in New Issue
Block a user