Skip to content

Commit c22c919

Browse files
committed
refactor: [#615] change password handler and function now use optional user id
1 parent dbcd0e1 commit c22c919

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/services/user.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -230,23 +230,23 @@ impl ProfileService {
230230
/// * An error if unable to successfully hash the password.
231231
/// * An error if unable to change the password in the database.
232232
/// * An error if it is not possible to authorize the action
233+
#[allow(clippy::missing_panics_doc)]
233234
pub async fn change_password(
234235
&self,
235-
user_id: UserId,
236-
change_password_form: &ChangePasswordForm,
237236
maybe_user_id: Option<UserId>,
237+
change_password_form: &ChangePasswordForm,
238238
) -> Result<(), ServiceError> {
239239
self.authorization_service
240240
.authorize(ACTION::ChangePassword, maybe_user_id)
241241
.await?;
242242

243-
info!("changing user password for user ID: {user_id}");
243+
info!("changing user password for user ID: {}", maybe_user_id.unwrap());
244244

245245
let settings = self.configuration.settings.read().await;
246246

247247
let user_authentication = self
248248
.user_authentication_repository
249-
.get_user_authentication_from_id(&user_id)
249+
.get_user_authentication_from_id(&maybe_user_id.unwrap())
250250
.await?;
251251

252252
verify_password(change_password_form.current_password.as_bytes(), &user_authentication)?;
@@ -265,7 +265,7 @@ impl ProfileService {
265265
let password_hash = hash_password(&change_password_form.password)?;
266266

267267
self.user_authentication_repository
268-
.change_password(user_id, &password_hash)
268+
.change_password(maybe_user_id.unwrap(), &password_hash)
269269
.await?;
270270

271271
Ok(())

src/web/api/server/v1/contexts/user/handlers.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,19 @@ pub async fn renew_token_handler(
132132
///
133133
/// - The user account is not found.
134134
#[allow(clippy::unused_async)]
135+
#[allow(clippy::missing_panics_doc)]
135136
pub async fn change_password_handler(
136137
State(app_data): State<Arc<AppData>>,
137138
ExtractOptionalLoggedInUser(maybe_user_id): ExtractOptionalLoggedInUser,
138-
ExtractLoggedInUser(user_id): ExtractLoggedInUser,
139139
extract::Json(change_password_form): extract::Json<ChangePasswordForm>,
140140
) -> Response {
141141
match app_data
142142
.profile_service
143-
.change_password(user_id, &change_password_form, maybe_user_id)
143+
.change_password(maybe_user_id, &change_password_form)
144144
.await
145145
{
146146
Ok(()) => Json(OkResponseData {
147-
data: format!("Password changed for user with ID: {user_id}"),
147+
data: format!("Password changed for user with ID: {}", maybe_user_id.unwrap()),
148148
})
149149
.into_response(),
150150
Err(error) => error.into_response(),

0 commit comments

Comments
 (0)