Simplify user update call syntax

This commit is contained in:
Pierre HUBERT 2022-11-19 16:43:28 +01:00
parent b10c48d080
commit 0c35400e64
3 changed files with 8 additions and 15 deletions

View File

@ -56,11 +56,8 @@ pub struct AddSuccessful2FALogin(pub UserID, pub IpAddr);
#[rtype(result = "bool")] #[rtype(result = "bool")]
pub struct Clear2FALoginHistory(pub UserID); pub struct Clear2FALoginHistory(pub UserID);
#[derive(Debug)]
pub struct UpdateUserResult(pub bool);
#[derive(Message)] #[derive(Message)]
#[rtype(UpdateUserResult)] #[rtype(result = "bool")]
pub struct UpdateUserRequest(pub User); pub struct UpdateUserRequest(pub User);
#[derive(Debug)] #[derive(Debug)]
@ -157,16 +154,16 @@ impl Handler<GetAllUsersRequest> for UsersActor {
} }
impl Handler<UpdateUserRequest> for UsersActor { impl Handler<UpdateUserRequest> for UsersActor {
type Result = MessageResult<UpdateUserRequest>; type Result = <UpdateUserRequest as actix::Message>::Result;
fn handle(&mut self, msg: UpdateUserRequest, _ctx: &mut Self::Context) -> Self::Result { fn handle(&mut self, msg: UpdateUserRequest, _ctx: &mut Self::Context) -> Self::Result {
MessageResult(UpdateUserResult(match self.manager.update_or_push(msg.0) { match self.manager.update_or_push(msg.0) {
Ok(_) => true, Ok(_) => true,
Err(e) => { Err(e) => {
log::error!("Failed to update user information! {:?}", e); log::error!("Failed to update user information! {:?}", e);
false false
} }
})) }
} }
} }

View File

@ -132,8 +132,7 @@ pub async fn users_route(
let res = users let res = users
.send(users_actor::UpdateUserRequest(user.clone())) .send(users_actor::UpdateUserRequest(user.clone()))
.await .await
.unwrap() .unwrap();
.0;
if !res { if !res {
danger = Some( danger = Some(

View File

@ -61,8 +61,7 @@ pub async fn save_totp_factor(
let res = users let res = users
.send(users_actor::UpdateUserRequest(user)) .send(users_actor::UpdateUserRequest(user))
.await .await
.unwrap() .unwrap();
.0;
if !res { if !res {
HttpResponse::InternalServerError().body("Failed to update user information!") HttpResponse::InternalServerError().body("Failed to update user information!")
@ -110,8 +109,7 @@ pub async fn save_webauthn_factor(
let res = users let res = users
.send(users_actor::UpdateUserRequest(user)) .send(users_actor::UpdateUserRequest(user))
.await .await
.unwrap() .unwrap();
.0;
if !res { if !res {
HttpResponse::InternalServerError().body("Failed to update user information!") HttpResponse::InternalServerError().body("Failed to update user information!")
@ -137,8 +135,7 @@ pub async fn delete_factor(
let res = users let res = users
.send(users_actor::UpdateUserRequest(user)) .send(users_actor::UpdateUserRequest(user))
.await .await
.unwrap() .unwrap();
.0;
if !res { if !res {
HttpResponse::InternalServerError().body("Failed to update user information!") HttpResponse::InternalServerError().body("Failed to update user information!")