@@ -31,111 +31,111 @@ |
||
| 31 | 31 | |
| 32 | 32 | class BackupCodesProvider implements IProvider { |
| 33 | 33 | |
| 34 | - /** @var string */ |
|
| 35 | - private $appName; |
|
| 36 | - |
|
| 37 | - /** @var BackupCodeStorage */ |
|
| 38 | - private $storage; |
|
| 39 | - |
|
| 40 | - /** @var IL10N */ |
|
| 41 | - private $l10n; |
|
| 42 | - |
|
| 43 | - /** @var AppManager */ |
|
| 44 | - private $appManager; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @param string $appName |
|
| 48 | - * @param BackupCodeStorage $storage |
|
| 49 | - * @param IL10N $l10n |
|
| 50 | - * @param AppManager $appManager |
|
| 51 | - */ |
|
| 52 | - public function __construct($appName, BackupCodeStorage $storage, IL10N $l10n, AppManager $appManager) { |
|
| 53 | - $this->appName = $appName; |
|
| 54 | - $this->l10n = $l10n; |
|
| 55 | - $this->storage = $storage; |
|
| 56 | - $this->appManager = $appManager; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Get unique identifier of this 2FA provider |
|
| 61 | - * |
|
| 62 | - * @return string |
|
| 63 | - */ |
|
| 64 | - public function getId() { |
|
| 65 | - return 'backup_codes'; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Get the display name for selecting the 2FA provider |
|
| 70 | - * |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public function getDisplayName() { |
|
| 74 | - return $this->l10n->t('Backup code'); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Get the description for selecting the 2FA provider |
|
| 79 | - * |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function getDescription() { |
|
| 83 | - return $this->l10n->t('Use backup code'); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Get the template for rending the 2FA provider view |
|
| 88 | - * |
|
| 89 | - * @param IUser $user |
|
| 90 | - * @return Template |
|
| 91 | - */ |
|
| 92 | - public function getTemplate(IUser $user) { |
|
| 93 | - $tmpl = new Template('twofactor_backupcodes', 'challenge'); |
|
| 94 | - return $tmpl; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Verify the given challenge |
|
| 99 | - * |
|
| 100 | - * @param IUser $user |
|
| 101 | - * @param string $challenge |
|
| 102 | - */ |
|
| 103 | - public function verifyChallenge(IUser $user, $challenge) { |
|
| 104 | - return $this->storage->validateCode($user, $challenge); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Decides whether 2FA is enabled for the given user |
|
| 109 | - * |
|
| 110 | - * @param IUser $user |
|
| 111 | - * @return boolean |
|
| 112 | - */ |
|
| 113 | - public function isTwoFactorAuthEnabledForUser(IUser $user) { |
|
| 114 | - return $this->storage->hasBackupCodes($user); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Determine whether backup codes should be active or not |
|
| 119 | - * |
|
| 120 | - * Backup codes only make sense if at least one 2FA provider is active, |
|
| 121 | - * hence this method checks all enabled apps on whether they provide 2FA |
|
| 122 | - * functionality or not. If there's at least one app, backup codes are |
|
| 123 | - * enabled on the personal settings page. |
|
| 124 | - * |
|
| 125 | - * @param IUser $user |
|
| 126 | - * @return boolean |
|
| 127 | - */ |
|
| 128 | - public function isActive(IUser $user) { |
|
| 129 | - $appIds = array_filter($this->appManager->getEnabledAppsForUser($user), function($appId) { |
|
| 130 | - return $appId !== $this->appName; |
|
| 131 | - }); |
|
| 132 | - foreach ($appIds as $appId) { |
|
| 133 | - $info = $this->appManager->getAppInfo($appId); |
|
| 134 | - if (isset($info['two-factor-providers']) && count($info['two-factor-providers']) > 0) { |
|
| 135 | - return true; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - return false; |
|
| 139 | - } |
|
| 34 | + /** @var string */ |
|
| 35 | + private $appName; |
|
| 36 | + |
|
| 37 | + /** @var BackupCodeStorage */ |
|
| 38 | + private $storage; |
|
| 39 | + |
|
| 40 | + /** @var IL10N */ |
|
| 41 | + private $l10n; |
|
| 42 | + |
|
| 43 | + /** @var AppManager */ |
|
| 44 | + private $appManager; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @param string $appName |
|
| 48 | + * @param BackupCodeStorage $storage |
|
| 49 | + * @param IL10N $l10n |
|
| 50 | + * @param AppManager $appManager |
|
| 51 | + */ |
|
| 52 | + public function __construct($appName, BackupCodeStorage $storage, IL10N $l10n, AppManager $appManager) { |
|
| 53 | + $this->appName = $appName; |
|
| 54 | + $this->l10n = $l10n; |
|
| 55 | + $this->storage = $storage; |
|
| 56 | + $this->appManager = $appManager; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Get unique identifier of this 2FA provider |
|
| 61 | + * |
|
| 62 | + * @return string |
|
| 63 | + */ |
|
| 64 | + public function getId() { |
|
| 65 | + return 'backup_codes'; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Get the display name for selecting the 2FA provider |
|
| 70 | + * |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public function getDisplayName() { |
|
| 74 | + return $this->l10n->t('Backup code'); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Get the description for selecting the 2FA provider |
|
| 79 | + * |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function getDescription() { |
|
| 83 | + return $this->l10n->t('Use backup code'); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Get the template for rending the 2FA provider view |
|
| 88 | + * |
|
| 89 | + * @param IUser $user |
|
| 90 | + * @return Template |
|
| 91 | + */ |
|
| 92 | + public function getTemplate(IUser $user) { |
|
| 93 | + $tmpl = new Template('twofactor_backupcodes', 'challenge'); |
|
| 94 | + return $tmpl; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Verify the given challenge |
|
| 99 | + * |
|
| 100 | + * @param IUser $user |
|
| 101 | + * @param string $challenge |
|
| 102 | + */ |
|
| 103 | + public function verifyChallenge(IUser $user, $challenge) { |
|
| 104 | + return $this->storage->validateCode($user, $challenge); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Decides whether 2FA is enabled for the given user |
|
| 109 | + * |
|
| 110 | + * @param IUser $user |
|
| 111 | + * @return boolean |
|
| 112 | + */ |
|
| 113 | + public function isTwoFactorAuthEnabledForUser(IUser $user) { |
|
| 114 | + return $this->storage->hasBackupCodes($user); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Determine whether backup codes should be active or not |
|
| 119 | + * |
|
| 120 | + * Backup codes only make sense if at least one 2FA provider is active, |
|
| 121 | + * hence this method checks all enabled apps on whether they provide 2FA |
|
| 122 | + * functionality or not. If there's at least one app, backup codes are |
|
| 123 | + * enabled on the personal settings page. |
|
| 124 | + * |
|
| 125 | + * @param IUser $user |
|
| 126 | + * @return boolean |
|
| 127 | + */ |
|
| 128 | + public function isActive(IUser $user) { |
|
| 129 | + $appIds = array_filter($this->appManager->getEnabledAppsForUser($user), function($appId) { |
|
| 130 | + return $appId !== $this->appName; |
|
| 131 | + }); |
|
| 132 | + foreach ($appIds as $appId) { |
|
| 133 | + $info = $this->appManager->getAppInfo($appId); |
|
| 134 | + if (isset($info['two-factor-providers']) && count($info['two-factor-providers']) > 0) { |
|
| 135 | + return true; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + return false; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | 141 | } |
@@ -10,10 +10,10 @@ |
||
| 10 | 10 | $user = OC::$server->getUserSession()->getUser(); |
| 11 | 11 | |
| 12 | 12 | if ($provider->isActive($user)) { |
| 13 | - $tmpl = new Template('twofactor_backupcodes', 'personal'); |
|
| 14 | - return $tmpl->fetchPage(); |
|
| 13 | + $tmpl = new Template('twofactor_backupcodes', 'personal'); |
|
| 14 | + return $tmpl->fetchPage(); |
|
| 15 | 15 | } else { |
| 16 | - return ""; |
|
| 16 | + return ""; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | // @codeCoverageIgnoreEnd |