summaryrefslogtreecommitdiffstats
path: root/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-08-13 07:25:01 +0200
committerGitHub <noreply@github.com>2020-08-13 07:25:01 +0200
commit725fecee3454dd1fabe1b373a8c9a37f81040fd9 (patch)
tree8928539bdd919e25295ebd7b0b15ce0828b4ee75 /lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php
parent3a39f2ae9165fdbf98ad9fafcb52d7dde7f75df8 (diff)
parent68794ebc9292cdedaa6a52d190e41e58f6edb1ba (diff)
downloadnextcloud-server-725fecee3454dd1fabe1b373a8c9a37f81040fd9.tar.gz
nextcloud-server-725fecee3454dd1fabe1b373a8c9a37f81040fd9.zip
Merge pull request #21344 from nextcloud/fix/twofactor-cleanup-event
Emit an event for every disabled 2FA provider during cleanup
Diffstat (limited to 'lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php')
-rw-r--r--lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php35
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php b/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php
index 02e6863d1c4..bd8ff0353ee 100644
--- a/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php
+++ b/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php
@@ -29,6 +29,7 @@ namespace OC\Authentication\TwoFactorAuth\Db;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
+use function array_map;
/**
* Data access object to query and assign (provider_id, uid, enabled) tuples of
@@ -91,13 +92,35 @@ 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)));
-
+ /**
+ * Delete all provider states of a user and return the provider IDs
+ *
+ * @param string $uid
+ *
+ * @return int[]
+ */
+ public function deleteByUser(string $uid): array {
+ $qb1 = $this->conn->getQueryBuilder();
+ $selectQuery = $qb1->select('*')
+ ->from(self::TABLE_NAME)
+ ->where($qb1->expr()->eq('uid', $qb1->createNamedParameter($uid)));
+ $selectResult = $selectQuery->execute();
+ $rows = $selectResult->fetchAll();
+ $selectResult->closeCursor();
+
+ $qb2 = $this->conn->getQueryBuilder();
+ $deleteQuery = $qb2
+ ->delete(self::TABLE_NAME)
+ ->where($qb2->expr()->eq('uid', $qb2->createNamedParameter($uid)));
$deleteQuery->execute();
+
+ return array_map(function (array $row) {
+ return [
+ 'provider_id' => $row['provider_id'],
+ 'uid' => $row['uid'],
+ 'enabled' => 1 === (int) $row['enabled'],
+ ];
+ }, $rows);
}
public function deleteAll(string $providerId) {