@@ -34,55 +34,55 @@ |
||
34 | 34 | |
35 | 35 | class ProviderLoader { |
36 | 36 | |
37 | - const BACKUP_CODES_APP_ID = 'twofactor_backupcodes'; |
|
37 | + const BACKUP_CODES_APP_ID = 'twofactor_backupcodes'; |
|
38 | 38 | |
39 | - /** @var IAppManager */ |
|
40 | - private $appManager; |
|
39 | + /** @var IAppManager */ |
|
40 | + private $appManager; |
|
41 | 41 | |
42 | - public function __construct(IAppManager $appManager) { |
|
43 | - $this->appManager = $appManager; |
|
44 | - } |
|
42 | + public function __construct(IAppManager $appManager) { |
|
43 | + $this->appManager = $appManager; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the list of 2FA providers for the given user |
|
48 | - * |
|
49 | - * @return IProvider[] |
|
50 | - * @throws Exception |
|
51 | - */ |
|
52 | - public function getProviders(IUser $user): array { |
|
53 | - $allApps = $this->appManager->getEnabledAppsForUser($user); |
|
54 | - $providers = []; |
|
46 | + /** |
|
47 | + * Get the list of 2FA providers for the given user |
|
48 | + * |
|
49 | + * @return IProvider[] |
|
50 | + * @throws Exception |
|
51 | + */ |
|
52 | + public function getProviders(IUser $user): array { |
|
53 | + $allApps = $this->appManager->getEnabledAppsForUser($user); |
|
54 | + $providers = []; |
|
55 | 55 | |
56 | - foreach ($allApps as $appId) { |
|
57 | - $info = $this->appManager->getAppInfo($appId); |
|
58 | - if (isset($info['two-factor-providers'])) { |
|
59 | - /** @var string[] $providerClasses */ |
|
60 | - $providerClasses = $info['two-factor-providers']; |
|
61 | - foreach ($providerClasses as $class) { |
|
62 | - try { |
|
63 | - $this->loadTwoFactorApp($appId); |
|
64 | - $provider = OC::$server->query($class); |
|
65 | - $providers[$provider->getId()] = $provider; |
|
66 | - } catch (QueryException $exc) { |
|
67 | - // Provider class can not be resolved |
|
68 | - throw new Exception("Could not load two-factor auth provider $class"); |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
72 | - } |
|
56 | + foreach ($allApps as $appId) { |
|
57 | + $info = $this->appManager->getAppInfo($appId); |
|
58 | + if (isset($info['two-factor-providers'])) { |
|
59 | + /** @var string[] $providerClasses */ |
|
60 | + $providerClasses = $info['two-factor-providers']; |
|
61 | + foreach ($providerClasses as $class) { |
|
62 | + try { |
|
63 | + $this->loadTwoFactorApp($appId); |
|
64 | + $provider = OC::$server->query($class); |
|
65 | + $providers[$provider->getId()] = $provider; |
|
66 | + } catch (QueryException $exc) { |
|
67 | + // Provider class can not be resolved |
|
68 | + throw new Exception("Could not load two-factor auth provider $class"); |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - return $providers; |
|
75 | - } |
|
74 | + return $providers; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Load an app by ID if it has not been loaded yet |
|
79 | - * |
|
80 | - * @param string $appId |
|
81 | - */ |
|
82 | - protected function loadTwoFactorApp(string $appId) { |
|
83 | - if (!OC_App::isAppLoaded($appId)) { |
|
84 | - OC_App::loadApp($appId); |
|
85 | - } |
|
86 | - } |
|
77 | + /** |
|
78 | + * Load an app by ID if it has not been loaded yet |
|
79 | + * |
|
80 | + * @param string $appId |
|
81 | + */ |
|
82 | + protected function loadTwoFactorApp(string $appId) { |
|
83 | + if (!OC_App::isAppLoaded($appId)) { |
|
84 | + OC_App::loadApp($appId); |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | 88 | } |
@@ -39,27 +39,27 @@ |
||
39 | 39 | */ |
40 | 40 | interface IRegistry { |
41 | 41 | |
42 | - /** |
|
43 | - * Get a key-value map of providers and their enabled/disabled state for |
|
44 | - * the given user. |
|
45 | - * |
|
46 | - * @since 14.0.0 |
|
47 | - * @return string[] where the array key is the provider ID (string) and the |
|
48 | - * value is the enabled state (bool) |
|
49 | - */ |
|
50 | - public function getProviderStates(IUser $user): array; |
|
42 | + /** |
|
43 | + * Get a key-value map of providers and their enabled/disabled state for |
|
44 | + * the given user. |
|
45 | + * |
|
46 | + * @since 14.0.0 |
|
47 | + * @return string[] where the array key is the provider ID (string) and the |
|
48 | + * value is the enabled state (bool) |
|
49 | + */ |
|
50 | + public function getProviderStates(IUser $user): array; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Enable the given 2FA provider for the given user |
|
54 | - * |
|
55 | - * @since 14.0.0 |
|
56 | - */ |
|
57 | - public function enableProviderFor(IProvider $provider, IUser $user); |
|
52 | + /** |
|
53 | + * Enable the given 2FA provider for the given user |
|
54 | + * |
|
55 | + * @since 14.0.0 |
|
56 | + */ |
|
57 | + public function enableProviderFor(IProvider $provider, IUser $user); |
|
58 | 58 | |
59 | - /** |
|
60 | - * Disable the given 2FA provider for the given user |
|
61 | - * |
|
62 | - * @since 14.0.0 |
|
63 | - */ |
|
64 | - public function disableProviderFor(IProvider $provider, IUser $user); |
|
59 | + /** |
|
60 | + * Disable the given 2FA provider for the given user |
|
61 | + * |
|
62 | + * @since 14.0.0 |
|
63 | + */ |
|
64 | + public function disableProviderFor(IProvider $provider, IUser $user); |
|
65 | 65 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * @copyright 2018 Christoph Wurst <[email protected]> |