chore: format code

This commit is contained in:
qaz741wsd856 2025-12-29 10:19:39 +00:00
parent 453d24cade
commit fcbfb928f7
4 changed files with 13 additions and 14 deletions

View file

@ -12,8 +12,7 @@ use crate::{
db, db,
error::AppError, error::AppError,
handlers::{ handlers::{
allow_totp_drift, allow_totp_drift, server_password_iterations,
server_password_iterations,
twofactor::{is_twofactor_enabled, list_user_twofactors}, twofactor::{is_twofactor_enabled, list_user_twofactors},
}, },
models::twofactor::{RememberTokenData, TwoFactor, TwoFactorType}, models::twofactor::{RememberTokenData, TwoFactor, TwoFactorType},
@ -267,7 +266,9 @@ pub async fn token(
Some(code) => code, Some(code) => code,
None => { None => {
// Return 2FA required error // Return 2FA required error
return Err(AppError::TwoFactorRequired(json_err_twofactor(&twofactor_ids))); return Err(AppError::TwoFactorRequired(json_err_twofactor(
&twofactor_ids,
)));
} }
}; };
@ -278,7 +279,9 @@ pub async fn token(
.find(|tf| { .find(|tf| {
tf.enabled && tf.atype == TwoFactorType::Authenticator as i32 tf.enabled && tf.atype == TwoFactorType::Authenticator as i32
}) })
.ok_or_else(|| AppError::BadRequest("TOTP not configured".to_string()))?; .ok_or_else(|| {
AppError::BadRequest("TOTP not configured".to_string())
})?;
// Validate TOTP code // Validate TOTP code
let allow_drift = allow_totp_drift(&env); let allow_drift = allow_totp_drift(&env);

View file

@ -19,9 +19,7 @@ pub async fn now() -> Json<String> {
/// ///
/// Simple healthcheck. Vaultwarden uses this to also verify DB connectivity. /// Simple healthcheck. Vaultwarden uses this to also verify DB connectivity.
#[worker::send] #[worker::send]
pub async fn alive( pub async fn alive(State(env): State<Arc<Env>>) -> Result<Json<String>, AppError> {
State(env): State<Arc<Env>>,
) -> Result<Json<String>, AppError> {
// Verify D1 binding is present + basic query works. // Verify D1 binding is present + basic query works.
let db = db::get_db(&env)?; let db = db::get_db(&env)?;
db.prepare("SELECT 1 as ok") db.prepare("SELECT 1 as ok")
@ -54,5 +52,3 @@ pub struct HibpBreachQuery {
pub async fn hibp_breach(_query: axum::extract::Query<HibpBreachQuery>) -> Json<Value> { pub async fn hibp_breach(_query: axum::extract::Query<HibpBreachQuery>) -> Json<Value> {
Json(json!([])) Json(json!([]))
} }

View file

@ -35,9 +35,9 @@ pub(crate) async fn list_user_twofactors(
/// For now, we intentionally only treat Authenticator (TOTP) as a real 2FA provider. /// For now, we intentionally only treat Authenticator (TOTP) as a real 2FA provider.
/// Remember-device tokens are never considered a 2FA method by themselves. /// Remember-device tokens are never considered a 2FA method by themselves.
pub(crate) fn is_twofactor_enabled(twofactors: &[TwoFactor]) -> bool { pub(crate) fn is_twofactor_enabled(twofactors: &[TwoFactor]) -> bool {
twofactors.iter().any(|tf| { twofactors
tf.enabled && tf.atype == TwoFactorType::Authenticator as i32 .iter()
}) .any(|tf| tf.enabled && tf.atype == TwoFactorType::Authenticator as i32)
} }
/// GET /api/two-factor - Get all enabled 2FA providers for current user /// GET /api/two-factor - Get all enabled 2FA providers for current user

View file

@ -6,8 +6,8 @@ use std::sync::Arc;
use worker::Env; use worker::Env;
use crate::handlers::{ use crate::handlers::{
accounts, attachments, ciphers, config, devices, domains, emergency_access, folders, identity, import, accounts, attachments, ciphers, config, devices, domains, emergency_access, folders, identity,
meta, sync, twofactor, webauth, import, meta, sync, twofactor, webauth,
}; };
pub fn api_router(env: Env) -> Router { pub fn api_router(env: Env) -> Router {