diff options
author | Daniel García <[email protected]> | 2019-02-16 21:30:55 +0100 |
---|---|---|
committer | Daniel García <[email protected]> | 2019-02-16 21:30:55 +0100 |
commit | 93805a5d7bb32c1f3c2168cfa73b60593dfeb53e (patch) | |
tree | a37dc9fdd883d235d6758200c8ed9d993e0fde6d /src | |
parent | 71da961ecdb4ea8581227e387f986df554c57410 (diff) | |
download | vaultwarden-93805a5d7bb32c1f3c2168cfa73b60593dfeb53e.tar.gz vaultwarden-93805a5d7bb32c1f3c2168cfa73b60593dfeb53e.zip |
Fix Yubikeys deleted on error
Diffstat (limited to 'src')
-rw-r--r-- | src/api/core/two_factor.rs | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/api/core/two_factor.rs b/src/api/core/two_factor.rs index 7c35c7ae..e797c506 100644 --- a/src/api/core/two_factor.rs +++ b/src/api/core/two_factor.rs @@ -573,11 +573,10 @@ fn activate_yubikey(data: JsonUpcase<EnableYubikeyData>, headers: Headers, conn: } // Check if we already have some data - let yubikey_data = TwoFactor::find_by_user_and_type(&user.uuid, TwoFactorType::YubiKey as i32, &conn); - - if let Some(yubikey_data) = yubikey_data { - yubikey_data.delete(&conn)?; - } + let mut yubikey_data = match TwoFactor::find_by_user_and_type(&user.uuid, TwoFactorType::YubiKey as i32, &conn) { + Some(data) => data, + None => TwoFactor::new(user.uuid.clone(), TwoFactorType::YubiKey, String::new()), + }; let yubikeys = parse_yubikeys(&data); @@ -605,12 +604,8 @@ fn activate_yubikey(data: JsonUpcase<EnableYubikeyData>, headers: Headers, conn: Nfc: data.Nfc, }; - let yubikey_registration = TwoFactor::new( - user.uuid.clone(), - TwoFactorType::YubiKey, - serde_json::to_string(&yubikey_metadata).unwrap(), - ); - yubikey_registration.save(&conn)?; + yubikey_data.data = serde_json::to_string(&yubikey_metadata).unwrap(); + yubikey_data.save(&conn)?; _generate_recover_code(&mut user, &conn); |