mirror of
				https://github.com/dani-garcia/vaultwarden.git
				synced 2025-10-27 16:30:02 +02:00 
			
		
		
		
	Updated bw_rs to Rocket version 0.4-rc1
This commit is contained in:
		| @@ -1,4 +1,4 @@ | ||||
| use rocket_contrib::Json; | ||||
| use rocket_contrib::json::Json; | ||||
|  | ||||
| use db::DbConn; | ||||
| use db::models::*; | ||||
| @@ -9,6 +9,29 @@ use mail; | ||||
|  | ||||
| use CONFIG; | ||||
|  | ||||
| use rocket::Route; | ||||
|  | ||||
| pub fn routes() -> Vec<Route> { | ||||
|     routes![ | ||||
|         register, | ||||
|         profile, | ||||
|         put_profile, | ||||
|         post_profile, | ||||
|         get_public_keys, | ||||
|         post_keys, | ||||
|         post_password, | ||||
|         post_kdf, | ||||
|         post_sstamp, | ||||
|         post_email_token, | ||||
|         post_email, | ||||
|         delete_account, | ||||
|         post_delete_account, | ||||
|         revision_date, | ||||
|         password_hint, | ||||
|         prelogin, | ||||
|     ] | ||||
| } | ||||
|  | ||||
| #[derive(Deserialize, Debug)] | ||||
| #[allow(non_snake_case)] | ||||
| struct RegisterData { | ||||
|   | ||||
| @@ -1,35 +1,75 @@ | ||||
| use std::path::Path; | ||||
| use std::collections::HashSet; | ||||
| use std::path::Path; | ||||
|  | ||||
| use rocket::State; | ||||
| use rocket::Data; | ||||
| use rocket::http::ContentType; | ||||
| use rocket::{request::Form, Data, Route, State}; | ||||
|  | ||||
| use rocket_contrib::{Json, Value}; | ||||
| use rocket_contrib::json::Json; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use multipart::server::{Multipart, SaveResult}; | ||||
| use multipart::server::save::SavedData; | ||||
| use multipart::server::{Multipart, SaveResult}; | ||||
|  | ||||
| use data_encoding::HEXLOWER; | ||||
|  | ||||
| use db::DbConn; | ||||
| use db::models::*; | ||||
| use db::DbConn; | ||||
|  | ||||
| use crypto; | ||||
|  | ||||
| use api::{self, PasswordData, JsonResult, EmptyResult, JsonUpcase, WebSocketUsers, UpdateType}; | ||||
| use api::{self, EmptyResult, JsonResult, JsonUpcase, PasswordData, UpdateType, WebSocketUsers}; | ||||
| use auth::Headers; | ||||
|  | ||||
| use CONFIG; | ||||
|  | ||||
| #[derive(FromForm)] | ||||
| #[allow(non_snake_case)] | ||||
| struct SyncData { | ||||
|     excludeDomains: bool, | ||||
| pub fn routes() -> Vec<Route> { | ||||
|     routes![ | ||||
|         sync, | ||||
|         get_ciphers, | ||||
|         get_cipher, | ||||
|         get_cipher_admin, | ||||
|         get_cipher_details, | ||||
|         post_ciphers, | ||||
|         put_cipher_admin, | ||||
|         post_ciphers_admin, | ||||
|         post_ciphers_import, | ||||
|         post_attachment, | ||||
|         post_attachment_admin, | ||||
|         post_attachment_share, | ||||
|         delete_attachment_post, | ||||
|         delete_attachment_post_admin, | ||||
|         delete_attachment, | ||||
|         delete_attachment_admin, | ||||
|         post_cipher_admin, | ||||
|         post_cipher_share, | ||||
|         put_cipher_share, | ||||
|         put_cipher_share_seleted, | ||||
|         post_cipher, | ||||
|         put_cipher, | ||||
|         delete_cipher_post, | ||||
|         delete_cipher_post_admin, | ||||
|         delete_cipher, | ||||
|         delete_cipher_admin, | ||||
|         delete_cipher_selected, | ||||
|         delete_cipher_selected_post, | ||||
|         delete_all, | ||||
|         move_cipher_selected, | ||||
|         move_cipher_selected_put, | ||||
|  | ||||
|         post_collections_update, | ||||
|         post_collections_admin, | ||||
|         put_collections_admin, | ||||
|     ] | ||||
| } | ||||
|  | ||||
| #[get("/sync?<data>")] | ||||
| fn sync(data: SyncData, headers: Headers, conn: DbConn) -> JsonResult { | ||||
| #[derive(FromForm, Default)] | ||||
| struct SyncData { | ||||
|     #[form(field = "excludeDomains")] | ||||
|     exclude_domains: bool, // Default: 'false' | ||||
| } | ||||
|  | ||||
| #[get("/sync?<data..>")] | ||||
| fn sync(data: Form<SyncData>, headers: Headers, conn: DbConn) -> JsonResult { | ||||
|     let user_json = headers.user.to_json(&conn); | ||||
|  | ||||
|     let folders = Folder::find_by_user(&headers.user.uuid, &conn); | ||||
| @@ -41,7 +81,7 @@ fn sync(data: SyncData, headers: Headers, conn: DbConn) -> JsonResult { | ||||
|     let ciphers = Cipher::find_by_user(&headers.user.uuid, &conn); | ||||
|     let ciphers_json: Vec<Value> = ciphers.iter().map(|c| c.to_json(&headers.host, &headers.user.uuid, &conn)).collect(); | ||||
|  | ||||
|     let domains_json = if data.excludeDomains { Value::Null } else { api::core::get_eq_domains(headers).unwrap().into_inner() }; | ||||
|     let domains_json = if data.exclude_domains { Value::Null } else { api::core::get_eq_domains(headers).unwrap().into_inner() }; | ||||
|  | ||||
|     Ok(Json(json!({ | ||||
|         "Profile": user_json, | ||||
| @@ -53,14 +93,6 @@ fn sync(data: SyncData, headers: Headers, conn: DbConn) -> JsonResult { | ||||
|     }))) | ||||
| } | ||||
|  | ||||
| #[get("/sync")] | ||||
| fn sync_no_query(headers: Headers, conn: DbConn) -> JsonResult { | ||||
|     let sync_data = SyncData { | ||||
|         excludeDomains: false, | ||||
|     }; | ||||
|     sync(sync_data, headers, conn) | ||||
| } | ||||
|  | ||||
| #[get("/ciphers")] | ||||
| fn get_ciphers(headers: Headers, conn: DbConn) -> JsonResult { | ||||
|     let ciphers = Cipher::find_by_user(&headers.user.uuid, &conn); | ||||
| @@ -695,8 +727,7 @@ fn delete_all(data: JsonUpcase<PasswordData>, headers: Headers, conn: DbConn, ws | ||||
|     for f in Folder::find_by_user(&user.uuid, &conn) { | ||||
|         if f.delete(&conn).is_err() { | ||||
|             err!("Failed deleting folder") | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             ws.send_folder_update(UpdateType::SyncFolderCreate, &f); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| use rocket::State; | ||||
| use rocket_contrib::{Json, Value}; | ||||
| use rocket_contrib::json::Json; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use db::DbConn; | ||||
| use db::models::*; | ||||
| @@ -7,6 +8,20 @@ use db::models::*; | ||||
| use api::{JsonResult, EmptyResult, JsonUpcase, WebSocketUsers, UpdateType}; | ||||
| use auth::Headers; | ||||
|  | ||||
| use rocket::Route; | ||||
|  | ||||
| pub fn routes() -> Vec<Route> { | ||||
|     routes![ | ||||
|         get_folders, | ||||
|         get_folder, | ||||
|         post_folders, | ||||
|         post_folder, | ||||
|         put_folder, | ||||
|         delete_folder_post, | ||||
|         delete_folder, | ||||
|     ] | ||||
| } | ||||
|  | ||||
| #[get("/folders")] | ||||
| fn get_folders(headers: Headers, conn: DbConn) -> JsonResult { | ||||
|     let folders = Folder::find_by_user(&headers.user.uuid, &conn); | ||||
|   | ||||
| @@ -4,126 +4,25 @@ mod folders; | ||||
| mod organizations; | ||||
| pub(crate) mod two_factor; | ||||
|  | ||||
| use self::accounts::*; | ||||
| use self::ciphers::*; | ||||
| use self::folders::*; | ||||
| use self::organizations::*; | ||||
| use self::two_factor::*; | ||||
|  | ||||
| pub fn routes() -> Vec<Route> { | ||||
|     routes![ | ||||
|         register, | ||||
|         profile, | ||||
|         put_profile, | ||||
|         post_profile, | ||||
|         get_public_keys, | ||||
|         post_keys, | ||||
|         post_password, | ||||
|         post_kdf, | ||||
|         post_sstamp, | ||||
|         post_email_token, | ||||
|         post_email, | ||||
|         delete_account, | ||||
|         post_delete_account, | ||||
|         revision_date, | ||||
|         password_hint, | ||||
|         prelogin, | ||||
|  | ||||
|         sync, | ||||
|         sync_no_query, | ||||
|  | ||||
|         get_ciphers, | ||||
|         get_cipher, | ||||
|         get_cipher_admin, | ||||
|         get_cipher_details, | ||||
|         post_ciphers, | ||||
|         put_cipher_admin, | ||||
|         post_ciphers_admin, | ||||
|         post_ciphers_import, | ||||
|         post_attachment, | ||||
|         post_attachment_admin, | ||||
|         post_attachment_share, | ||||
|         delete_attachment_post, | ||||
|         delete_attachment_post_admin, | ||||
|         delete_attachment, | ||||
|         delete_attachment_admin, | ||||
|         post_cipher_admin, | ||||
|         post_cipher_share, | ||||
|         put_cipher_share, | ||||
|         put_cipher_share_seleted, | ||||
|         post_cipher, | ||||
|         put_cipher, | ||||
|         delete_cipher_post, | ||||
|         delete_cipher_post_admin, | ||||
|         delete_cipher, | ||||
|         delete_cipher_admin, | ||||
|         delete_cipher_selected, | ||||
|         delete_cipher_selected_post, | ||||
|         delete_all, | ||||
|         move_cipher_selected, | ||||
|         move_cipher_selected_put, | ||||
|  | ||||
|         get_folders, | ||||
|         get_folder, | ||||
|         post_folders, | ||||
|         post_folder, | ||||
|         put_folder, | ||||
|         delete_folder_post, | ||||
|         delete_folder, | ||||
|  | ||||
|         get_twofactor, | ||||
|         get_recover, | ||||
|         recover, | ||||
|         disable_twofactor, | ||||
|         disable_twofactor_put, | ||||
|         generate_authenticator, | ||||
|         activate_authenticator, | ||||
|         activate_authenticator_put, | ||||
|         generate_u2f, | ||||
|         activate_u2f, | ||||
|         activate_u2f_put, | ||||
|  | ||||
|         get_organization, | ||||
|         create_organization, | ||||
|         delete_organization, | ||||
|         post_delete_organization, | ||||
|         leave_organization, | ||||
|         get_user_collections, | ||||
|         get_org_collections, | ||||
|         get_org_collection_detail, | ||||
|         get_collection_users, | ||||
|         put_organization, | ||||
|         post_organization, | ||||
|         post_organization_collections, | ||||
|         delete_organization_collection_user, | ||||
|         post_organization_collection_delete_user, | ||||
|         post_organization_collection_update, | ||||
|         put_organization_collection_update, | ||||
|         delete_organization_collection, | ||||
|         post_organization_collection_delete, | ||||
|         post_collections_update, | ||||
|         post_collections_admin, | ||||
|         put_collections_admin, | ||||
|         get_org_details, | ||||
|         get_org_users, | ||||
|         send_invite, | ||||
|         confirm_invite, | ||||
|         get_user, | ||||
|         edit_user, | ||||
|         put_organization_user, | ||||
|         delete_user, | ||||
|         post_delete_user, | ||||
|         post_reinvite_user, | ||||
|         post_org_import, | ||||
|  | ||||
|     let mut mod_routes = routes![ | ||||
|         clear_device_token, | ||||
|         put_device_token, | ||||
|  | ||||
|         get_eq_domains, | ||||
|         post_eq_domains, | ||||
|         put_eq_domains, | ||||
|     ]; | ||||
|  | ||||
|     ] | ||||
|     let mut routes = Vec::new(); | ||||
|     routes.append(&mut accounts::routes()); | ||||
|     routes.append(&mut ciphers::routes()); | ||||
|     routes.append(&mut folders::routes()); | ||||
|     routes.append(&mut organizations::routes()); | ||||
|     routes.append(&mut two_factor::routes()); | ||||
|     routes.append(&mut mod_routes); | ||||
|  | ||||
|     routes | ||||
| } | ||||
|  | ||||
| /// | ||||
| @@ -132,7 +31,8 @@ pub fn routes() -> Vec<Route> { | ||||
|  | ||||
| use rocket::Route; | ||||
|  | ||||
| use rocket_contrib::{Json, Value}; | ||||
| use rocket_contrib::json::Json; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use db::DbConn; | ||||
| use db::models::*; | ||||
| @@ -141,8 +41,8 @@ use api::{JsonResult, EmptyResult, JsonUpcase}; | ||||
| use auth::Headers; | ||||
|  | ||||
| #[put("/devices/identifier/<uuid>/clear-token", data = "<data>")] | ||||
| fn clear_device_token(uuid: String, data: Json<Value>, headers: Headers, conn: DbConn) -> EmptyResult { | ||||
|     let _data: Value = data.into_inner(); | ||||
| fn clear_device_token(uuid: String, data: JsonUpcase<Value>, headers: Headers, conn: DbConn) -> EmptyResult { | ||||
|     let _data: Value = data.into_inner().data; | ||||
|      | ||||
|     let device = match Device::find_by_uuid(&uuid, &conn) { | ||||
|         Some(device) => device, | ||||
| @@ -160,8 +60,8 @@ fn clear_device_token(uuid: String, data: Json<Value>, headers: Headers, conn: D | ||||
| } | ||||
|  | ||||
| #[put("/devices/identifier/<uuid>/token", data = "<data>")] | ||||
| fn put_device_token(uuid: String, data: Json<Value>, headers: Headers, conn: DbConn) -> JsonResult { | ||||
|     let _data: Value = data.into_inner(); | ||||
| fn put_device_token(uuid: String, data: JsonUpcase<Value>, headers: Headers, conn: DbConn) -> JsonResult { | ||||
|     let _data: Value = data.into_inner().data; | ||||
|      | ||||
|     let device = match Device::find_by_uuid(&uuid, &conn) { | ||||
|         Some(device) => device, | ||||
|   | ||||
| @@ -1,5 +1,8 @@ | ||||
| use rocket::State; | ||||
| use rocket_contrib::{Json, Value}; | ||||
| use rocket::request::Form; | ||||
| use rocket_contrib::json::Json; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use CONFIG; | ||||
| use db::DbConn; | ||||
| use db::models::*; | ||||
| @@ -9,6 +12,42 @@ use auth::{Headers, AdminHeaders, OwnerHeaders}; | ||||
|  | ||||
| use serde::{Deserialize, Deserializer}; | ||||
|  | ||||
| use rocket::Route; | ||||
|  | ||||
| pub fn routes() -> Vec<Route> { | ||||
|     routes![ | ||||
|         get_organization, | ||||
|         create_organization, | ||||
|         delete_organization, | ||||
|         post_delete_organization, | ||||
|         leave_organization, | ||||
|         get_user_collections, | ||||
|         get_org_collections, | ||||
|         get_org_collection_detail, | ||||
|         get_collection_users, | ||||
|         put_organization, | ||||
|         post_organization, | ||||
|         post_organization_collections, | ||||
|         delete_organization_collection_user, | ||||
|         post_organization_collection_delete_user, | ||||
|         post_organization_collection_update, | ||||
|         put_organization_collection_update, | ||||
|         delete_organization_collection, | ||||
|         post_organization_collection_delete, | ||||
|         get_org_details, | ||||
|         get_org_users, | ||||
|         send_invite, | ||||
|         confirm_invite, | ||||
|         get_user, | ||||
|         edit_user, | ||||
|         put_organization_user, | ||||
|         delete_user, | ||||
|         post_delete_user, | ||||
|         post_reinvite_user, | ||||
|         post_org_import, | ||||
|     ] | ||||
| } | ||||
|  | ||||
|  | ||||
| #[derive(Deserialize)] | ||||
| #[allow(non_snake_case)] | ||||
| @@ -315,14 +354,14 @@ fn get_collection_users(org_id: String, coll_id: String, _headers: AdminHeaders, | ||||
| } | ||||
|  | ||||
| #[derive(FromForm)] | ||||
| #[allow(non_snake_case)] | ||||
| struct OrgIdData { | ||||
|     organizationId: String | ||||
|     #[form(field = "organizationId")] | ||||
|     organization_id: String | ||||
| } | ||||
|  | ||||
| #[get("/ciphers/organization-details?<data>")] | ||||
| fn get_org_details(data: OrgIdData, headers: Headers, conn: DbConn) -> JsonResult { | ||||
|     let ciphers = Cipher::find_by_org(&data.organizationId, &conn); | ||||
| #[get("/ciphers/organization-details?<data..>")] | ||||
| fn get_org_details(data: Form<OrgIdData>, headers: Headers, conn: DbConn) -> JsonResult { | ||||
|     let ciphers = Cipher::find_by_org(&data.organization_id, &conn); | ||||
|     let ciphers_json: Vec<Value> = ciphers.iter().map(|c| c.to_json(&headers.host, &headers.user.uuid, &conn)).collect(); | ||||
|  | ||||
|     Ok(Json(json!({ | ||||
| @@ -643,10 +682,10 @@ struct RelationsData { | ||||
|     Value: usize, | ||||
| } | ||||
|  | ||||
| #[post("/ciphers/import-organization?<query>", data = "<data>")] | ||||
| fn post_org_import(query: OrgIdData, data: JsonUpcase<ImportData>, headers: Headers, conn: DbConn, ws: State<WebSocketUsers>) -> EmptyResult { | ||||
| #[post("/ciphers/import-organization?<query..>", data = "<data>")] | ||||
| fn post_org_import(query: Form<OrgIdData>, data: JsonUpcase<ImportData>, headers: Headers, conn: DbConn, ws: State<WebSocketUsers>) -> EmptyResult { | ||||
|     let data: ImportData = data.into_inner().data; | ||||
|     let org_id = query.organizationId; | ||||
|     let org_id = query.into_inner().organization_id; | ||||
|  | ||||
|     let org_user = match UserOrganization::find_by_user_and_org(&headers.user.uuid, &org_id, &conn) { | ||||
|         Some(user) => user, | ||||
| @@ -700,4 +739,4 @@ fn post_org_import(query: OrgIdData, data: JsonUpcase<ImportData>, headers: Head | ||||
|         Ok(()) => Ok(()), | ||||
|         Err(_) => err!("Failed to update the revision, please log out and log back in to finish import.") | ||||
|     } | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,8 @@ | ||||
| use data_encoding::BASE32; | ||||
| use rocket_contrib::{Json, Value}; | ||||
| use rocket_contrib::json::Json; | ||||
| use serde_json; | ||||
| use serde_json::Value; | ||||
|  | ||||
|  | ||||
| use db::{ | ||||
|     models::{TwoFactor, TwoFactorType, User}, | ||||
| @@ -12,6 +14,24 @@ use crypto; | ||||
| use api::{ApiResult, JsonResult, JsonUpcase, NumberOrString, PasswordData}; | ||||
| use auth::Headers; | ||||
|  | ||||
| use rocket::Route; | ||||
|  | ||||
| pub fn routes() -> Vec<Route> { | ||||
|     routes![ | ||||
|         get_twofactor, | ||||
|         get_recover, | ||||
|         recover, | ||||
|         disable_twofactor, | ||||
|         disable_twofactor_put, | ||||
|         generate_authenticator, | ||||
|         activate_authenticator, | ||||
|         activate_authenticator_put, | ||||
|         generate_u2f, | ||||
|         activate_u2f, | ||||
|         activate_u2f_put, | ||||
|     ] | ||||
| } | ||||
|  | ||||
| #[get("/two-factor")] | ||||
| fn get_twofactor(headers: Headers, conn: DbConn) -> JsonResult { | ||||
|     let twofactors = TwoFactor::find_by_user(&headers.user.uuid, &conn); | ||||
|   | ||||
| @@ -4,7 +4,8 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; | ||||
| use rocket::request::{self, Form, FormItems, FromForm, FromRequest, Request}; | ||||
| use rocket::{Outcome, Route}; | ||||
|  | ||||
| use rocket_contrib::{Json, Value}; | ||||
| use rocket_contrib::json::Json; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use num_traits::FromPrimitive; | ||||
|  | ||||
| @@ -21,9 +22,9 @@ pub fn routes() -> Vec<Route> { | ||||
|     routes![login] | ||||
| } | ||||
|  | ||||
| #[post("/connect/token", data = "<connect_data>")] | ||||
| fn login(connect_data: Form<ConnectData>, device_type: DeviceType, conn: DbConn, socket: Option<SocketAddr>) -> JsonResult { | ||||
|     let data = connect_data.get(); | ||||
| #[post("/connect/token", data = "<data>")] | ||||
| fn login(data: Form<ConnectData>, device_type: DeviceType, conn: DbConn, socket: Option<SocketAddr>) -> JsonResult { | ||||
|     let data: ConnectData = data.into_inner(); | ||||
|  | ||||
|     match data.grant_type { | ||||
|         GrantType::RefreshToken => _refresh_login(data, device_type, conn), | ||||
| @@ -31,7 +32,7 @@ fn login(connect_data: Form<ConnectData>, device_type: DeviceType, conn: DbConn, | ||||
|     } | ||||
| } | ||||
|  | ||||
| fn _refresh_login(data: &ConnectData, _device_type: DeviceType, conn: DbConn) -> JsonResult { | ||||
| fn _refresh_login(data: ConnectData, _device_type: DeviceType, conn: DbConn) -> JsonResult { | ||||
|     // Extract token | ||||
|     let token = data.get("refresh_token"); | ||||
|  | ||||
| @@ -59,7 +60,7 @@ fn _refresh_login(data: &ConnectData, _device_type: DeviceType, conn: DbConn) -> | ||||
|     } | ||||
| } | ||||
|  | ||||
| fn _password_login(data: &ConnectData, device_type: DeviceType, conn: DbConn, remote: Option<SocketAddr>) -> JsonResult { | ||||
| fn _password_login(data: ConnectData, device_type: DeviceType, conn: DbConn, remote: Option<SocketAddr>) -> JsonResult { | ||||
|     // Get the ip for error reporting | ||||
|     let ip = match remote { | ||||
|         Some(ip) => ip.ip(), | ||||
| @@ -319,11 +320,9 @@ impl<'f> FromForm<'f> for ConnectData { | ||||
|         let mut data = HashMap::new(); | ||||
|  | ||||
|         // Insert data into map | ||||
|         for (key, value) in items { | ||||
|             match (key.url_decode(), value.url_decode()) { | ||||
|                 (Ok(key), Ok(value)) => data.insert(key.to_lowercase(), value), | ||||
|                 _ => return Err("Error decoding key or value".to_string()), | ||||
|             }; | ||||
|         for item in items { | ||||
|             let (key, value) = item.key_value_decoded(); | ||||
|             data.insert(key.to_lowercase(), value); | ||||
|         } | ||||
|  | ||||
|         // Validate needed values | ||||
|   | ||||
| @@ -12,11 +12,12 @@ pub use self::notifications::routes as notifications_routes; | ||||
| pub use self::notifications::{start_notification_server, WebSocketUsers, UpdateType}; | ||||
|  | ||||
| use rocket::response::status::BadRequest; | ||||
| use rocket_contrib::Json; | ||||
| use rocket_contrib::json::Json; | ||||
| use serde_json::Value; | ||||
|  | ||||
| // Type aliases for API methods results | ||||
| type ApiResult<T> = Result<T, BadRequest<Json>>; | ||||
| type JsonResult = ApiResult<Json>; | ||||
| type ApiResult<T> = Result<T, BadRequest<Json<Value>>>; | ||||
| type JsonResult = ApiResult<Json<Value>>; | ||||
| type EmptyResult = ApiResult<()>; | ||||
|  | ||||
| use util; | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| use rocket::Route; | ||||
| use rocket_contrib::Json; | ||||
| use rocket_contrib::json::Json; | ||||
| use serde_json::Value as JsonValue; | ||||
|  | ||||
| use api::JsonResult; | ||||
|   | ||||
| @@ -6,7 +6,8 @@ use rocket::response::{self, NamedFile, Responder}; | ||||
| use rocket::response::content::Content; | ||||
| use rocket::http::{ContentType, Status}; | ||||
| use rocket::Route; | ||||
| use rocket_contrib::{Json, Value}; | ||||
| use rocket_contrib::json::Json; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use CONFIG; | ||||
|  | ||||
|   | ||||
| @@ -40,7 +40,7 @@ pub fn decode_jwt(token: &str) -> Result<JWTClaims, String> { | ||||
|     let validation = jwt::Validation { | ||||
|         leeway: 30, // 30 seconds | ||||
|         validate_exp: true, | ||||
|         validate_iat: true, | ||||
|         validate_iat: false, // IssuedAt is the same as NotBefore | ||||
|         validate_nbf: true, | ||||
|         aud: None, | ||||
|         iss: Some(JWT_ISSUER.clone()), | ||||
| @@ -197,8 +197,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for OrgHeaders { | ||||
|             Outcome::Success(headers) => { | ||||
|                 // org_id is expected to be the first dynamic param | ||||
|                 match request.get_param::<String>(0) { | ||||
|                     Err(_) => err_handler!("Error getting the organization id"), | ||||
|                     Ok(org_id) => { | ||||
|                     Some(Ok(org_id)) => { | ||||
|                         let conn = match request.guard::<DbConn>() { | ||||
|                             Outcome::Success(conn) => conn, | ||||
|                             _ => err_handler!("Error getting DB") | ||||
| @@ -227,7 +226,8 @@ impl<'a, 'r> FromRequest<'a, 'r> for OrgHeaders { | ||||
|                             user: headers.user, | ||||
|                             org_user_type: org_user.type_, | ||||
|                         }) | ||||
|                     } | ||||
|                     }, | ||||
|                     _ => err_handler!("Error getting the organization id"), | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| use serde_json::Value as JsonValue; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use super::Cipher; | ||||
| use CONFIG; | ||||
| @@ -29,7 +29,7 @@ impl Attachment { | ||||
|         format!("{}/{}/{}", CONFIG.attachments_folder, self.cipher_uuid, self.id) | ||||
|     } | ||||
|  | ||||
|     pub fn to_json(&self, host: &str) -> JsonValue { | ||||
|     pub fn to_json(&self, host: &str) -> Value { | ||||
|         use util::get_display_size; | ||||
|  | ||||
|         let web_path = format!("{}/attachments/{}/{}", host, self.cipher_uuid, self.id); | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| use chrono::{NaiveDateTime, Utc}; | ||||
| use serde_json::Value as JsonValue; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use uuid::Uuid; | ||||
|  | ||||
| @@ -68,23 +68,23 @@ use db::schema::*; | ||||
|  | ||||
| /// Database methods | ||||
| impl Cipher { | ||||
|     pub fn to_json(&self, host: &str, user_uuid: &str, conn: &DbConn) -> JsonValue { | ||||
|     pub fn to_json(&self, host: &str, user_uuid: &str, conn: &DbConn) -> Value { | ||||
|         use serde_json; | ||||
|         use util::format_date; | ||||
|         use super::Attachment; | ||||
|  | ||||
|         let attachments = Attachment::find_by_cipher(&self.uuid, conn); | ||||
|         let attachments_json: Vec<JsonValue> = attachments.iter().map(|c| c.to_json(host)).collect(); | ||||
|         let attachments_json: Vec<Value> = attachments.iter().map(|c| c.to_json(host)).collect(); | ||||
|  | ||||
|         let fields_json: JsonValue = if let Some(ref fields) = self.fields { | ||||
|         let fields_json: Value = if let Some(ref fields) = self.fields { | ||||
|             serde_json::from_str(fields).unwrap() | ||||
|         } else { JsonValue::Null }; | ||||
|         } else { Value::Null }; | ||||
|          | ||||
|         let password_history_json: JsonValue = if let Some(ref password_history) = self.password_history { | ||||
|         let password_history_json: Value = if let Some(ref password_history) = self.password_history { | ||||
|             serde_json::from_str(password_history).unwrap() | ||||
|         } else { JsonValue::Null }; | ||||
|         } else { Value::Null }; | ||||
|  | ||||
|         let mut data_json: JsonValue = serde_json::from_str(&self.data).unwrap(); | ||||
|         let mut data_json: Value = serde_json::from_str(&self.data).unwrap(); | ||||
|  | ||||
|         // TODO: ******* Backwards compat start ********** | ||||
|         // To remove backwards compatibility, just remove this entire section | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| use serde_json::Value as JsonValue; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use uuid::Uuid; | ||||
|  | ||||
| @@ -25,7 +25,7 @@ impl Collection { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     pub fn to_json(&self) -> JsonValue { | ||||
|     pub fn to_json(&self) -> Value { | ||||
|         json!({ | ||||
|             "Id": self.uuid, | ||||
|             "OrganizationId": self.org_uuid, | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| use chrono::{NaiveDateTime, Utc}; | ||||
| use serde_json::Value as JsonValue; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use uuid::Uuid; | ||||
|  | ||||
| @@ -42,7 +42,7 @@ impl Folder { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     pub fn to_json(&self) -> JsonValue { | ||||
|     pub fn to_json(&self) -> Value { | ||||
|         use util::format_date; | ||||
|  | ||||
|         json!({ | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| use serde_json::Value as JsonValue; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use uuid::Uuid; | ||||
| use super::{User, CollectionUser, Invitation}; | ||||
| @@ -70,7 +70,7 @@ impl Organization { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     pub fn to_json(&self) -> JsonValue { | ||||
|     pub fn to_json(&self) -> Value { | ||||
|         json!({ | ||||
|             "Id": self.uuid, | ||||
|             "Name": self.name, | ||||
| @@ -181,7 +181,7 @@ impl Organization { | ||||
| } | ||||
|  | ||||
| impl UserOrganization { | ||||
|     pub fn to_json(&self, conn: &DbConn) -> JsonValue { | ||||
|     pub fn to_json(&self, conn: &DbConn) -> Value { | ||||
|         let org = Organization::find_by_uuid(&self.org_uuid, conn).unwrap(); | ||||
|  | ||||
|         json!({ | ||||
| @@ -209,7 +209,7 @@ impl UserOrganization { | ||||
|         }) | ||||
|     } | ||||
|  | ||||
|     pub fn to_json_user_details(&self, conn: &DbConn) -> JsonValue { | ||||
|     pub fn to_json_user_details(&self, conn: &DbConn) -> Value { | ||||
|         let user = User::find_by_uuid(&self.user_uuid, conn).unwrap(); | ||||
|  | ||||
|         json!({ | ||||
| @@ -226,7 +226,7 @@ impl UserOrganization { | ||||
|         }) | ||||
|     } | ||||
|  | ||||
|     pub fn to_json_collection_user_details(&self, read_only: bool, conn: &DbConn) -> JsonValue { | ||||
|     pub fn to_json_collection_user_details(&self, read_only: bool, conn: &DbConn) -> Value { | ||||
|         let user = User::find_by_uuid(&self.user_uuid, conn).unwrap(); | ||||
|  | ||||
|         json!({ | ||||
| @@ -241,7 +241,7 @@ impl UserOrganization { | ||||
|         }) | ||||
|     } | ||||
|  | ||||
|     pub fn to_json_details(&self, conn: &DbConn) -> JsonValue {         | ||||
|     pub fn to_json_details(&self, conn: &DbConn) -> Value {         | ||||
|         let coll_uuids = if self.access_all {  | ||||
|             vec![] // If we have complete access, no need to fill the array | ||||
|         } else { | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| use serde_json::Value as JsonValue; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use uuid::Uuid; | ||||
|  | ||||
| @@ -59,7 +59,7 @@ impl TwoFactor { | ||||
|         generated == totp_code | ||||
|     } | ||||
|  | ||||
|     pub fn to_json(&self) -> JsonValue { | ||||
|     pub fn to_json(&self) -> Value { | ||||
|         json!({ | ||||
|             "Enabled": self.enabled, | ||||
|             "Key": "", // This key and value vary | ||||
| @@ -67,7 +67,7 @@ impl TwoFactor { | ||||
|         }) | ||||
|     } | ||||
|  | ||||
|     pub fn to_json_list(&self) -> JsonValue { | ||||
|     pub fn to_json_list(&self) -> Value { | ||||
|         json!({ | ||||
|             "Enabled": self.enabled, | ||||
|             "Type": self.type_, | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| use chrono::{NaiveDateTime, Utc}; | ||||
| use serde_json::Value as JsonValue; | ||||
| use serde_json::Value; | ||||
|  | ||||
| use uuid::Uuid; | ||||
|  | ||||
| @@ -120,14 +120,14 @@ use super::{Cipher, Folder, Device, UserOrganization, UserOrgType}; | ||||
|  | ||||
| /// Database methods | ||||
| impl User { | ||||
|     pub fn to_json(&self, conn: &DbConn) -> JsonValue { | ||||
|     pub fn to_json(&self, conn: &DbConn) -> Value { | ||||
|         use super::{UserOrganization, UserOrgType, UserOrgStatus, TwoFactor}; | ||||
|  | ||||
|         let mut orgs = UserOrganization::find_by_user(&self.uuid, conn); | ||||
|         if self.is_server_admin() { | ||||
|             orgs.push(UserOrganization::new_virtual(self.uuid.clone(), UserOrgType::Owner, UserOrgStatus::Confirmed)); | ||||
|         } | ||||
|         let orgs_json: Vec<JsonValue> = orgs.iter().map(|c| c.to_json(&conn)).collect(); | ||||
|         let orgs_json: Vec<Value> = orgs.iter().map(|c| c.to_json(&conn)).collect(); | ||||
|         let twofactor_enabled = !TwoFactor::find_by_user(&self.uuid, conn).is_empty(); | ||||
|  | ||||
|         json!({ | ||||
|   | ||||
| @@ -1,7 +1,8 @@ | ||||
| #![feature(plugin, custom_derive, vec_remove_item, try_trait)] | ||||
| #![plugin(rocket_codegen)] | ||||
| #![feature(proc_macro_hygiene, decl_macro, custom_derive, vec_remove_item, try_trait)] | ||||
| #![recursion_limit="128"] | ||||
| #![allow(proc_macro_derive_resolution_fallback)] // TODO: Remove this when diesel update fixes warnings | ||||
|  | ||||
| #[macro_use] | ||||
| extern crate rocket; | ||||
| extern crate rocket_contrib; | ||||
| extern crate reqwest; | ||||
|   | ||||
| @@ -23,7 +23,7 @@ macro_rules! err { | ||||
| #[macro_export] | ||||
| macro_rules! err_json { | ||||
|     ($expr:expr) => {{ | ||||
|         return Err($crate::rocket::response::status::BadRequest(Some($crate::rocket_contrib::Json($expr)))); | ||||
|         return Err($crate::rocket::response::status::BadRequest(Some($crate::rocket_contrib::json::Json($expr)))); | ||||
|     }} | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user