Simplify password change call syntax
This commit is contained in:
		| @@ -41,16 +41,13 @@ pub struct GetAllUsersRequest; | |||||||
| pub struct GetAllUsersResult(pub Vec<User>); | pub struct GetAllUsersResult(pub Vec<User>); | ||||||
|  |  | ||||||
| #[derive(Message)] | #[derive(Message)] | ||||||
| #[rtype(ChangePasswordResult)] | #[rtype(result = "bool")] | ||||||
| pub struct ChangePasswordRequest { | pub struct ChangePasswordRequest { | ||||||
|     pub user_id: UserID, |     pub user_id: UserID, | ||||||
|     pub new_password: String, |     pub new_password: String, | ||||||
|     pub temporary: bool, |     pub temporary: bool, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Debug)] |  | ||||||
| pub struct ChangePasswordResult(pub bool); |  | ||||||
|  |  | ||||||
| #[derive(Message)] | #[derive(Message)] | ||||||
| #[rtype(result = "bool")] | #[rtype(result = "bool")] | ||||||
| pub struct AddSuccessful2FALogin(pub UserID, pub IpAddr); | pub struct AddSuccessful2FALogin(pub UserID, pub IpAddr); | ||||||
| @@ -109,14 +106,11 @@ impl Handler<LoginRequest> for UsersActor { | |||||||
| } | } | ||||||
|  |  | ||||||
| impl Handler<ChangePasswordRequest> for UsersActor { | impl Handler<ChangePasswordRequest> for UsersActor { | ||||||
|     type Result = MessageResult<ChangePasswordRequest>; |     type Result = <ChangePasswordRequest as actix::Message>::Result; | ||||||
|  |  | ||||||
|     fn handle(&mut self, msg: ChangePasswordRequest, _ctx: &mut Self::Context) -> Self::Result { |     fn handle(&mut self, msg: ChangePasswordRequest, _ctx: &mut Self::Context) -> Self::Result { | ||||||
|         MessageResult(ChangePasswordResult(self.manager.change_user_password( |         self.manager | ||||||
|             &msg.user_id, |             .change_user_password(&msg.user_id, &msg.new_password, msg.temporary) | ||||||
|             &msg.new_password, |  | ||||||
|             msg.temporary, |  | ||||||
|         ))) |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ use actix_web::{web, HttpRequest, HttpResponse, Responder}; | |||||||
| use askama::Template; | use askama::Template; | ||||||
|  |  | ||||||
| use crate::actors::bruteforce_actor::BruteForceActor; | use crate::actors::bruteforce_actor::BruteForceActor; | ||||||
| use crate::actors::users_actor::{ChangePasswordResult, LoginResult, UsersActor}; | use crate::actors::users_actor::{LoginResult, UsersActor}; | ||||||
| use crate::actors::{bruteforce_actor, users_actor}; | use crate::actors::{bruteforce_actor, users_actor}; | ||||||
| use crate::constants::{APP_NAME, MAX_FAILED_LOGIN_ATTEMPTS, MIN_PASS_LEN}; | use crate::constants::{APP_NAME, MAX_FAILED_LOGIN_ATTEMPTS, MIN_PASS_LEN}; | ||||||
| use crate::controllers::base_controller::{ | use crate::controllers::base_controller::{ | ||||||
| @@ -237,7 +237,7 @@ pub async fn reset_password_route( | |||||||
|         if req.password.len() < MIN_PASS_LEN { |         if req.password.len() < MIN_PASS_LEN { | ||||||
|             danger = Some("Password is too short!".to_string()); |             danger = Some("Password is too short!".to_string()); | ||||||
|         } else { |         } else { | ||||||
|             let res: ChangePasswordResult = users |             let res: bool = users | ||||||
|                 .send(users_actor::ChangePasswordRequest { |                 .send(users_actor::ChangePasswordRequest { | ||||||
|                     user_id: user_id.clone(), |                     user_id: user_id.clone(), | ||||||
|                     new_password: req.password.clone(), |                     new_password: req.password.clone(), | ||||||
| @@ -246,7 +246,7 @@ pub async fn reset_password_route( | |||||||
|                 .await |                 .await | ||||||
|                 .unwrap(); |                 .unwrap(); | ||||||
|  |  | ||||||
|             if !res.0 { |             if !res { | ||||||
|                 danger = Some("Failed to change password!".to_string()); |                 danger = Some("Failed to change password!".to_string()); | ||||||
|             } else { |             } else { | ||||||
|                 SessionIdentity(id.as_ref()).set_status(&http_req, SessionStatus::SignedIn); |                 SessionIdentity(id.as_ref()).set_status(&http_req, SessionStatus::SignedIn); | ||||||
|   | |||||||
| @@ -125,8 +125,7 @@ pub async fn change_password_route( | |||||||
|                     temporary: false, |                     temporary: false, | ||||||
|                 }) |                 }) | ||||||
|                 .await |                 .await | ||||||
|                 .unwrap() |                 .unwrap(); | ||||||
|                 .0; |  | ||||||
|  |  | ||||||
|             if !res { |             if !res { | ||||||
|                 danger = |                 danger = | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user