Browse Source

Disable Login with device if push is not enabled

pull/4577/head
Timshel 11 months ago
parent
commit
6454c7eea9
  1. 20
      src/api/core/accounts.rs

20
src/api/core/accounts.rs

@ -50,7 +50,6 @@ pub fn routes() -> Vec<rocket::Route> {
api_key, api_key,
rotate_api_key, rotate_api_key,
get_known_device, get_known_device,
get_known_device_from_path,
put_avatar, put_avatar,
put_device_token, put_device_token,
put_clear_device_token, put_clear_device_token,
@ -979,20 +978,17 @@ async fn rotate_api_key(data: JsonUpcase<PasswordOrOtpData>, headers: Headers, c
_api_key(data, true, headers, conn).await _api_key(data, true, headers, conn).await
} }
// This variant is deprecated: https://github.com/bitwarden/server/pull/2682 // ATM only used to toggle Login with device
#[get("/devices/knowndevice/<email>/<uuid>")] // Without push it's not working so always return false
async fn get_known_device_from_path(email: &str, uuid: &str, mut conn: DbConn) -> JsonResult { #[get("/devices/knowndevice")]
// This endpoint doesn't have auth header async fn get_known_device(device: KnownDevice, mut conn: DbConn) -> JsonResult {
let mut result = false; let mut result = false;
if let Some(user) = User::find_by_mail(email, &mut conn).await { if CONFIG.push_enabled() {
result = Device::find_by_uuid_and_user(uuid, &user.uuid, &mut conn).await.is_some(); if let Some(user) = User::find_by_mail(&device.email, &mut conn).await {
result = Device::find_by_uuid_and_user(&device.uuid, &user.uuid, &mut conn).await.is_some();
} }
Ok(Json(json!(result)))
} }
Ok(Json(json!(result)))
#[get("/devices/knowndevice")]
async fn get_known_device(device: KnownDevice, conn: DbConn) -> JsonResult {
get_known_device_from_path(&device.email, &device.uuid, conn).await
} }
struct KnownDevice { struct KnownDevice {

Loading…
Cancel
Save