aboutsummaryrefslogtreecommitdiffstats
path: root/apps/twofactor_backupcodes/lib
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2017-05-02 14:40:44 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2017-05-02 14:40:44 +0200
commitd8b3fe460e8fc12d7611f0e2f3f469e791f4c090 (patch)
tree927396a0a92244288921d717602933c025ee4078 /apps/twofactor_backupcodes/lib
parent94c2f12226ed005fc2a1e9c440ec70346e9c272a (diff)
downloadnextcloud-server-d8b3fe460e8fc12d7611f0e2f3f469e791f4c090.tar.gz
nextcloud-server-d8b3fe460e8fc12d7611f0e2f3f469e791f4c090.zip
Hide 2FA backup codes if no other 2FA providers are enabled
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/twofactor_backupcodes/lib')
-rw-r--r--apps/twofactor_backupcodes/lib/Provider/BackupCodesProvider.php41
1 files changed, 40 insertions, 1 deletions
diff --git a/apps/twofactor_backupcodes/lib/Provider/BackupCodesProvider.php b/apps/twofactor_backupcodes/lib/Provider/BackupCodesProvider.php
index 902f7c783d5..5c5500862e6 100644
--- a/apps/twofactor_backupcodes/lib/Provider/BackupCodesProvider.php
+++ b/apps/twofactor_backupcodes/lib/Provider/BackupCodesProvider.php
@@ -22,6 +22,7 @@
namespace OCA\TwoFactorBackupCodes\Provider;
+use OC\App\AppManager;
use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\IL10N;
@@ -30,15 +31,29 @@ use OCP\Template;
class BackupCodesProvider implements IProvider {
+ /** @var string */
+ private $appName;
+
/** @var BackupCodeStorage */
private $storage;
/** @var IL10N */
private $l10n;
- public function __construct(BackupCodeStorage $storage, IL10N $l10n) {
+ /** @var AppManager */
+ private $appManager;
+
+ /**
+ * @param string $appName
+ * @param BackupCodeStorage $storage
+ * @param IL10N $l10n
+ * @param AppManager $appManager
+ */
+ public function __construct($appName, BackupCodeStorage $storage, IL10N $l10n, AppManager $appManager) {
+ $this->appName = $appName;
$this->l10n = $l10n;
$this->storage = $storage;
+ $this->appManager = $appManager;
}
/**
@@ -99,4 +114,28 @@ class BackupCodesProvider implements IProvider {
return $this->storage->hasBackupCodes($user);
}
+ /**
+ * Determine whether backup codes should be active or not
+ *
+ * Backup codes only make sense if at least one 2FA provider is active,
+ * hence this method checks all enabled apps on whether they provide 2FA
+ * functionality or not. If there's at least one app, backup codes are
+ * enabled on the personal settings page.
+ *
+ * @param IUser $user
+ * @return boolean
+ */
+ public function isActive(IUser $user) {
+ $appIds = array_filter($this->appManager->getEnabledAppsForUser($user), function($appId) {
+ return $appId !== $this->appName;
+ });
+ foreach ($appIds as $appId) {
+ $info = $this->appManager->getAppInfo($appId);
+ if (isset($info['two-factor-providers']) && count($info['two-factor-providers']) > 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
}