Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-11-22 05:10:29 +01:00
Merge pull request #129 from krankur/beta
Implemented PUT for /two-factor/authenticator and /two-factor/disable #124
Dieser Commit ist enthalten in:
Commit
e7e0717f5b
4 geänderte Dateien mit 25 neuen und 68 gelöschten Zeilen
|
@ -87,8 +87,6 @@ fn get_cipher_details(uuid: String, headers: Headers, conn: DbConn) -> JsonResul
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
struct CipherData {
|
struct CipherData {
|
||||||
// Id is optional as it is included only in bulk share
|
|
||||||
Id: Option<String>,
|
|
||||||
// Folder id is not included in import
|
// Folder id is not included in import
|
||||||
FolderId: Option<String>,
|
FolderId: Option<String>,
|
||||||
// TODO: Some of these might appear all the time, no need for Option
|
// TODO: Some of these might appear all the time, no need for Option
|
||||||
|
@ -334,65 +332,6 @@ struct ShareCipherData {
|
||||||
fn post_cipher_share(uuid: String, data: JsonUpcase<ShareCipherData>, headers: Headers, conn: DbConn) -> JsonResult {
|
fn post_cipher_share(uuid: String, data: JsonUpcase<ShareCipherData>, headers: Headers, conn: DbConn) -> JsonResult {
|
||||||
let data: ShareCipherData = data.into_inner().data;
|
let data: ShareCipherData = data.into_inner().data;
|
||||||
|
|
||||||
share_cipher_by_uuid(&uuid, data, &headers, &conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[put("/ciphers/<uuid>/share", data = "<data>")]
|
|
||||||
fn put_cipher_share(uuid: String, data: JsonUpcase<ShareCipherData>, headers: Headers, conn: DbConn) -> JsonResult {
|
|
||||||
let data: ShareCipherData = data.into_inner().data;
|
|
||||||
|
|
||||||
share_cipher_by_uuid(&uuid, data, &headers, &conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
struct ShareSelectedCipherData {
|
|
||||||
Ciphers: Vec<CipherData>,
|
|
||||||
CollectionIds: Vec<String>
|
|
||||||
}
|
|
||||||
|
|
||||||
#[put("/ciphers/share", data = "<data>")]
|
|
||||||
fn put_cipher_share_seleted(data: JsonUpcase<ShareSelectedCipherData>, headers: Headers, conn: DbConn) -> EmptyResult {
|
|
||||||
let mut data: ShareSelectedCipherData = data.into_inner().data;
|
|
||||||
let mut cipher_ids: Vec<String> = Vec::new();
|
|
||||||
|
|
||||||
if data.Ciphers.len() == 0 {
|
|
||||||
err!("You must select at least one cipher.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if data.CollectionIds.len() == 0 {
|
|
||||||
err!("You must select at least one collection.")
|
|
||||||
}
|
|
||||||
|
|
||||||
for cipher in data.Ciphers.iter() {
|
|
||||||
match cipher.Id {
|
|
||||||
Some(ref id) => cipher_ids.push(id.to_string()),
|
|
||||||
None => err!("Request missing ids field")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let attachments = Attachment::find_by_ciphers(cipher_ids, &conn);
|
|
||||||
|
|
||||||
if attachments.len() > 0 {
|
|
||||||
err!("Ciphers should not have any attachments.")
|
|
||||||
}
|
|
||||||
|
|
||||||
while let Some(cipher) = data.Ciphers.pop() {
|
|
||||||
let mut shared_cipher_data = ShareCipherData {
|
|
||||||
Cipher: cipher,
|
|
||||||
CollectionIds: data.CollectionIds.clone()
|
|
||||||
};
|
|
||||||
|
|
||||||
match shared_cipher_data.Cipher.Id.take() {
|
|
||||||
Some(id) => share_cipher_by_uuid(&id, shared_cipher_data , &headers, &conn)?,
|
|
||||||
None => err!("Request missing ids field")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn share_cipher_by_uuid(uuid: &str, data: ShareCipherData, headers: &Headers, conn: &DbConn) -> JsonResult {
|
|
||||||
let mut cipher = match Cipher::find_by_uuid(&uuid, &conn) {
|
let mut cipher = match Cipher::find_by_uuid(&uuid, &conn) {
|
||||||
Some(cipher) => {
|
Some(cipher) => {
|
||||||
if cipher.is_write_accessible_to_user(&headers.user.uuid, &conn) {
|
if cipher.is_write_accessible_to_user(&headers.user.uuid, &conn) {
|
||||||
|
@ -426,6 +365,11 @@ fn share_cipher_by_uuid(uuid: &str, data: ShareCipherData, headers: &Headers, co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[put("/ciphers/<uuid>/share", data = "<data>")]
|
||||||
|
fn put_cipher_share(uuid: String, data: JsonUpcase<ShareCipherData>, headers: Headers, conn: DbConn) -> JsonResult {
|
||||||
|
post_cipher_share(uuid, data, headers, conn)
|
||||||
|
}
|
||||||
|
|
||||||
#[post("/ciphers/<uuid>/attachment", format = "multipart/form-data", data = "<data>")]
|
#[post("/ciphers/<uuid>/attachment", format = "multipart/form-data", data = "<data>")]
|
||||||
fn post_attachment(uuid: String, data: Data, content_type: &ContentType, headers: Headers, conn: DbConn) -> JsonResult {
|
fn post_attachment(uuid: String, data: Data, content_type: &ContentType, headers: Headers, conn: DbConn) -> JsonResult {
|
||||||
let cipher = match Cipher::find_by_uuid(&uuid, &conn) {
|
let cipher = match Cipher::find_by_uuid(&uuid, &conn) {
|
||||||
|
|
|
@ -42,7 +42,6 @@ pub fn routes() -> Vec<Route> {
|
||||||
post_cipher_admin,
|
post_cipher_admin,
|
||||||
post_cipher_share,
|
post_cipher_share,
|
||||||
put_cipher_share,
|
put_cipher_share,
|
||||||
put_cipher_share_seleted,
|
|
||||||
post_cipher,
|
post_cipher,
|
||||||
put_cipher,
|
put_cipher,
|
||||||
delete_cipher_post,
|
delete_cipher_post,
|
||||||
|
@ -66,8 +65,10 @@ pub fn routes() -> Vec<Route> {
|
||||||
get_recover,
|
get_recover,
|
||||||
recover,
|
recover,
|
||||||
disable_twofactor,
|
disable_twofactor,
|
||||||
|
disable_twofactor_put,
|
||||||
generate_authenticator,
|
generate_authenticator,
|
||||||
activate_authenticator,
|
activate_authenticator,
|
||||||
|
activate_authenticator_put,
|
||||||
generate_u2f,
|
generate_u2f,
|
||||||
activate_u2f,
|
activate_u2f,
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,15 @@ fn disable_twofactor(
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[put("/two-factor/disable", data = "<data>")]
|
||||||
|
fn disable_twofactor_put(
|
||||||
|
data: JsonUpcase<DisableTwoFactorData>,
|
||||||
|
headers: Headers,
|
||||||
|
conn: DbConn,
|
||||||
|
) -> JsonResult {
|
||||||
|
disable_twofactor(data, headers, conn)
|
||||||
|
}
|
||||||
|
|
||||||
#[post("/two-factor/get-authenticator", data = "<data>")]
|
#[post("/two-factor/get-authenticator", data = "<data>")]
|
||||||
fn generate_authenticator(
|
fn generate_authenticator(
|
||||||
data: JsonUpcase<PasswordData>,
|
data: JsonUpcase<PasswordData>,
|
||||||
|
@ -194,6 +203,15 @@ fn activate_authenticator(
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[put("/two-factor/authenticator", data = "<data>")]
|
||||||
|
fn activate_authenticator_put(
|
||||||
|
data: JsonUpcase<EnableAuthenticatorData>,
|
||||||
|
headers: Headers,
|
||||||
|
conn: DbConn,
|
||||||
|
) -> JsonResult {
|
||||||
|
activate_authenticator(data, headers, conn)
|
||||||
|
}
|
||||||
|
|
||||||
fn _generate_recover_code(user: &mut User, conn: &DbConn) {
|
fn _generate_recover_code(user: &mut User, conn: &DbConn) {
|
||||||
if user.totp_recover.is_none() {
|
if user.totp_recover.is_none() {
|
||||||
let totp_recover = BASE32.encode(&crypto::get_random(vec![0u8; 20]));
|
let totp_recover = BASE32.encode(&crypto::get_random(vec![0u8; 20]));
|
||||||
|
|
|
@ -111,10 +111,4 @@ impl Attachment {
|
||||||
.filter(attachments::cipher_uuid.eq(cipher_uuid))
|
.filter(attachments::cipher_uuid.eq(cipher_uuid))
|
||||||
.load::<Self>(&**conn).expect("Error loading attachments")
|
.load::<Self>(&**conn).expect("Error loading attachments")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_by_ciphers(cipher_uuids: Vec<String>, conn: &DbConn) -> Vec<Self> {
|
|
||||||
attachments::table
|
|
||||||
.filter(attachments::cipher_uuid.eq_any(cipher_uuids))
|
|
||||||
.load::<Self>(&**conn).expect("Error loading attachments")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Laden …
In neuem Issue referenzieren