Browse Source

2fa reset twofactor_remember

pull/7563/head
Timshel 2 months ago
parent
commit
c38a2731e6
  1. 4
      src/api/core/two_factor/authenticator.rs
  2. 4
      src/api/core/two_factor/duo.rs
  3. 4
      src/api/core/two_factor/email.rs
  4. 12
      src/api/core/two_factor/mod.rs
  5. 4
      src/api/core/two_factor/webauthn.rs
  6. 4
      src/api/core/two_factor/yubikey.rs

4
src/api/core/two_factor/authenticator.rs

@ -192,9 +192,7 @@ async fn disable_authenticator(data: Json<DisableAuthenticatorData>, headers: He
} }
} }
if TwoFactor::find_by_user(&user.uuid, &conn).await.is_empty() { super::check_2fa_state(&user, headers.device.atype, &headers.ip.ip, &conn).await?;
super::enforce_2fa_policy(&user, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await?;
}
Ok(()) Ok(())
} }

4
src/api/core/two_factor/duo.rs

@ -163,9 +163,7 @@ async fn disable_duo(data: Json<VerificationTokenData>, headers: Headers, conn:
log_user_event(EventType::UserDisabled2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await; log_user_event(EventType::UserDisabled2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
} }
if TwoFactor::find_by_user(&user.uuid, &conn).await.is_empty() { super::check_2fa_state(&user, headers.device.atype, &headers.ip.ip, &conn).await?;
super::enforce_2fa_policy(&user, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await?;
}
Ok(()) Ok(())
} }

4
src/api/core/two_factor/email.rs

@ -250,9 +250,7 @@ async fn disable_email(data: Json<VerificationTokenData>, headers: Headers, conn
log_user_event(EventType::UserDisabled2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await; log_user_event(EventType::UserDisabled2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
} }
if TwoFactor::find_by_user(&user.uuid, &conn).await.is_empty() { super::check_2fa_state(&user, headers.device.atype, &headers.ip.ip, &conn).await?;
super::enforce_2fa_policy(&user, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await?;
}
Ok(()) Ok(())
} }

12
src/api/core/two_factor/mod.rs

@ -13,8 +13,8 @@ use crate::{
db::{ db::{
DbConn, DbPool, DbConn, DbPool,
models::{ models::{
DeviceType, EventType, Membership, MembershipType, OrgPolicyType, Organization, OrganizationId, TwoFactor, Device, DeviceType, EventType, Membership, MembershipType, OrgPolicyType, Organization, OrganizationId,
TwoFactorIncomplete, TwoFactorType, User, UserId, TwoFactor, TwoFactorIncomplete, TwoFactorType, User, UserId,
}, },
}, },
mail, mail,
@ -122,6 +122,14 @@ async fn generate_recover_code(user: &mut User, conn: &DbConn) {
} }
} }
pub async fn check_2fa_state(user: &User, device_type: i32, ip: &std::net::IpAddr, conn: &DbConn) -> EmptyResult {
if TwoFactor::find_by_user(&user.uuid, conn).await.is_empty() {
Device::clear_twofactor_remember_by_user(&user.uuid, conn).await?;
enforce_2fa_policy(user, &user.uuid, device_type, ip, conn).await?;
}
Ok(())
}
pub async fn enforce_2fa_policy( pub async fn enforce_2fa_policy(
user: &User, user: &User,
act_user_id: &UserId, act_user_id: &UserId,

4
src/api/core/two_factor/webauthn.rs

@ -394,8 +394,8 @@ async fn inner_delete_webauthns(
} }
} }
if keys.is_empty() && TwoFactor::find_by_user(&user.uuid, conn).await.is_empty() { if keys.is_empty() {
super::enforce_2fa_policy(&user, &user.uuid, headers.device.atype, &headers.ip.ip, conn).await?; super::check_2fa_state(&user, headers.device.atype, &headers.ip.ip, conn).await?;
} }
Ok(Json(json!({ Ok(Json(json!({

4
src/api/core/two_factor/yubikey.rs

@ -214,9 +214,7 @@ async fn delete_yubikeys(data: Json<VerificationTokenData>, headers: Headers, co
log_user_event(EventType::UserDisabled2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await; log_user_event(EventType::UserDisabled2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
} }
if TwoFactor::find_by_user(&user.uuid, &conn).await.is_empty() { super::check_2fa_state(&user, headers.device.atype, &headers.ip.ip, &conn).await?;
super::enforce_2fa_policy(&user, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await?;
}
Ok(()) Ok(())
} }

Loading…
Cancel
Save