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