mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-11-25 20:16:18 -05:00
fix email as 2fa provider (#6473)
This commit is contained in:
@@ -10,7 +10,7 @@ use crate::{
|
|||||||
auth::Headers,
|
auth::Headers,
|
||||||
crypto,
|
crypto,
|
||||||
db::{
|
db::{
|
||||||
models::{DeviceId, EventType, TwoFactor, TwoFactorType, User, UserId},
|
models::{EventType, TwoFactor, TwoFactorType, User, UserId},
|
||||||
DbConn,
|
DbConn,
|
||||||
},
|
},
|
||||||
error::{Error, MapResult},
|
error::{Error, MapResult},
|
||||||
@@ -24,16 +24,10 @@ pub fn routes() -> Vec<Route> {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct SendEmailLoginData {
|
struct SendEmailLoginData {
|
||||||
#[serde(alias = "DeviceIdentifier")]
|
|
||||||
device_identifier: DeviceId,
|
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
#[serde(alias = "Email")]
|
#[serde(alias = "Email")]
|
||||||
email: Option<String>,
|
email: String,
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
#[serde(alias = "MasterPasswordHash")]
|
#[serde(alias = "MasterPasswordHash")]
|
||||||
master_password_hash: Option<String>,
|
master_password_hash: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// User is trying to login and wants to use email 2FA.
|
/// User is trying to login and wants to use email 2FA.
|
||||||
@@ -45,14 +39,19 @@ async fn send_email_login(data: Json<SendEmailLoginData>, conn: DbConn) -> Empty
|
|||||||
use crate::db::models::User;
|
use crate::db::models::User;
|
||||||
|
|
||||||
// Get the user
|
// Get the user
|
||||||
let Some(user) = User::find_by_device_id(&data.device_identifier, &conn).await else {
|
let Some(user) = User::find_by_mail(&data.email, &conn).await else {
|
||||||
err!("Cannot find user. Try again.")
|
err!("Username or password is incorrect. Try again.")
|
||||||
};
|
};
|
||||||
|
|
||||||
if !CONFIG._enable_email_2fa() {
|
if !CONFIG._enable_email_2fa() {
|
||||||
err!("Email 2FA is disabled")
|
err!("Email 2FA is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check password
|
||||||
|
if !user.check_valid_password(&data.master_password_hash) {
|
||||||
|
err!("Username or password is incorrect. Try again.")
|
||||||
|
}
|
||||||
|
|
||||||
send_token(&user.uuid, &conn).await?;
|
send_token(&user.uuid, &conn).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::db::schema::{devices, invitations, sso_users, users};
|
use crate::db::schema::{invitations, sso_users, users};
|
||||||
use chrono::{NaiveDateTime, TimeDelta, Utc};
|
use chrono::{NaiveDateTime, TimeDelta, Utc};
|
||||||
use derive_more::{AsRef, Deref, Display, From};
|
use derive_more::{AsRef, Deref, Display, From};
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
@@ -10,7 +10,6 @@ use super::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
api::EmptyResult,
|
api::EmptyResult,
|
||||||
crypto,
|
crypto,
|
||||||
db::models::DeviceId,
|
|
||||||
db::DbConn,
|
db::DbConn,
|
||||||
error::MapResult,
|
error::MapResult,
|
||||||
sso::OIDCIdentifier,
|
sso::OIDCIdentifier,
|
||||||
@@ -387,17 +386,6 @@ impl User {
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find_by_device_id(device_uuid: &DeviceId, conn: &DbConn) -> Option<Self> {
|
|
||||||
db_run! { conn: {
|
|
||||||
users::table
|
|
||||||
.inner_join(devices::table.on(devices::user_uuid.eq(users::uuid)))
|
|
||||||
.filter(devices::uuid.eq(device_uuid))
|
|
||||||
.select(users::all_columns)
|
|
||||||
.first::<Self>(conn)
|
|
||||||
.ok()
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_all(conn: &DbConn) -> Vec<(Self, Option<SsoUser>)> {
|
pub async fn get_all(conn: &DbConn) -> Vec<(Self, Option<SsoUser>)> {
|
||||||
db_run! { conn: {
|
db_run! { conn: {
|
||||||
users::table
|
users::table
|
||||||
|
|||||||
Reference in New Issue
Block a user