|
|
@ -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, |
|
|
|