Skip to content

Commit

Permalink
feat: [#618] scaffolding for changing pass endpoint
Browse files Browse the repository at this point in the history
This only adds the enpoint which alwyas returns a 404 response.
  • Loading branch information
josecelano committed Jun 4, 2024
1 parent 3c4522f commit df848de
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/web/api/server/v1/contexts/user/forms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ pub struct LoginForm {
pub struct JsonWebToken {
pub token: String, // // todo: rename to `encoded` or `value`
}

// Profile

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ChangePasswordForm {
pub password: String,
pub new_password: String,
pub confirm_password: String,
}
21 changes: 20 additions & 1 deletion src/web/api/server/v1/contexts/user/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use axum::response::{IntoResponse, Response};
use axum::Json;
use serde::Deserialize;

use super::forms::{JsonWebToken, LoginForm, RegistrationForm};
use super::forms::{ChangePasswordForm, JsonWebToken, LoginForm, RegistrationForm};
use super::responses::{self};
use crate::common::AppData;
use crate::errors::ServiceError;
use crate::web::api::server::v1::extractors::user_id::ExtractLoggedInUser;
use crate::web::api::server::v1::responses::OkResponseData;

Expand Down Expand Up @@ -123,6 +124,24 @@ pub async fn renew_token_handler(
}
}

/// It changes the user's password.
///
/// # Errors
///
/// It returns an error if:
///
/// - The user account is not found.
#[allow(clippy::unused_async)]
pub async fn change_password_handler(
State(_app_data): State<Arc<AppData>>,
extract::Json(change_password_form): extract::Json<ChangePasswordForm>,
) -> Response {

println!("change pass form: {change_password_form:#?}");

ServiceError::AccountNotFound.into_response()
}

/// It bans a user from the index.
///
/// # Errors
Expand Down
8 changes: 7 additions & 1 deletion src/web/api/server/v1/contexts/user/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use axum::routing::{delete, get, post};
use axum::Router;

use super::handlers::{
ban_handler, email_verification_handler, login_handler, registration_handler, renew_token_handler, verify_token_handler,
ban_handler, change_password_handler, email_verification_handler, login_handler, registration_handler, renew_token_handler,
verify_token_handler,
};
use crate::common::AppData;

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

0 comments on commit df848de

Please sign in to comment.