Skip to content

Commit df848de

Browse files
committed
feat: [#618] scaffolding for changing pass endpoint
This only adds the enpoint which alwyas returns a 404 response.
1 parent 3c4522f commit df848de

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ pub struct LoginForm {
2222
pub struct JsonWebToken {
2323
pub token: String, // // todo: rename to `encoded` or `value`
2424
}
25+
26+
// Profile
27+
28+
#[derive(Clone, Debug, Deserialize, Serialize)]
29+
pub struct ChangePasswordForm {
30+
pub password: String,
31+
pub new_password: String,
32+
pub confirm_password: String,
33+
}

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

+20-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use axum::response::{IntoResponse, Response};
77
use axum::Json;
88
use serde::Deserialize;
99

10-
use super::forms::{JsonWebToken, LoginForm, RegistrationForm};
10+
use super::forms::{ChangePasswordForm, JsonWebToken, LoginForm, RegistrationForm};
1111
use super::responses::{self};
1212
use crate::common::AppData;
13+
use crate::errors::ServiceError;
1314
use crate::web::api::server::v1::extractors::user_id::ExtractLoggedInUser;
1415
use crate::web::api::server::v1::responses::OkResponseData;
1516

@@ -123,6 +124,24 @@ pub async fn renew_token_handler(
123124
}
124125
}
125126

127+
/// It changes the user's password.
128+
///
129+
/// # Errors
130+
///
131+
/// It returns an error if:
132+
///
133+
/// - The user account is not found.
134+
#[allow(clippy::unused_async)]
135+
pub async fn change_password_handler(
136+
State(_app_data): State<Arc<AppData>>,
137+
extract::Json(change_password_form): extract::Json<ChangePasswordForm>,
138+
) -> Response {
139+
140+
println!("change pass form: {change_password_form:#?}");
141+
142+
ServiceError::AccountNotFound.into_response()
143+
}
144+
126145
/// It bans a user from the index.
127146
///
128147
/// # Errors

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use axum::routing::{delete, get, post};
77
use axum::Router;
88

99
use super::handlers::{
10-
ban_handler, email_verification_handler, login_handler, registration_handler, renew_token_handler, verify_token_handler,
10+
ban_handler, change_password_handler, email_verification_handler, login_handler, registration_handler, renew_token_handler,
11+
verify_token_handler,
1112
};
1213
use crate::common::AppData;
1314

@@ -28,6 +29,11 @@ pub fn router(app_data: Arc<AppData>) -> Router {
2829
.route("/login", post(login_handler).with_state(app_data.clone()))
2930
.route("/token/verify", post(verify_token_handler).with_state(app_data.clone()))
3031
.route("/token/renew", post(renew_token_handler).with_state(app_data.clone()))
32+
// Profile
33+
.route(
34+
"/:user/change-password",
35+
post(change_password_handler).with_state(app_data.clone()),
36+
)
3137
// User ban
3238
// code-review: should not this be a POST method? We add the user to the blacklist. We do not delete the user.
3339
.route("/ban/:user", delete(ban_handler).with_state(app_data))

0 commit comments

Comments
 (0)