2018-02-14 23:40:34 +00:00
|
|
|
use std::path::Path;
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-02-14 23:53:11 +00:00
|
|
|
use rocket::Data;
|
2018-02-10 00:00:55 +00:00
|
|
|
use rocket::http::ContentType;
|
|
|
|
|
|
|
|
use rocket_contrib::{Json, Value};
|
|
|
|
|
2018-02-14 23:40:34 +00:00
|
|
|
use multipart::server::{Multipart, SaveResult};
|
|
|
|
use multipart::server::save::SavedData;
|
|
|
|
|
|
|
|
use data_encoding::HEXLOWER;
|
2018-02-10 00:00:55 +00:00
|
|
|
|
|
|
|
use db::DbConn;
|
|
|
|
use db::models::*;
|
2018-02-14 23:40:34 +00:00
|
|
|
|
2018-02-10 00:00:55 +00:00
|
|
|
use util;
|
2018-02-14 23:40:34 +00:00
|
|
|
use crypto;
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-02-22 23:38:54 +00:00
|
|
|
use api::{self, PasswordData, JsonResult, EmptyResult};
|
2018-02-10 00:00:55 +00:00
|
|
|
use auth::Headers;
|
|
|
|
|
2018-02-14 23:40:34 +00:00
|
|
|
use CONFIG;
|
|
|
|
|
2018-02-10 00:00:55 +00:00
|
|
|
#[get("/sync")]
|
2018-02-17 19:47:13 +00:00
|
|
|
fn sync(headers: Headers, conn: DbConn) -> JsonResult {
|
2018-02-20 13:09:00 +00:00
|
|
|
let user_json = headers.user.to_json();
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-02-20 13:09:00 +00:00
|
|
|
let folders = Folder::find_by_user(&headers.user.uuid, &conn);
|
2018-02-10 00:00:55 +00:00
|
|
|
let folders_json: Vec<Value> = folders.iter().map(|c| c.to_json()).collect();
|
|
|
|
|
2018-02-20 13:09:00 +00:00
|
|
|
let ciphers = Cipher::find_by_user(&headers.user.uuid, &conn);
|
2018-02-15 00:49:36 +00:00
|
|
|
let ciphers_json: Vec<Value> = ciphers.iter().map(|c| c.to_json(&headers.host, &conn)).collect();
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-02-20 13:09:00 +00:00
|
|
|
let domains_json = api::core::get_eq_domains(headers).unwrap().into_inner();
|
|
|
|
|
2018-02-10 00:00:55 +00:00
|
|
|
Ok(Json(json!({
|
2018-02-20 13:09:00 +00:00
|
|
|
"Profile": user_json,
|
2018-02-10 00:00:55 +00:00
|
|
|
"Folders": folders_json,
|
|
|
|
"Ciphers": ciphers_json,
|
2018-02-20 13:09:00 +00:00
|
|
|
"Domains": domains_json,
|
2018-02-10 00:00:55 +00:00
|
|
|
"Object": "sync"
|
|
|
|
})))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[get("/ciphers")]
|
2018-02-17 19:47:13 +00:00
|
|
|
fn get_ciphers(headers: Headers, conn: DbConn) -> JsonResult {
|
2018-02-10 00:00:55 +00:00
|
|
|
let ciphers = Cipher::find_by_user(&headers.user.uuid, &conn);
|
|
|
|
|
2018-02-15 00:49:36 +00:00
|
|
|
let ciphers_json: Vec<Value> = ciphers.iter().map(|c| c.to_json(&headers.host, &conn)).collect();
|
2018-02-10 00:00:55 +00:00
|
|
|
|
|
|
|
Ok(Json(json!({
|
|
|
|
"Data": ciphers_json,
|
|
|
|
"Object": "list",
|
|
|
|
})))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/ciphers/<uuid>")]
|
2018-02-17 19:47:13 +00:00
|
|
|
fn get_cipher(uuid: String, headers: Headers, conn: DbConn) -> JsonResult {
|
2018-02-10 00:00:55 +00:00
|
|
|
let cipher = match Cipher::find_by_uuid(&uuid, &conn) {
|
|
|
|
Some(cipher) => cipher,
|
|
|
|
None => err!("Cipher doesn't exist")
|
|
|
|
};
|
|
|
|
|
|
|
|
if cipher.user_uuid != headers.user.uuid {
|
2018-02-14 23:40:34 +00:00
|
|
|
err!("Cipher is not owned by user")
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 00:49:36 +00:00
|
|
|
Ok(Json(cipher.to_json(&headers.host, &conn)))
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
struct CipherData {
|
2018-02-22 23:38:54 +00:00
|
|
|
// Folder id is not included in import
|
2018-02-10 00:00:55 +00:00
|
|
|
folderId: Option<String>,
|
2018-02-22 23:38:54 +00:00
|
|
|
// TODO: Some of these might appear all the time, no need for Option
|
2018-02-10 00:00:55 +00:00
|
|
|
organizationId: Option<String>,
|
2018-03-05 23:02:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Login = 1,
|
|
|
|
SecureNote = 2,
|
|
|
|
Card = 3,
|
|
|
|
Identity = 4
|
|
|
|
*/
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
type_: i32,
|
|
|
|
name: String,
|
2018-02-10 00:00:55 +00:00
|
|
|
notes: Option<String>,
|
2018-03-05 23:02:36 +00:00
|
|
|
fields: Option<Value>,
|
2018-02-15 23:32:26 +00:00
|
|
|
|
2018-03-05 23:02:36 +00:00
|
|
|
// Only one of these should exist, depending on type
|
2018-02-10 00:00:55 +00:00
|
|
|
login: Option<Value>,
|
2018-02-15 23:32:26 +00:00
|
|
|
secureNote: Option<Value>,
|
2018-02-10 00:00:55 +00:00
|
|
|
card: Option<Value>,
|
2018-02-15 23:32:26 +00:00
|
|
|
identity: Option<Value>,
|
|
|
|
|
2018-03-05 23:02:36 +00:00
|
|
|
favorite: bool,
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[post("/ciphers", data = "<data>")]
|
2018-02-17 19:47:13 +00:00
|
|
|
fn post_ciphers(data: Json<CipherData>, headers: Headers, conn: DbConn) -> JsonResult {
|
2018-02-17 22:38:55 +00:00
|
|
|
let data: CipherData = data.into_inner();
|
|
|
|
|
2018-02-15 23:32:26 +00:00
|
|
|
let user_uuid = headers.user.uuid.clone();
|
2018-03-05 23:02:36 +00:00
|
|
|
let favorite = data.favorite;
|
|
|
|
let mut cipher = Cipher::new(user_uuid, data.type_, data.name.clone(), favorite);
|
2018-02-15 23:32:26 +00:00
|
|
|
|
2018-02-17 22:38:55 +00:00
|
|
|
update_cipher_from_data(&mut cipher, data, &headers, &conn)?;
|
2018-02-15 23:32:26 +00:00
|
|
|
cipher.save(&conn);
|
|
|
|
|
|
|
|
Ok(Json(cipher.to_json(&headers.host, &conn)))
|
|
|
|
}
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-02-17 22:38:55 +00:00
|
|
|
fn update_cipher_from_data(cipher: &mut Cipher, data: CipherData, headers: &Headers, conn: &DbConn) -> EmptyResult {
|
|
|
|
if let Some(folder_id) = data.folderId {
|
|
|
|
match Folder::find_by_uuid(&folder_id, conn) {
|
2018-02-14 23:40:34 +00:00
|
|
|
Some(folder) => {
|
|
|
|
if folder.user_uuid != headers.user.uuid {
|
|
|
|
err!("Folder is not owned by user")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => err!("Folder doesn't exist")
|
|
|
|
}
|
|
|
|
|
2018-02-17 22:38:55 +00:00
|
|
|
cipher.folder_uuid = Some(folder_id);
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 23:02:36 +00:00
|
|
|
if let org_id @ Some(_) = data.organizationId {
|
2018-02-15 23:32:26 +00:00
|
|
|
// TODO: Check if user in org
|
2018-03-05 23:02:36 +00:00
|
|
|
cipher.organization_uuid = org_id;
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 23:02:36 +00:00
|
|
|
// TODO: ******* Backwards compat start **********
|
|
|
|
// To remove backwards compatibility, just create an empty values object,
|
|
|
|
// and remove the compat code from cipher::to_json
|
2018-02-10 00:00:55 +00:00
|
|
|
let mut values = json!({
|
|
|
|
"Name": data.name,
|
|
|
|
"Notes": data.notes
|
|
|
|
});
|
|
|
|
|
2018-03-05 23:02:36 +00:00
|
|
|
if let Some(ref fields) = data.fields {
|
|
|
|
values["Fields"] = Value::Array(fields.as_array().unwrap().iter().map(|f| {
|
|
|
|
let mut value = json!({});
|
|
|
|
|
|
|
|
// Copy every field object and change the names to the correct case
|
|
|
|
copy_values(&f, &mut value);
|
|
|
|
|
|
|
|
value
|
|
|
|
}).collect());
|
|
|
|
} else {
|
|
|
|
values["Fields"] = Value::Null;
|
|
|
|
}
|
|
|
|
// TODO: ******* Backwards compat end **********
|
|
|
|
|
|
|
|
if let notes @ Some(_) = data.notes {
|
|
|
|
cipher.notes = notes;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(fields) = data.fields {
|
|
|
|
use serde_json::to_string;
|
|
|
|
cipher.fields = to_string(&fields).ok();
|
|
|
|
}
|
|
|
|
|
2018-02-15 23:32:26 +00:00
|
|
|
let type_data_opt = match data.type_ {
|
2018-02-17 22:38:55 +00:00
|
|
|
1 => data.login,
|
|
|
|
2 => data.secureNote,
|
|
|
|
3 => data.card,
|
|
|
|
4 => data.identity,
|
2018-02-15 23:32:26 +00:00
|
|
|
_ => err!("Invalid type")
|
|
|
|
};
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-02-15 23:32:26 +00:00
|
|
|
let type_data = match type_data_opt {
|
|
|
|
Some(data) => data,
|
|
|
|
None => err!("Data missing")
|
|
|
|
};
|
|
|
|
|
|
|
|
// Copy the type data and change the names to the correct case
|
|
|
|
if !copy_values(&type_data, &mut values) {
|
|
|
|
err!("Data invalid")
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 23:32:26 +00:00
|
|
|
cipher.data = values.to_string();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2018-02-10 00:00:55 +00:00
|
|
|
fn copy_values(from: &Value, to: &mut Value) -> bool {
|
|
|
|
let map = match from.as_object() {
|
|
|
|
Some(map) => map,
|
|
|
|
None => return false
|
|
|
|
};
|
|
|
|
|
|
|
|
for (key, val) in map {
|
|
|
|
to[util::upcase_first(key)] = val.clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2018-02-22 23:38:54 +00:00
|
|
|
use super::folders::FolderData;
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
struct ImportData {
|
|
|
|
ciphers: Vec<CipherData>,
|
|
|
|
folders: Vec<FolderData>,
|
|
|
|
folderRelationships: Vec<RelationsData>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
struct RelationsData {
|
|
|
|
// Cipher id
|
|
|
|
key: u32,
|
|
|
|
// Folder id
|
|
|
|
value: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-10 00:00:55 +00:00
|
|
|
#[post("/ciphers/import", data = "<data>")]
|
2018-02-22 23:38:54 +00:00
|
|
|
fn post_ciphers_import(data: Json<ImportData>, headers: Headers, conn: DbConn) -> EmptyResult {
|
|
|
|
let data: ImportData = data.into_inner();
|
2018-02-15 23:32:26 +00:00
|
|
|
|
|
|
|
// Read and create the folders
|
2018-02-22 23:38:54 +00:00
|
|
|
let folders: Vec<_> = data.folders.iter().map(|folder| {
|
|
|
|
let mut folder = Folder::new(headers.user.uuid.clone(), folder.name.clone());
|
2018-02-15 23:32:26 +00:00
|
|
|
folder.save(&conn);
|
|
|
|
folder
|
|
|
|
}).collect();
|
|
|
|
|
|
|
|
// Read the relations between folders and ciphers
|
2018-02-22 23:38:54 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
let mut relations_map = HashMap::new();
|
|
|
|
|
|
|
|
for relation in data.folderRelationships {
|
|
|
|
relations_map.insert(relation.key, relation.value);
|
|
|
|
}
|
2018-02-15 23:32:26 +00:00
|
|
|
|
|
|
|
// Read and create the ciphers
|
2018-02-22 23:38:54 +00:00
|
|
|
let mut index = 0;
|
|
|
|
for cipher_data in data.ciphers {
|
|
|
|
let folder_uuid = relations_map.get(&index)
|
|
|
|
.map(|i| folders[*i as usize].uuid.clone());
|
2018-02-15 23:32:26 +00:00
|
|
|
|
|
|
|
let user_uuid = headers.user.uuid.clone();
|
2018-03-05 23:02:36 +00:00
|
|
|
let favorite = cipher_data.favorite;
|
|
|
|
let mut cipher = Cipher::new(user_uuid, cipher_data.type_, cipher_data.name.clone(), favorite);
|
2018-02-22 23:38:54 +00:00
|
|
|
|
|
|
|
if update_cipher_from_data(&mut cipher, cipher_data, &headers, &conn).is_err() { err!("Error creating cipher") }
|
2018-02-15 23:32:26 +00:00
|
|
|
|
2018-02-22 23:38:54 +00:00
|
|
|
cipher.folder_uuid = folder_uuid;
|
2018-02-15 23:32:26 +00:00
|
|
|
|
|
|
|
cipher.save(&conn);
|
2018-02-22 23:38:54 +00:00
|
|
|
index += 1;
|
|
|
|
}
|
2018-02-15 23:32:26 +00:00
|
|
|
|
|
|
|
Ok(())
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 23:32:26 +00:00
|
|
|
#[post("/ciphers/<uuid>", data = "<data>")]
|
2018-02-17 19:47:13 +00:00
|
|
|
fn post_cipher(uuid: String, data: Json<CipherData>, headers: Headers, conn: DbConn) -> JsonResult {
|
2018-02-15 23:32:26 +00:00
|
|
|
put_cipher(uuid, data, headers, conn)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[put("/ciphers/<uuid>", data = "<data>")]
|
2018-02-17 19:47:13 +00:00
|
|
|
fn put_cipher(uuid: String, data: Json<CipherData>, headers: Headers, conn: DbConn) -> JsonResult {
|
2018-02-17 22:38:55 +00:00
|
|
|
let data: CipherData = data.into_inner();
|
|
|
|
|
2018-02-15 23:32:26 +00:00
|
|
|
let mut cipher = match Cipher::find_by_uuid(&uuid, &conn) {
|
|
|
|
Some(cipher) => cipher,
|
|
|
|
None => err!("Cipher doesn't exist")
|
|
|
|
};
|
|
|
|
|
|
|
|
if cipher.user_uuid != headers.user.uuid {
|
|
|
|
err!("Cipher is not owned by user")
|
|
|
|
}
|
|
|
|
|
2018-03-05 23:02:36 +00:00
|
|
|
cipher.favorite = data.favorite;
|
2018-02-15 23:32:26 +00:00
|
|
|
|
2018-02-17 22:38:55 +00:00
|
|
|
update_cipher_from_data(&mut cipher, data, &headers, &conn)?;
|
2018-02-15 23:32:26 +00:00
|
|
|
cipher.save(&conn);
|
|
|
|
|
|
|
|
Ok(Json(cipher.to_json(&headers.host, &conn)))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-10 00:00:55 +00:00
|
|
|
#[post("/ciphers/<uuid>/attachment", format = "multipart/form-data", data = "<data>")]
|
2018-02-17 19:47:13 +00:00
|
|
|
fn post_attachment(uuid: String, data: Data, content_type: &ContentType, headers: Headers, conn: DbConn) -> JsonResult {
|
2018-02-14 23:40:34 +00:00
|
|
|
let cipher = match Cipher::find_by_uuid(&uuid, &conn) {
|
|
|
|
Some(cipher) => cipher,
|
|
|
|
None => err!("Cipher doesn't exist")
|
|
|
|
};
|
|
|
|
|
|
|
|
if cipher.user_uuid != headers.user.uuid {
|
|
|
|
err!("Cipher is not owned by user")
|
|
|
|
}
|
2018-02-10 00:00:55 +00:00
|
|
|
|
|
|
|
let mut params = content_type.params();
|
2018-02-14 23:40:34 +00:00
|
|
|
let boundary_pair = params.next().expect("No boundary provided");
|
2018-02-10 00:00:55 +00:00
|
|
|
let boundary = boundary_pair.1;
|
|
|
|
|
2018-02-14 23:40:34 +00:00
|
|
|
let base_path = Path::new(&CONFIG.attachments_folder).join(&cipher.uuid);
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-02-14 23:40:34 +00:00
|
|
|
Multipart::with_body(data.open(), boundary).foreach_entry(|mut field| {
|
|
|
|
let name = field.headers.filename.unwrap(); // This is provided by the client, don't trust it
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-02-14 23:40:34 +00:00
|
|
|
let file_name = HEXLOWER.encode(&crypto::get_random(vec![0; 10]));
|
|
|
|
let path = base_path.join(&file_name);
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-02-14 23:40:34 +00:00
|
|
|
let size = match field.data.save()
|
|
|
|
.memory_threshold(0)
|
|
|
|
.size_limit(None)
|
|
|
|
.with_path(path) {
|
2018-02-14 23:53:11 +00:00
|
|
|
SaveResult::Full(SavedData::File(_, size)) => size as i32,
|
2018-02-14 23:40:34 +00:00
|
|
|
_ => return
|
|
|
|
};
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-02-14 23:40:34 +00:00
|
|
|
let attachment = Attachment::new(file_name, cipher.uuid.clone(), name, size);
|
|
|
|
println!("Attachment: {:#?}", attachment);
|
|
|
|
attachment.save(&conn);
|
2018-02-22 23:38:54 +00:00
|
|
|
}).expect("Error processing multipart data");
|
2018-02-14 23:40:34 +00:00
|
|
|
|
2018-02-15 00:49:36 +00:00
|
|
|
Ok(Json(cipher.to_json(&headers.host, &conn)))
|
2018-02-14 23:40:34 +00:00
|
|
|
}
|
|
|
|
|
2018-02-17 22:38:55 +00:00
|
|
|
#[post("/ciphers/<uuid>/attachment/<attachment_id>/delete")]
|
|
|
|
fn delete_attachment_post(uuid: String, attachment_id: String, headers: Headers, conn: DbConn) -> EmptyResult {
|
2018-02-14 23:40:34 +00:00
|
|
|
delete_attachment(uuid, attachment_id, headers, conn)
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[delete("/ciphers/<uuid>/attachment/<attachment_id>")]
|
2018-02-17 19:47:13 +00:00
|
|
|
fn delete_attachment(uuid: String, attachment_id: String, headers: Headers, conn: DbConn) -> EmptyResult {
|
2018-02-14 23:40:34 +00:00
|
|
|
let attachment = match Attachment::find_by_id(&attachment_id, &conn) {
|
|
|
|
Some(attachment) => attachment,
|
|
|
|
None => err!("Attachment doesn't exist")
|
|
|
|
};
|
|
|
|
|
|
|
|
if attachment.cipher_uuid != uuid {
|
|
|
|
err!("Attachment from other cipher")
|
|
|
|
}
|
|
|
|
|
|
|
|
let cipher = match Cipher::find_by_uuid(&uuid, &conn) {
|
|
|
|
Some(cipher) => cipher,
|
|
|
|
None => err!("Cipher doesn't exist")
|
|
|
|
};
|
|
|
|
|
|
|
|
if cipher.user_uuid != headers.user.uuid {
|
|
|
|
err!("Cipher is not owned by user")
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 18:05:57 +00:00
|
|
|
// Delete attachment
|
2018-02-14 23:40:34 +00:00
|
|
|
attachment.delete(&conn);
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-02-14 23:40:34 +00:00
|
|
|
Ok(())
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 23:32:26 +00:00
|
|
|
#[post("/ciphers/<uuid>/delete")]
|
2018-02-17 19:47:13 +00:00
|
|
|
fn delete_cipher_post(uuid: String, headers: Headers, conn: DbConn) -> EmptyResult {
|
2018-02-15 23:32:26 +00:00
|
|
|
delete_cipher(uuid, headers, conn)
|
2018-02-15 18:05:57 +00:00
|
|
|
}
|
2018-02-10 00:00:55 +00:00
|
|
|
|
|
|
|
#[delete("/ciphers/<uuid>")]
|
2018-02-17 19:47:13 +00:00
|
|
|
fn delete_cipher(uuid: String, headers: Headers, conn: DbConn) -> EmptyResult {
|
2018-02-15 18:05:57 +00:00
|
|
|
let cipher = match Cipher::find_by_uuid(&uuid, &conn) {
|
|
|
|
Some(cipher) => cipher,
|
|
|
|
None => err!("Cipher doesn't exist")
|
|
|
|
};
|
|
|
|
|
|
|
|
if cipher.user_uuid != headers.user.uuid {
|
|
|
|
err!("Cipher is not owned by user")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete attachments
|
|
|
|
for a in Attachment::find_by_cipher(&cipher.uuid, &conn) { a.delete(&conn); }
|
|
|
|
|
|
|
|
// Delete cipher
|
|
|
|
cipher.delete(&conn);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-03-05 23:02:36 +00:00
|
|
|
#[post("/ciphers/delete", data = "<data>")]
|
|
|
|
fn delete_cipher_selected(data: Json<Value>, headers: Headers, conn: DbConn) -> EmptyResult {
|
|
|
|
let data: Value = data.into_inner();
|
|
|
|
|
|
|
|
println!("{:#?}", data);
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2018-02-22 23:38:54 +00:00
|
|
|
#[post("/ciphers/purge", data = "<data>")]
|
|
|
|
fn delete_all(data: Json<PasswordData>, headers: Headers, conn: DbConn) -> EmptyResult {
|
|
|
|
let data: PasswordData = data.into_inner();
|
|
|
|
let password_hash = data.masterPasswordHash;
|
2018-02-10 00:00:55 +00:00
|
|
|
|
|
|
|
let user = headers.user;
|
|
|
|
|
2018-02-22 23:38:54 +00:00
|
|
|
if !user.check_valid_password(&password_hash) {
|
2018-02-10 00:00:55 +00:00
|
|
|
err!("Invalid password")
|
|
|
|
}
|
|
|
|
|
2018-02-15 18:05:57 +00:00
|
|
|
// Delete ciphers and their attachments
|
|
|
|
for cipher in Cipher::find_by_user(&user.uuid, &conn) {
|
|
|
|
for a in Attachment::find_by_cipher(&cipher.uuid, &conn) { a.delete(&conn); }
|
2018-02-10 00:00:55 +00:00
|
|
|
|
2018-02-15 18:05:57 +00:00
|
|
|
cipher.delete(&conn);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete folders
|
|
|
|
for f in Folder::find_by_user(&user.uuid, &conn) { f.delete(&conn); }
|
|
|
|
|
|
|
|
Ok(())
|
2018-02-10 00:00:55 +00:00
|
|
|
}
|