mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2026-03-24 10:49:20 -07:00
fix email as 2fa for sso (#6495)
* fix email as 2fa for sso * allow saving device without updating `updated_at` * check if email is some * allow device to be saved in postgresql * use twofactor_incomplete table * no need to update device.updated_at
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::db::schema::{invitations, sso_users, users};
|
||||
use crate::db::schema::{invitations, sso_users, twofactor_incomplete, users};
|
||||
use chrono::{NaiveDateTime, TimeDelta, Utc};
|
||||
use derive_more::{AsRef, Deref, Display, From};
|
||||
use diesel::prelude::*;
|
||||
@@ -10,7 +10,7 @@ use super::{
|
||||
use crate::{
|
||||
api::EmptyResult,
|
||||
crypto,
|
||||
db::DbConn,
|
||||
db::{models::DeviceId, DbConn},
|
||||
error::MapResult,
|
||||
sso::OIDCIdentifier,
|
||||
util::{format_date, get_uuid, retry},
|
||||
@@ -386,6 +386,20 @@ impl User {
|
||||
}}
|
||||
}
|
||||
|
||||
pub async fn find_by_device_for_email2fa(device_uuid: &DeviceId, conn: &DbConn) -> Option<Self> {
|
||||
if let Some(user_uuid) = db_run! ( conn: {
|
||||
twofactor_incomplete::table
|
||||
.filter(twofactor_incomplete::device_uuid.eq(device_uuid))
|
||||
.order_by(twofactor_incomplete::login_time.desc())
|
||||
.select(twofactor_incomplete::user_uuid)
|
||||
.first::<UserId>(conn)
|
||||
.ok()
|
||||
}) {
|
||||
return Self::find_by_uuid(&user_uuid, conn).await;
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub async fn get_all(conn: &DbConn) -> Vec<(Self, Option<SsoUser>)> {
|
||||
db_run! { conn: {
|
||||
users::table
|
||||
|
||||
Reference in New Issue
Block a user