2018-02-10 01:00:55 +01:00
|
|
|
mod accounts;
|
|
|
|
mod ciphers;
|
|
|
|
mod folders;
|
2018-02-17 22:30:19 +01:00
|
|
|
mod organizations;
|
2018-02-10 01:00:55 +01:00
|
|
|
mod two_factor;
|
|
|
|
|
|
|
|
use self::accounts::*;
|
|
|
|
use self::ciphers::*;
|
|
|
|
use self::folders::*;
|
2018-02-17 22:30:19 +01:00
|
|
|
use self::organizations::*;
|
2018-02-10 01:00:55 +01:00
|
|
|
use self::two_factor::*;
|
|
|
|
|
|
|
|
pub fn routes() -> Vec<Route> {
|
|
|
|
routes![
|
|
|
|
register,
|
|
|
|
profile,
|
|
|
|
post_keys,
|
|
|
|
post_password,
|
|
|
|
post_sstamp,
|
|
|
|
post_email,
|
|
|
|
delete_account,
|
|
|
|
revision_date,
|
|
|
|
|
|
|
|
sync,
|
|
|
|
|
|
|
|
get_ciphers,
|
|
|
|
get_cipher,
|
|
|
|
post_ciphers,
|
|
|
|
post_ciphers_import,
|
|
|
|
post_attachment,
|
2018-02-15 00:40:34 +01:00
|
|
|
delete_attachment_post,
|
2018-02-10 01:00:55 +01:00
|
|
|
delete_attachment,
|
|
|
|
post_cipher,
|
|
|
|
put_cipher,
|
2018-02-16 00:32:26 +01:00
|
|
|
delete_cipher_post,
|
2018-03-06 00:02:36 +01:00
|
|
|
delete_cipher,
|
|
|
|
delete_cipher_selected,
|
2018-02-10 01:00:55 +01:00
|
|
|
delete_all,
|
|
|
|
|
|
|
|
get_folders,
|
|
|
|
get_folder,
|
|
|
|
post_folders,
|
|
|
|
post_folder,
|
|
|
|
put_folder,
|
|
|
|
delete_folder_post,
|
|
|
|
delete_folder,
|
|
|
|
|
|
|
|
get_twofactor,
|
|
|
|
get_recover,
|
2018-02-15 19:05:57 +01:00
|
|
|
recover,
|
2018-02-10 01:00:55 +01:00
|
|
|
generate_authenticator,
|
|
|
|
activate_authenticator,
|
|
|
|
disable_authenticator,
|
|
|
|
|
2018-02-17 22:30:19 +01:00
|
|
|
get_user_collections,
|
2018-02-10 01:00:55 +01:00
|
|
|
|
|
|
|
clear_device_token,
|
|
|
|
put_device_token,
|
|
|
|
|
|
|
|
get_eq_domains,
|
|
|
|
post_eq_domains
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Move this somewhere else
|
|
|
|
///
|
|
|
|
|
|
|
|
use rocket::Route;
|
|
|
|
|
2018-02-23 00:38:54 +01:00
|
|
|
use rocket_contrib::Json;
|
2018-02-10 01:00:55 +01:00
|
|
|
|
|
|
|
use db::DbConn;
|
|
|
|
|
2018-02-17 23:21:04 +01:00
|
|
|
use api::{JsonResult, EmptyResult};
|
2018-02-10 01:00:55 +01:00
|
|
|
use auth::Headers;
|
|
|
|
|
|
|
|
#[put("/devices/identifier/<uuid>/clear-token")]
|
2018-02-17 20:47:13 +01:00
|
|
|
fn clear_device_token(uuid: String, conn: DbConn) -> JsonResult {
|
|
|
|
err!("Not implemented")
|
|
|
|
}
|
2018-02-10 01:00:55 +01:00
|
|
|
|
|
|
|
#[put("/devices/identifier/<uuid>/token")]
|
2018-02-17 20:47:13 +01:00
|
|
|
fn put_device_token(uuid: String, conn: DbConn) -> JsonResult {
|
|
|
|
err!("Not implemented")
|
|
|
|
}
|
2018-02-10 01:00:55 +01:00
|
|
|
|
2018-02-17 23:21:04 +01:00
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
struct GlobalDomain {
|
|
|
|
Type: i32,
|
|
|
|
Domains: Vec<String>,
|
|
|
|
Excluded: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
const GLOBAL_DOMAINS: &'static str = include_str!("global_domains.json");
|
|
|
|
|
2018-02-10 01:00:55 +01:00
|
|
|
#[get("/settings/domains")]
|
2018-02-20 14:09:00 +01:00
|
|
|
fn get_eq_domains(headers: Headers) -> JsonResult {
|
2018-02-17 23:21:04 +01:00
|
|
|
let user = headers.user;
|
|
|
|
use serde_json::from_str;
|
|
|
|
|
|
|
|
let equivalent_domains: Vec<Vec<String>> = from_str(&user.equivalent_domains).unwrap();
|
|
|
|
let excluded_globals: Vec<i32> = from_str(&user.excluded_globals).unwrap();
|
|
|
|
|
|
|
|
let mut globals: Vec<GlobalDomain> = from_str(GLOBAL_DOMAINS).unwrap();
|
|
|
|
|
|
|
|
for global in &mut globals {
|
|
|
|
global.Excluded = excluded_globals.contains(&global.Type);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(Json(json!({
|
|
|
|
"EquivalentDomains": equivalent_domains,
|
2018-02-20 14:09:00 +01:00
|
|
|
"GlobalEquivalentDomains": globals,
|
|
|
|
"Object": "domains",
|
2018-02-17 23:21:04 +01:00
|
|
|
})))
|
2018-02-10 01:00:55 +01:00
|
|
|
}
|
|
|
|
|
2018-02-23 00:38:54 +01:00
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
struct EquivDomainData {
|
|
|
|
ExcludedGlobalEquivalentDomains: Option<Vec<i32>>,
|
|
|
|
EquivalentDomains: Option<Vec<Vec<String>>>,
|
|
|
|
}
|
|
|
|
|
2018-02-15 00:40:34 +01:00
|
|
|
#[post("/settings/domains", data = "<data>")]
|
2018-02-17 23:21:04 +01:00
|
|
|
fn post_eq_domains(data: Json<EquivDomainData>, headers: Headers, conn: DbConn) -> EmptyResult {
|
|
|
|
let data: EquivDomainData = data.into_inner();
|
2018-02-15 00:40:34 +01:00
|
|
|
|
2018-02-17 23:21:04 +01:00
|
|
|
let excluded_globals = data.ExcludedGlobalEquivalentDomains.unwrap_or(Vec::new());
|
|
|
|
let equivalent_domains = data.EquivalentDomains.unwrap_or(Vec::new());
|
2018-02-15 00:40:34 +01:00
|
|
|
|
2018-02-17 23:21:04 +01:00
|
|
|
let mut user = headers.user;
|
|
|
|
use serde_json::to_string;
|
2018-02-15 00:40:34 +01:00
|
|
|
|
2018-02-17 23:21:04 +01:00
|
|
|
user.excluded_globals = to_string(&excluded_globals).unwrap_or("[]".to_string());
|
|
|
|
user.equivalent_domains = to_string(&equivalent_domains).unwrap_or("[]".to_string());
|
|
|
|
|
|
|
|
user.save(&conn);
|
|
|
|
|
|
|
|
Ok(())
|
2018-02-10 01:00:55 +01:00
|
|
|
}
|