From 6c7fa3afa5293b58678e998154c7b4413e730d10 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 19 Jan 2021 17:57:07 +0100 Subject: [PATCH] Can change user password --- src/controllers/routes.rs | 2 ++ src/controllers/settings_controller.rs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/controllers/routes.rs b/src/controllers/routes.rs index 9442f1f..eaafbb2 100644 --- a/src/controllers/routes.rs +++ b/src/controllers/routes.rs @@ -101,6 +101,8 @@ pub fn get_routes() -> Vec { Route::post("/settings/get_security", Box::new(settings_controller::get_security)), Route::post("/settings/set_security", Box::new(settings_controller::set_security)), Route::post("/settings/check_password", Box::new(settings_controller::check_password)), + Route::post("/settings/update_password", Box::new(settings_controller::update_password)), + // Friends controller Route::post("/friends/getList", Box::new(friends_controller::get_list)), diff --git a/src/controllers/settings_controller.rs b/src/controllers/settings_controller.rs index 4009b2f..b1e31d9 100644 --- a/src/controllers/settings_controller.rs +++ b/src/controllers/settings_controller.rs @@ -123,4 +123,15 @@ pub fn check_password(r: &mut HttpRequestHandler) -> RequestResult { r.need_user_password("password")?; r.success("The password is valid.") +} + +/// Update user password +pub fn update_password(r: &mut HttpRequestHandler) -> RequestResult { + r.need_user_password("oldPassword")?; + + let new_password = r.post_string("newPassword")?; + + account_helper::change_password(r.user_id_ref()?, &new_password)?; + + r.success("Password updated !") } \ No newline at end of file