From 3852851f658cadaa4793e2a48b64dbefdf0ffefb Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 12 Nov 2023 02:52:26 -0500 Subject: [PATCH] 'success' fields, cleanup --- .../endpoints/password_reset_redeem_handler.rs | 15 ++++++++------- .../endpoints/password_reset_request_handler.rs | 5 +++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/service/plugins/users/src/endpoints/password_reset_redeem_handler.rs b/crates/service/plugins/users/src/endpoints/password_reset_redeem_handler.rs index 9afd3daa73..6009844974 100644 --- a/crates/service/plugins/users/src/endpoints/password_reset_redeem_handler.rs +++ b/crates/service/plugins/users/src/endpoints/password_reset_redeem_handler.rs @@ -15,7 +15,6 @@ use password::bcrypt_hash_password::bcrypt_hash_password; #[derive(Deserialize)] pub struct PasswordResetRedemptionRequest { - username_or_email: String, reset_token: String, new_password: String, new_password_validation: String, @@ -36,6 +35,7 @@ pub enum PasswordResetRedemptionError { #[derive(Serialize, Debug)] pub struct PasswordResetRedemptionErrorResponse { + success: bool, kind: PasswordResetRedemptionError, } impl Display for PasswordResetRedemptionErrorResponse { @@ -46,13 +46,13 @@ impl Display for PasswordResetRedemptionErrorResponse { impl From for PasswordResetRedemptionErrorResponse { fn from(value: PasswordResetRedemptionError) -> Self { - Self { kind: value } + Self { kind: value, success: false } } } impl From for PasswordResetRedemptionErrorResponse { fn from(value: errors::AnyhowError) -> Self { log::error!("Internal error: {value}"); - Self { kind: PasswordResetRedemptionError::Internal } + Self { kind: PasswordResetRedemptionError::Internal, success: false } } } @@ -78,11 +78,10 @@ pub async fn password_reset_redeem_handler( if new_password != request.new_password_validation.trim() { return Err(PasswordResetRedemptionErrorResponse { kind: PasswordResetRedemptionError::PasswordsDoNotMatch, + success: false, }); } - //TODO: Handle banned users, they shouldn't be able to do this - let result = lookup_password_reset_request(&request.reset_token, &mysql_pool).await .map_err(|err| { log::error!("Password reset error {:?}", err); @@ -95,18 +94,18 @@ pub async fn password_reset_redeem_handler( warn!("No such reset request."); return Err(PasswordResetRedemptionErrorResponse { kind: PasswordResetRedemptionError::InvalidRedemption, + success: false, }); } Err(err) => { error!("lookup error: {err}"); return Err(PasswordResetRedemptionErrorResponse { kind: PasswordResetRedemptionError::InvalidRedemption, + success: false, }); } }; - println!("Reset state: {}", transaction_and_state.reset_state.user_token); - let ip_address = get_request_ip(&http_request); let password_hash = match bcrypt_hash_password(new_password.to_string()) { @@ -115,6 +114,7 @@ pub async fn password_reset_redeem_handler( error!("password hash error: {err}"); return Err(PasswordResetRedemptionErrorResponse { kind: PasswordResetRedemptionError::Internal, + success: false, }); } }; @@ -131,6 +131,7 @@ pub async fn password_reset_redeem_handler( error!("password reset error: {err}"); return Err(PasswordResetRedemptionErrorResponse { kind: PasswordResetRedemptionError::Internal, + success: false, }); } diff --git a/crates/service/plugins/users/src/endpoints/password_reset_request_handler.rs b/crates/service/plugins/users/src/endpoints/password_reset_request_handler.rs index 7560c127f5..ca5e50ec6c 100644 --- a/crates/service/plugins/users/src/endpoints/password_reset_request_handler.rs +++ b/crates/service/plugins/users/src/endpoints/password_reset_request_handler.rs @@ -35,6 +35,7 @@ pub enum PasswordResetRequestedRequestError { #[derive(Serialize, Debug)] pub struct PasswordResetRequestedErrorResponse { + success: bool, kind: PasswordResetRequestedRequestError, } impl Display for PasswordResetRequestedErrorResponse { @@ -45,13 +46,13 @@ impl Display for PasswordResetRequestedErrorResponse { impl From for PasswordResetRequestedErrorResponse { fn from(value: PasswordResetRequestedRequestError) -> Self { - Self { kind: value } + Self { kind: value, success: false } } } impl From for PasswordResetRequestedErrorResponse { fn from(value: errors::AnyhowError) -> Self { log::error!("Internal error: {value}"); - Self { kind: PasswordResetRequestedRequestError::Internal } + Self { kind: PasswordResetRequestedRequestError::Internal, success: false } } }