From 60d4b45e8924b2d8ccc2326a1f463ee9dae32905 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 8 Jan 2020 10:51:44 +0100 Subject: Clean up 2FA provider registry when a user is deleted Signed-off-by: Christoph Wurst --- .../TwoFactorAuth/Db/ProviderUserAssignmentDao.php | 9 +++++++++ lib/private/Authentication/TwoFactorAuth/Registry.php | 7 +++++++ 2 files changed, 16 insertions(+) (limited to 'lib/private/Authentication/TwoFactorAuth') diff --git a/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php b/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php index adf16887efa..4e8f9731d94 100644 --- a/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php +++ b/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php @@ -93,6 +93,15 @@ class ProviderUserAssignmentDao { } + public function deleteByUser(string $uid) { + $qb = $this->conn->getQueryBuilder(); + + $deleteQuery = $qb->delete(self::TABLE_NAME) + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))); + + $deleteQuery->execute(); + } + public function deleteAll(string $providerId) { $qb = $this->conn->getQueryBuilder(); diff --git a/lib/private/Authentication/TwoFactorAuth/Registry.php b/lib/private/Authentication/TwoFactorAuth/Registry.php index 151299b28e3..97df2bd5311 100644 --- a/lib/private/Authentication/TwoFactorAuth/Registry.php +++ b/lib/private/Authentication/TwoFactorAuth/Registry.php @@ -66,6 +66,13 @@ class Registry implements IRegistry { $this->dispatcher->dispatch(self::EVENT_PROVIDER_DISABLED, $event); } + /** + * @todo evaluate if we should emit RegistryEvents for each of the deleted rows -> needs documentation + */ + public function deleteUserData(IUser $user): void { + $this->assignmentDao->deleteByUser($user->getUID()); + } + public function cleanUp(string $providerId) { $this->assignmentDao->deleteAll($providerId); } -- cgit v1.2.3