From dc1bb6de201738b07286acc4b6a778b2372f3276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Thu, 6 Dec 2018 16:28:36 +0100 Subject: [PATCH] Update device push token methods to more closely follow the official server response --- src/api/core/mod.rs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/api/core/mod.rs b/src/api/core/mod.rs index dcc2821c..d4b4d2e7 100644 --- a/src/api/core/mod.rs +++ b/src/api/core/mod.rs @@ -40,10 +40,8 @@ use db::models::*; use api::{JsonResult, EmptyResult, JsonUpcase}; use auth::Headers; -#[put("/devices/identifier//clear-token", data = "")] -fn clear_device_token(uuid: String, data: JsonUpcase, headers: Headers, conn: DbConn) -> EmptyResult { - let _data: Value = data.into_inner().data; - +#[put("/devices/identifier//clear-token")] +fn clear_device_token(uuid: String, headers: Headers, conn: DbConn) -> EmptyResult { let device = match Device::find_by_uuid(&uuid, &conn) { Some(device) => device, None => err!("Device not found") @@ -53,16 +51,16 @@ fn clear_device_token(uuid: String, data: JsonUpcase, headers: Headers, c err!("Device not owned by user") } - match device.delete(&conn) { - Ok(()) => Ok(()), - Err(_) => err!("Failed deleting device") - } + // This only clears push token + // https://github.com/bitwarden/core/blob/master/src/Api/Controllers/DevicesController.cs#L109 + // https://github.com/bitwarden/core/blob/master/src/Core/Services/Implementations/DeviceService.cs#L37 + Ok(()) } #[put("/devices/identifier//token", data = "")] fn put_device_token(uuid: String, data: JsonUpcase, headers: Headers, conn: DbConn) -> JsonResult { let _data: Value = data.into_inner().data; - + let device = match Device::find_by_uuid(&uuid, &conn) { Some(device) => device, None => err!("Device not found") @@ -72,9 +70,17 @@ fn put_device_token(uuid: String, data: JsonUpcase, headers: Headers, con err!("Device not owned by user") } - // TODO: What does this do? + // This should save the push token, but we don't have push functionality - err!("Not implemented") + use util::format_date; + + Ok(Json(json!({ + "Id": device.uuid, + "Name": device.name, + "Type": device.type_, + "Identifier": device.uuid, + "CreationDate": format_date(&device.created_at), + }))) } #[derive(Serialize, Deserialize, Debug)]