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")]
pub struct Clear2FALoginHistory(pub UserID);
#[derive(Debug)]
pub struct UpdateUserResult(pub bool);
#[derive(Message)]
#[rtype(UpdateUserResult)]
#[rtype(result = "bool")]
pub struct UpdateUserRequest(pub User);
#[derive(Debug)]
@ -157,16 +154,16 @@ impl Handler<GetAllUsersRequest> 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 {
MessageResult(UpdateUserResult(match self.manager.update_or_push(msg.0) {
match self.manager.update_or_push(msg.0) {
Ok(_) => true,
Err(e) => {
log::error!("Failed to update user information! {:?}", e);
false
}
}))
}
}
}

View File

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

View File

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