vw_small

Hardened fork of Vaultwarden (https://github.com/dani-garcia/vaultwarden) with fewer features.
git clone https://git.philomathiclife.com/repos/vw_small
Log | Files | Refs | README

commit c0ba3406ef4018597cf6d2c4bf22d544c2998036
parent 9ebca9929022eaf1b2ee29f9fa47ad8df03b2c34
Author: Daniel GarcĂ­a <dani-garcia@users.noreply.github.com>
Date:   Thu, 16 Jan 2020 16:21:57 +0100

Merge pull request #812 from swedishborgie/postgresql

Fixes #635 - Unique constraint violation when using U2F tokens on PostgreSQL
Diffstat:
Msrc/db/models/two_factor.rs | 7+++++++
1 file changed, 7 insertions(+), 0 deletions(-)

diff --git a/src/db/models/two_factor.rs b/src/db/models/two_factor.rs @@ -73,6 +73,13 @@ impl TwoFactor { impl TwoFactor { #[cfg(feature = "postgresql")] pub fn save(&self, conn: &DbConn) -> EmptyResult { + // We need to make sure we're not going to violate the unique constraint on user_uuid and atype. + // This happens automatically on other DBMS backends due to replace_into(). PostgreSQL does + // not support multiple constraints on ON CONFLICT clauses. + diesel::delete(twofactor::table.filter(twofactor::user_uuid.eq(&self.user_uuid)).filter(twofactor::atype.eq(&self.atype))) + .execute(&**conn) + .map_res("Error deleting twofactor for insert")?; + diesel::insert_into(twofactor::table) .values(self) .on_conflict(twofactor::uuid)