From 4a2784919b23832e099b0251afff2cf3e0c9c869 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 17 Feb 2021 18:44:37 +0100 Subject: [PATCH] Return more information on successful reset token check --- src/api_data/mod.rs | 3 ++- src/api_data/res_check_password_token.rs | 24 ++++++++++++++++++++++++ src/controllers/account_controller.rs | 7 +++++-- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 src/api_data/res_check_password_token.rs diff --git a/src/api_data/mod.rs b/src/api_data/mod.rs index a885c98..a0db0cb 100644 --- a/src/api_data/mod.rs +++ b/src/api_data/mod.rs @@ -65,4 +65,5 @@ pub mod call_member_info; pub mod left_call_message; pub mod new_call_signal; pub mod call_peer_ready; -pub mod call_peer_interrupted_streaming; \ No newline at end of file +pub mod call_peer_interrupted_streaming; +pub mod res_check_password_token; \ No newline at end of file diff --git a/src/api_data/res_check_password_token.rs b/src/api_data/res_check_password_token.rs new file mode 100644 index 0000000..2320cbc --- /dev/null +++ b/src/api_data/res_check_password_token.rs @@ -0,0 +1,24 @@ +//! # Successful validation of password reset token +//! +//! @author Pierre Hubert + +use serde::Serialize; + +use crate::data::user::User; + +#[derive(Serialize)] +pub struct ResCheckPasswordToken { + first_name: String, + last_name: String, + mail: String, +} + +impl ResCheckPasswordToken { + pub fn new(user: &User) -> Self { + Self { + first_name: user.first_name.to_string(), + last_name: user.last_name.to_string(), + mail: user.email.to_string(), + } + } +} \ No newline at end of file diff --git a/src/controllers/account_controller.rs b/src/controllers/account_controller.rs index c288099..f365a6f 100644 --- a/src/controllers/account_controller.rs +++ b/src/controllers/account_controller.rs @@ -4,6 +4,7 @@ use crate::api_data::account_export_api::AccountExportAPI; use crate::api_data::current_user_id::CurrentUserID; use crate::api_data::login_success::LoginSuccess; use crate::api_data::res_check_email_exists::ResCheckEmailExists; +use crate::api_data::res_check_password_token::ResCheckPasswordToken; use crate::api_data::res_check_security_answers::ResCheckSecurityAnswers; use crate::api_data::res_check_security_questions_exists::ResCheckSecurityQuestionsExists; use crate::api_data::res_get_security_questions::ResGetSecurityQuestions; @@ -171,8 +172,10 @@ pub fn check_security_answers(r: &mut HttpRequestHandler) -> RequestResult { /// Check the validity of a password reset token pub fn check_password_reset_token(r: &mut HttpRequestHandler) -> RequestResult { - r.post_user_id_from_password_reset_token("token")?; - r.success("The token is valid") + let user_id = r.post_user_id_from_password_reset_token("token")?; + let user = user_helper::find_user_by_id(&user_id)?; + + r.set_response(ResCheckPasswordToken::new(&user)) } /// Reset user password