@@ -31,22 +31,22 @@ |
||
| 31 | 31 | use OCP\Migration\SimpleMigrationStep; |
| 32 | 32 | |
| 33 | 33 | class Version21000Date20210309185127 extends SimpleMigrationStep { |
| 34 | - /** |
|
| 35 | - * @param IOutput $output |
|
| 36 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 37 | - * @param array $options |
|
| 38 | - * @return null|ISchemaWrapper |
|
| 39 | - */ |
|
| 40 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
| 41 | - /** @var ISchemaWrapper $schema */ |
|
| 42 | - $schema = $schemaClosure(); |
|
| 34 | + /** |
|
| 35 | + * @param IOutput $output |
|
| 36 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 37 | + * @param array $options |
|
| 38 | + * @return null|ISchemaWrapper |
|
| 39 | + */ |
|
| 40 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
| 41 | + /** @var ISchemaWrapper $schema */ |
|
| 42 | + $schema = $schemaClosure(); |
|
| 43 | 43 | |
| 44 | - $table = $schema->getTable('known_users'); |
|
| 45 | - if (!$table->hasIndex('ku_known_user')) { |
|
| 46 | - $table->addIndex(['known_user'], 'ku_known_user'); |
|
| 47 | - return $schema; |
|
| 48 | - } |
|
| 44 | + $table = $schema->getTable('known_users'); |
|
| 45 | + if (!$table->hasIndex('ku_known_user')) { |
|
| 46 | + $table->addIndex(['known_user'], 'ku_known_user'); |
|
| 47 | + return $schema; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return null; |
|
| 51 | - } |
|
| 50 | + return null; |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -43,6 +43,6 @@ |
||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | public function getData(): int { |
| 46 | - return (int)$this->config->getAppValue('comments', 'maxAutoCompleteResults', '10'); |
|
| 46 | + return (int) $this->config->getAppValue('comments', 'maxAutoCompleteResults', '10'); |
|
| 47 | 47 | } |
| 48 | 48 | } |
@@ -12,16 +12,16 @@ |
||
| 12 | 12 | use OCP\IConfig; |
| 13 | 13 | |
| 14 | 14 | class MaxAutoCompleteResultsInitialState extends InitialStateProvider { |
| 15 | - public function __construct( |
|
| 16 | - private IConfig $config, |
|
| 17 | - ) { |
|
| 18 | - } |
|
| 15 | + public function __construct( |
|
| 16 | + private IConfig $config, |
|
| 17 | + ) { |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - public function getKey(): string { |
|
| 21 | - return 'maxAutoCompleteResults'; |
|
| 22 | - } |
|
| 20 | + public function getKey(): string { |
|
| 21 | + return 'maxAutoCompleteResults'; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function getData(): int { |
|
| 25 | - return (int)$this->config->getAppValue('comments', 'maxAutoCompleteResults', '10'); |
|
| 26 | - } |
|
| 24 | + public function getData(): int { |
|
| 25 | + return (int)$this->config->getAppValue('comments', 'maxAutoCompleteResults', '10'); |
|
| 26 | + } |
|
| 27 | 27 | } |
@@ -36,27 +36,27 @@ |
||
| 36 | 36 | |
| 37 | 37 | class Version1002Date20170919123342 extends SimpleMigrationStep { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param IOutput $output |
|
| 41 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 42 | - * @param array $options |
|
| 43 | - * @return null|ISchemaWrapper |
|
| 44 | - * @since 13.0.0 |
|
| 45 | - */ |
|
| 46 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 47 | - /** @var ISchemaWrapper $schema */ |
|
| 48 | - $schema = $schemaClosure(); |
|
| 49 | - |
|
| 50 | - $table = $schema->getTable('twofactor_backupcodes'); |
|
| 51 | - $column = $table->getColumn('user_id'); |
|
| 52 | - $column->setDefault(''); |
|
| 53 | - |
|
| 54 | - $column = $table->getColumn('used'); |
|
| 55 | - if ($column->getType()->getName() !== Types::SMALLINT) { |
|
| 56 | - $column->setType(Type::getType(Types::SMALLINT)); |
|
| 57 | - $column->setOptions(['length' => 6]); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - return $schema; |
|
| 61 | - } |
|
| 39 | + /** |
|
| 40 | + * @param IOutput $output |
|
| 41 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 42 | + * @param array $options |
|
| 43 | + * @return null|ISchemaWrapper |
|
| 44 | + * @since 13.0.0 |
|
| 45 | + */ |
|
| 46 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 47 | + /** @var ISchemaWrapper $schema */ |
|
| 48 | + $schema = $schemaClosure(); |
|
| 49 | + |
|
| 50 | + $table = $schema->getTable('twofactor_backupcodes'); |
|
| 51 | + $column = $table->getColumn('user_id'); |
|
| 52 | + $column->setDefault(''); |
|
| 53 | + |
|
| 54 | + $column = $table->getColumn('used'); |
|
| 55 | + if ($column->getType()->getName() !== Types::SMALLINT) { |
|
| 56 | + $column->setType(Type::getType(Types::SMALLINT)); |
|
| 57 | + $column->setOptions(['length' => 6]); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + return $schema; |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -6,51 +6,51 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ComposerStaticInitTwoFactorBackupCodes |
| 8 | 8 | { |
| 9 | - public static $prefixLengthsPsr4 = array ( |
|
| 9 | + public static $prefixLengthsPsr4 = array( |
|
| 10 | 10 | 'O' => |
| 11 | - array ( |
|
| 11 | + array( |
|
| 12 | 12 | 'OCA\\TwoFactorBackupCodes\\' => 25, |
| 13 | 13 | ), |
| 14 | 14 | ); |
| 15 | 15 | |
| 16 | - public static $prefixDirsPsr4 = array ( |
|
| 16 | + public static $prefixDirsPsr4 = array( |
|
| 17 | 17 | 'OCA\\TwoFactorBackupCodes\\' => |
| 18 | - array ( |
|
| 19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
| 18 | + array( |
|
| 19 | + 0 => __DIR__.'/..'.'/../lib', |
|
| 20 | 20 | ), |
| 21 | 21 | ); |
| 22 | 22 | |
| 23 | - public static $classMap = array ( |
|
| 24 | - 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', |
|
| 25 | - 'OCA\\TwoFactorBackupCodes\\Activity\\Provider' => __DIR__ . '/..' . '/../lib/Activity/Provider.php', |
|
| 26 | - 'OCA\\TwoFactorBackupCodes\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
| 27 | - 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\CheckBackupCodes' => __DIR__ . '/..' . '/../lib/BackgroundJob/CheckBackupCodes.php', |
|
| 28 | - 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\RememberBackupCodesJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/RememberBackupCodesJob.php', |
|
| 29 | - 'OCA\\TwoFactorBackupCodes\\Controller\\SettingsController' => __DIR__ . '/..' . '/../lib/Controller/SettingsController.php', |
|
| 30 | - 'OCA\\TwoFactorBackupCodes\\Db\\BackupCode' => __DIR__ . '/..' . '/../lib/Db/BackupCode.php', |
|
| 31 | - 'OCA\\TwoFactorBackupCodes\\Db\\BackupCodeMapper' => __DIR__ . '/..' . '/../lib/Db/BackupCodeMapper.php', |
|
| 32 | - 'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => __DIR__ . '/..' . '/../lib/Event/CodesGenerated.php', |
|
| 33 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => __DIR__ . '/..' . '/../lib/Listener/ActivityPublisher.php', |
|
| 34 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ClearNotifications' => __DIR__ . '/..' . '/../lib/Listener/ClearNotifications.php', |
|
| 35 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderDisabled' => __DIR__ . '/..' . '/../lib/Listener/ProviderDisabled.php', |
|
| 36 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderEnabled' => __DIR__ . '/..' . '/../lib/Listener/ProviderEnabled.php', |
|
| 37 | - 'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => __DIR__ . '/..' . '/../lib/Listener/RegistryUpdater.php', |
|
| 38 | - 'OCA\\TwoFactorBackupCodes\\Listener\\UserDeleted' => __DIR__ . '/..' . '/../lib/Listener/UserDeleted.php', |
|
| 39 | - 'OCA\\TwoFactorBackupCodes\\Migration\\CheckBackupCodes' => __DIR__ . '/..' . '/../lib/Migration/CheckBackupCodes.php', |
|
| 40 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607104347' => __DIR__ . '/..' . '/../lib/Migration/Version1002Date20170607104347.php', |
|
| 41 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607113030' => __DIR__ . '/..' . '/../lib/Migration/Version1002Date20170607113030.php', |
|
| 42 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170919123342' => __DIR__ . '/..' . '/../lib/Migration/Version1002Date20170919123342.php', |
|
| 43 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170926101419' => __DIR__ . '/..' . '/../lib/Migration/Version1002Date20170926101419.php', |
|
| 44 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20180821043638' => __DIR__ . '/..' . '/../lib/Migration/Version1002Date20180821043638.php', |
|
| 45 | - 'OCA\\TwoFactorBackupCodes\\Notifications\\Notifier' => __DIR__ . '/..' . '/../lib/Notifications/Notifier.php', |
|
| 46 | - 'OCA\\TwoFactorBackupCodes\\Provider\\BackupCodesProvider' => __DIR__ . '/..' . '/../lib/Provider/BackupCodesProvider.php', |
|
| 47 | - 'OCA\\TwoFactorBackupCodes\\Service\\BackupCodeStorage' => __DIR__ . '/..' . '/../lib/Service/BackupCodeStorage.php', |
|
| 48 | - 'OCA\\TwoFactorBackupCodes\\Settings\\Personal' => __DIR__ . '/..' . '/../lib/Settings/Personal.php', |
|
| 23 | + public static $classMap = array( |
|
| 24 | + 'Composer\\InstalledVersions' => __DIR__.'/..'.'/composer/InstalledVersions.php', |
|
| 25 | + 'OCA\\TwoFactorBackupCodes\\Activity\\Provider' => __DIR__.'/..'.'/../lib/Activity/Provider.php', |
|
| 26 | + 'OCA\\TwoFactorBackupCodes\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
| 27 | + 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\CheckBackupCodes' => __DIR__.'/..'.'/../lib/BackgroundJob/CheckBackupCodes.php', |
|
| 28 | + 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\RememberBackupCodesJob' => __DIR__.'/..'.'/../lib/BackgroundJob/RememberBackupCodesJob.php', |
|
| 29 | + 'OCA\\TwoFactorBackupCodes\\Controller\\SettingsController' => __DIR__.'/..'.'/../lib/Controller/SettingsController.php', |
|
| 30 | + 'OCA\\TwoFactorBackupCodes\\Db\\BackupCode' => __DIR__.'/..'.'/../lib/Db/BackupCode.php', |
|
| 31 | + 'OCA\\TwoFactorBackupCodes\\Db\\BackupCodeMapper' => __DIR__.'/..'.'/../lib/Db/BackupCodeMapper.php', |
|
| 32 | + 'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => __DIR__.'/..'.'/../lib/Event/CodesGenerated.php', |
|
| 33 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => __DIR__.'/..'.'/../lib/Listener/ActivityPublisher.php', |
|
| 34 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ClearNotifications' => __DIR__.'/..'.'/../lib/Listener/ClearNotifications.php', |
|
| 35 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderDisabled' => __DIR__.'/..'.'/../lib/Listener/ProviderDisabled.php', |
|
| 36 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderEnabled' => __DIR__.'/..'.'/../lib/Listener/ProviderEnabled.php', |
|
| 37 | + 'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => __DIR__.'/..'.'/../lib/Listener/RegistryUpdater.php', |
|
| 38 | + 'OCA\\TwoFactorBackupCodes\\Listener\\UserDeleted' => __DIR__.'/..'.'/../lib/Listener/UserDeleted.php', |
|
| 39 | + 'OCA\\TwoFactorBackupCodes\\Migration\\CheckBackupCodes' => __DIR__.'/..'.'/../lib/Migration/CheckBackupCodes.php', |
|
| 40 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607104347' => __DIR__.'/..'.'/../lib/Migration/Version1002Date20170607104347.php', |
|
| 41 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607113030' => __DIR__.'/..'.'/../lib/Migration/Version1002Date20170607113030.php', |
|
| 42 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170919123342' => __DIR__.'/..'.'/../lib/Migration/Version1002Date20170919123342.php', |
|
| 43 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170926101419' => __DIR__.'/..'.'/../lib/Migration/Version1002Date20170926101419.php', |
|
| 44 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20180821043638' => __DIR__.'/..'.'/../lib/Migration/Version1002Date20180821043638.php', |
|
| 45 | + 'OCA\\TwoFactorBackupCodes\\Notifications\\Notifier' => __DIR__.'/..'.'/../lib/Notifications/Notifier.php', |
|
| 46 | + 'OCA\\TwoFactorBackupCodes\\Provider\\BackupCodesProvider' => __DIR__.'/..'.'/../lib/Provider/BackupCodesProvider.php', |
|
| 47 | + 'OCA\\TwoFactorBackupCodes\\Service\\BackupCodeStorage' => __DIR__.'/..'.'/../lib/Service/BackupCodeStorage.php', |
|
| 48 | + 'OCA\\TwoFactorBackupCodes\\Settings\\Personal' => __DIR__.'/..'.'/../lib/Settings/Personal.php', |
|
| 49 | 49 | ); |
| 50 | 50 | |
| 51 | 51 | public static function getInitializer(ClassLoader $loader) |
| 52 | 52 | { |
| 53 | - return \Closure::bind(function () use ($loader) { |
|
| 53 | + return \Closure::bind(function() use ($loader) { |
|
| 54 | 54 | $loader->prefixLengthsPsr4 = ComposerStaticInitTwoFactorBackupCodes::$prefixLengthsPsr4; |
| 55 | 55 | $loader->prefixDirsPsr4 = ComposerStaticInitTwoFactorBackupCodes::$prefixDirsPsr4; |
| 56 | 56 | $loader->classMap = ComposerStaticInitTwoFactorBackupCodes::$classMap; |
@@ -6,29 +6,29 @@ |
||
| 6 | 6 | $baseDir = $vendorDir; |
| 7 | 7 | |
| 8 | 8 | return array( |
| 9 | - 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', |
|
| 10 | - 'OCA\\TwoFactorBackupCodes\\Activity\\Provider' => $baseDir . '/../lib/Activity/Provider.php', |
|
| 11 | - 'OCA\\TwoFactorBackupCodes\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', |
|
| 12 | - 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\CheckBackupCodes' => $baseDir . '/../lib/BackgroundJob/CheckBackupCodes.php', |
|
| 13 | - 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\RememberBackupCodesJob' => $baseDir . '/../lib/BackgroundJob/RememberBackupCodesJob.php', |
|
| 14 | - 'OCA\\TwoFactorBackupCodes\\Controller\\SettingsController' => $baseDir . '/../lib/Controller/SettingsController.php', |
|
| 15 | - 'OCA\\TwoFactorBackupCodes\\Db\\BackupCode' => $baseDir . '/../lib/Db/BackupCode.php', |
|
| 16 | - 'OCA\\TwoFactorBackupCodes\\Db\\BackupCodeMapper' => $baseDir . '/../lib/Db/BackupCodeMapper.php', |
|
| 17 | - 'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => $baseDir . '/../lib/Event/CodesGenerated.php', |
|
| 18 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => $baseDir . '/../lib/Listener/ActivityPublisher.php', |
|
| 19 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ClearNotifications' => $baseDir . '/../lib/Listener/ClearNotifications.php', |
|
| 20 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderDisabled' => $baseDir . '/../lib/Listener/ProviderDisabled.php', |
|
| 21 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderEnabled' => $baseDir . '/../lib/Listener/ProviderEnabled.php', |
|
| 22 | - 'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => $baseDir . '/../lib/Listener/RegistryUpdater.php', |
|
| 23 | - 'OCA\\TwoFactorBackupCodes\\Listener\\UserDeleted' => $baseDir . '/../lib/Listener/UserDeleted.php', |
|
| 24 | - 'OCA\\TwoFactorBackupCodes\\Migration\\CheckBackupCodes' => $baseDir . '/../lib/Migration/CheckBackupCodes.php', |
|
| 25 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607104347' => $baseDir . '/../lib/Migration/Version1002Date20170607104347.php', |
|
| 26 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607113030' => $baseDir . '/../lib/Migration/Version1002Date20170607113030.php', |
|
| 27 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170919123342' => $baseDir . '/../lib/Migration/Version1002Date20170919123342.php', |
|
| 28 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170926101419' => $baseDir . '/../lib/Migration/Version1002Date20170926101419.php', |
|
| 29 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20180821043638' => $baseDir . '/../lib/Migration/Version1002Date20180821043638.php', |
|
| 30 | - 'OCA\\TwoFactorBackupCodes\\Notifications\\Notifier' => $baseDir . '/../lib/Notifications/Notifier.php', |
|
| 31 | - 'OCA\\TwoFactorBackupCodes\\Provider\\BackupCodesProvider' => $baseDir . '/../lib/Provider/BackupCodesProvider.php', |
|
| 32 | - 'OCA\\TwoFactorBackupCodes\\Service\\BackupCodeStorage' => $baseDir . '/../lib/Service/BackupCodeStorage.php', |
|
| 33 | - 'OCA\\TwoFactorBackupCodes\\Settings\\Personal' => $baseDir . '/../lib/Settings/Personal.php', |
|
| 9 | + 'Composer\\InstalledVersions' => $vendorDir.'/composer/InstalledVersions.php', |
|
| 10 | + 'OCA\\TwoFactorBackupCodes\\Activity\\Provider' => $baseDir.'/../lib/Activity/Provider.php', |
|
| 11 | + 'OCA\\TwoFactorBackupCodes\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php', |
|
| 12 | + 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\CheckBackupCodes' => $baseDir.'/../lib/BackgroundJob/CheckBackupCodes.php', |
|
| 13 | + 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\RememberBackupCodesJob' => $baseDir.'/../lib/BackgroundJob/RememberBackupCodesJob.php', |
|
| 14 | + 'OCA\\TwoFactorBackupCodes\\Controller\\SettingsController' => $baseDir.'/../lib/Controller/SettingsController.php', |
|
| 15 | + 'OCA\\TwoFactorBackupCodes\\Db\\BackupCode' => $baseDir.'/../lib/Db/BackupCode.php', |
|
| 16 | + 'OCA\\TwoFactorBackupCodes\\Db\\BackupCodeMapper' => $baseDir.'/../lib/Db/BackupCodeMapper.php', |
|
| 17 | + 'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => $baseDir.'/../lib/Event/CodesGenerated.php', |
|
| 18 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => $baseDir.'/../lib/Listener/ActivityPublisher.php', |
|
| 19 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ClearNotifications' => $baseDir.'/../lib/Listener/ClearNotifications.php', |
|
| 20 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderDisabled' => $baseDir.'/../lib/Listener/ProviderDisabled.php', |
|
| 21 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderEnabled' => $baseDir.'/../lib/Listener/ProviderEnabled.php', |
|
| 22 | + 'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => $baseDir.'/../lib/Listener/RegistryUpdater.php', |
|
| 23 | + 'OCA\\TwoFactorBackupCodes\\Listener\\UserDeleted' => $baseDir.'/../lib/Listener/UserDeleted.php', |
|
| 24 | + 'OCA\\TwoFactorBackupCodes\\Migration\\CheckBackupCodes' => $baseDir.'/../lib/Migration/CheckBackupCodes.php', |
|
| 25 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607104347' => $baseDir.'/../lib/Migration/Version1002Date20170607104347.php', |
|
| 26 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607113030' => $baseDir.'/../lib/Migration/Version1002Date20170607113030.php', |
|
| 27 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170919123342' => $baseDir.'/../lib/Migration/Version1002Date20170919123342.php', |
|
| 28 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170926101419' => $baseDir.'/../lib/Migration/Version1002Date20170926101419.php', |
|
| 29 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20180821043638' => $baseDir.'/../lib/Migration/Version1002Date20180821043638.php', |
|
| 30 | + 'OCA\\TwoFactorBackupCodes\\Notifications\\Notifier' => $baseDir.'/../lib/Notifications/Notifier.php', |
|
| 31 | + 'OCA\\TwoFactorBackupCodes\\Provider\\BackupCodesProvider' => $baseDir.'/../lib/Provider/BackupCodesProvider.php', |
|
| 32 | + 'OCA\\TwoFactorBackupCodes\\Service\\BackupCodeStorage' => $baseDir.'/../lib/Service/BackupCodeStorage.php', |
|
| 33 | + 'OCA\\TwoFactorBackupCodes\\Settings\\Personal' => $baseDir.'/../lib/Settings/Personal.php', |
|
| 34 | 34 | ); |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | try { |
| 58 | 58 | $this->providerInstances[] = $this->serverContainer->query($provider); |
| 59 | 59 | } catch (QueryException $e) { |
| 60 | - $this->logger->error("Could not query resource provider $provider: " . $e->getMessage(), [ |
|
| 60 | + $this->logger->error("Could not query resource provider $provider: ".$e->getMessage(), [ |
|
| 61 | 61 | 'exception' => $e, |
| 62 | 62 | ]); |
| 63 | 63 | } |
@@ -15,36 +15,36 @@ |
||
| 15 | 15 | use Psr\Log\LoggerInterface; |
| 16 | 16 | |
| 17 | 17 | class ProviderManager implements IProviderManager { |
| 18 | - /** @var string[] */ |
|
| 19 | - protected array $providers = []; |
|
| 20 | - |
|
| 21 | - /** @var IProvider[] */ |
|
| 22 | - protected array $providerInstances = []; |
|
| 23 | - |
|
| 24 | - public function __construct( |
|
| 25 | - protected IServerContainer $serverContainer, |
|
| 26 | - protected LoggerInterface $logger, |
|
| 27 | - ) { |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - public function getResourceProviders(): array { |
|
| 31 | - if ($this->providers !== []) { |
|
| 32 | - foreach ($this->providers as $provider) { |
|
| 33 | - try { |
|
| 34 | - $this->providerInstances[] = $this->serverContainer->query($provider); |
|
| 35 | - } catch (QueryException $e) { |
|
| 36 | - $this->logger->error("Could not query resource provider $provider: " . $e->getMessage(), [ |
|
| 37 | - 'exception' => $e, |
|
| 38 | - ]); |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - $this->providers = []; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - return $this->providerInstances; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function registerResourceProvider(string $provider): void { |
|
| 48 | - $this->providers[] = $provider; |
|
| 49 | - } |
|
| 18 | + /** @var string[] */ |
|
| 19 | + protected array $providers = []; |
|
| 20 | + |
|
| 21 | + /** @var IProvider[] */ |
|
| 22 | + protected array $providerInstances = []; |
|
| 23 | + |
|
| 24 | + public function __construct( |
|
| 25 | + protected IServerContainer $serverContainer, |
|
| 26 | + protected LoggerInterface $logger, |
|
| 27 | + ) { |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + public function getResourceProviders(): array { |
|
| 31 | + if ($this->providers !== []) { |
|
| 32 | + foreach ($this->providers as $provider) { |
|
| 33 | + try { |
|
| 34 | + $this->providerInstances[] = $this->serverContainer->query($provider); |
|
| 35 | + } catch (QueryException $e) { |
|
| 36 | + $this->logger->error("Could not query resource provider $provider: " . $e->getMessage(), [ |
|
| 37 | + 'exception' => $e, |
|
| 38 | + ]); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + $this->providers = []; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + return $this->providerInstances; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function registerResourceProvider(string $provider): void { |
|
| 48 | + $this->providers[] = $provider; |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -78,7 +78,7 @@ |
||
| 78 | 78 | $this->logger->debug('Default user calendar reset'); |
| 79 | 79 | } catch (Throwable $e) { |
| 80 | 80 | // Any error with activities shouldn't abort the calendar deletion, so we just log it |
| 81 | - $this->logger->error('Error generating activities for a deleted calendar: ' . $e->getMessage(), [ |
|
| 81 | + $this->logger->error('Error generating activities for a deleted calendar: '.$e->getMessage(), [ |
|
| 82 | 82 | 'exception' => $e, |
| 83 | 83 | ]); |
| 84 | 84 | } |
@@ -20,43 +20,43 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class CalendarDeletionDefaultUpdaterListener implements IEventListener { |
| 22 | 22 | |
| 23 | - public function __construct( |
|
| 24 | - private IConfig $config, |
|
| 25 | - private LoggerInterface $logger, |
|
| 26 | - ) { |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * In case the user has set their default calendar to the deleted one |
|
| 31 | - */ |
|
| 32 | - public function handle(Event $event): void { |
|
| 33 | - if (!($event instanceof CalendarDeletedEvent)) { |
|
| 34 | - // Not what we subscribed to |
|
| 35 | - return; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - try { |
|
| 39 | - $principalUri = $event->getCalendarData()['principaluri']; |
|
| 40 | - if (!str_starts_with($principalUri, 'principals/users')) { |
|
| 41 | - $this->logger->debug('Default calendar needs no update because the deleted calendar does not belong to a user principal'); |
|
| 42 | - return; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - [, $uid] = \Sabre\Uri\split($principalUri); |
|
| 46 | - $uri = $event->getCalendarData()['uri']; |
|
| 47 | - if ($this->config->getUserValue($uid, 'dav', 'defaultCalendar') !== $uri) { |
|
| 48 | - $this->logger->debug('Default calendar needs no update because the deleted calendar is no the user\'s default one'); |
|
| 49 | - return; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - $this->config->deleteUserValue($uid, 'dav', 'defaultCalendar'); |
|
| 53 | - |
|
| 54 | - $this->logger->debug('Default user calendar reset'); |
|
| 55 | - } catch (Throwable $e) { |
|
| 56 | - // Any error with activities shouldn't abort the calendar deletion, so we just log it |
|
| 57 | - $this->logger->error('Error generating activities for a deleted calendar: ' . $e->getMessage(), [ |
|
| 58 | - 'exception' => $e, |
|
| 59 | - ]); |
|
| 60 | - } |
|
| 61 | - } |
|
| 23 | + public function __construct( |
|
| 24 | + private IConfig $config, |
|
| 25 | + private LoggerInterface $logger, |
|
| 26 | + ) { |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * In case the user has set their default calendar to the deleted one |
|
| 31 | + */ |
|
| 32 | + public function handle(Event $event): void { |
|
| 33 | + if (!($event instanceof CalendarDeletedEvent)) { |
|
| 34 | + // Not what we subscribed to |
|
| 35 | + return; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + try { |
|
| 39 | + $principalUri = $event->getCalendarData()['principaluri']; |
|
| 40 | + if (!str_starts_with($principalUri, 'principals/users')) { |
|
| 41 | + $this->logger->debug('Default calendar needs no update because the deleted calendar does not belong to a user principal'); |
|
| 42 | + return; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + [, $uid] = \Sabre\Uri\split($principalUri); |
|
| 46 | + $uri = $event->getCalendarData()['uri']; |
|
| 47 | + if ($this->config->getUserValue($uid, 'dav', 'defaultCalendar') !== $uri) { |
|
| 48 | + $this->logger->debug('Default calendar needs no update because the deleted calendar is no the user\'s default one'); |
|
| 49 | + return; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + $this->config->deleteUserValue($uid, 'dav', 'defaultCalendar'); |
|
| 53 | + |
|
| 54 | + $this->logger->debug('Default user calendar reset'); |
|
| 55 | + } catch (Throwable $e) { |
|
| 56 | + // Any error with activities shouldn't abort the calendar deletion, so we just log it |
|
| 57 | + $this->logger->error('Error generating activities for a deleted calendar: ' . $e->getMessage(), [ |
|
| 58 | + 'exception' => $e, |
|
| 59 | + ]); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | protected function run($argument) { |
| 110 | - $try = (int)$argument['try'] + 1; |
|
| 110 | + $try = (int) $argument['try'] + 1; |
|
| 111 | 111 | |
| 112 | 112 | switch ($argument['type']) { |
| 113 | 113 | case IAccountManager::PROPERTY_WEBSITE: |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | break; |
| 120 | 120 | default: |
| 121 | 121 | // no valid type given, no need to retry |
| 122 | - $this->logger->error($argument['type'] . ' is no valid type for user account data.'); |
|
| 122 | + $this->logger->error($argument['type'].' is no valid type for user account data.'); |
|
| 123 | 123 | $result = true; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | protected function verifyWebsite(array $argument) { |
| 138 | 138 | $result = false; |
| 139 | 139 | |
| 140 | - $url = rtrim($argument['data'], '/') . '/.well-known/' . 'CloudIdVerificationCode.txt'; |
|
| 140 | + $url = rtrim($argument['data'], '/').'/.well-known/'.'CloudIdVerificationCode.txt'; |
|
| 141 | 141 | |
| 142 | 142 | $client = $this->httpClientService->newClient(); |
| 143 | 143 | try { |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | $user = $this->userManager->get($argument['uid']); |
| 155 | 155 | // we don't check a valid user -> give up |
| 156 | 156 | if ($user === null) { |
| 157 | - $this->logger->error($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); |
|
| 157 | + $this->logger->error($argument['uid'].' doesn\'t exist, can\'t verify user data.'); |
|
| 158 | 158 | return $result; |
| 159 | 159 | } |
| 160 | 160 | $userAccount = $this->accountManager->getAccount($user); |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | // we don't check a valid user -> give up |
| 182 | 182 | if ($user === null) { |
| 183 | - $this->logger->info($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); |
|
| 183 | + $this->logger->info($argument['uid'].' doesn\'t exist, can\'t verify user data.'); |
|
| 184 | 184 | return true; |
| 185 | 185 | } |
| 186 | 186 | |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | try { |
| 223 | 223 | $client = $this->httpClientService->newClient(); |
| 224 | 224 | $response = $client->get( |
| 225 | - $this->lookupServerUrl . '/users?search=' . urlencode($cloudId) . '&exactCloudId=1', |
|
| 225 | + $this->lookupServerUrl.'/users?search='.urlencode($cloudId).'&exactCloudId=1', |
|
| 226 | 226 | [ |
| 227 | 227 | 'timeout' => 10, |
| 228 | 228 | 'connect_timeout' => 3, |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | 'data' => $argument['data'], |
| 255 | 255 | 'type' => $argument['type'], |
| 256 | 256 | 'uid' => $argument['uid'], |
| 257 | - 'try' => (int)$argument['try'] + 1, |
|
| 257 | + 'try' => (int) $argument['try'] + 1, |
|
| 258 | 258 | 'lastRun' => time() |
| 259 | 259 | ] |
| 260 | 260 | ); |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * @return bool |
| 268 | 268 | */ |
| 269 | 269 | protected function shouldRun(array $argument) { |
| 270 | - $lastRun = (int)$argument['lastRun']; |
|
| 270 | + $lastRun = (int) $argument['lastRun']; |
|
| 271 | 271 | return ((time() - $lastRun) > $this->interval); |
| 272 | 272 | } |
| 273 | 273 | |
@@ -20,224 +20,224 @@ |
||
| 20 | 20 | use Psr\Log\LoggerInterface; |
| 21 | 21 | |
| 22 | 22 | class VerifyUserData extends Job { |
| 23 | - /** @var bool */ |
|
| 24 | - private bool $retainJob = true; |
|
| 25 | - |
|
| 26 | - /** @var int max number of attempts to send the request */ |
|
| 27 | - private int $maxTry = 24; |
|
| 28 | - |
|
| 29 | - /** @var int how much time should be between two tries (1 hour) */ |
|
| 30 | - private int $interval = 3600; |
|
| 31 | - private string $lookupServerUrl; |
|
| 32 | - |
|
| 33 | - public function __construct( |
|
| 34 | - private IAccountManager $accountManager, |
|
| 35 | - private IUserManager $userManager, |
|
| 36 | - private IClientService $httpClientService, |
|
| 37 | - private LoggerInterface $logger, |
|
| 38 | - ITimeFactory $timeFactory, |
|
| 39 | - private IConfig $config, |
|
| 40 | - ) { |
|
| 41 | - parent::__construct($timeFactory); |
|
| 42 | - |
|
| 43 | - $lookupServerUrl = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
| 44 | - $this->lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function start(IJobList $jobList): void { |
|
| 48 | - if ($this->shouldRun($this->argument)) { |
|
| 49 | - parent::start($jobList); |
|
| 50 | - $jobList->remove($this, $this->argument); |
|
| 51 | - if ($this->retainJob) { |
|
| 52 | - $this->reAddJob($jobList, $this->argument); |
|
| 53 | - } else { |
|
| 54 | - $this->resetVerificationState(); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - protected function run($argument) { |
|
| 60 | - $try = (int)$argument['try'] + 1; |
|
| 61 | - |
|
| 62 | - switch ($argument['type']) { |
|
| 63 | - case IAccountManager::PROPERTY_WEBSITE: |
|
| 64 | - $result = $this->verifyWebsite($argument); |
|
| 65 | - break; |
|
| 66 | - case IAccountManager::PROPERTY_TWITTER: |
|
| 67 | - case IAccountManager::PROPERTY_EMAIL: |
|
| 68 | - $result = $this->verifyViaLookupServer($argument, $argument['type']); |
|
| 69 | - break; |
|
| 70 | - default: |
|
| 71 | - // no valid type given, no need to retry |
|
| 72 | - $this->logger->error($argument['type'] . ' is no valid type for user account data.'); |
|
| 73 | - $result = true; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if ($result === true || $try > $this->maxTry) { |
|
| 77 | - $this->retainJob = false; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * verify web page |
|
| 83 | - * |
|
| 84 | - * @param array $argument |
|
| 85 | - * @return bool true if we could check the verification code, otherwise false |
|
| 86 | - */ |
|
| 87 | - protected function verifyWebsite(array $argument) { |
|
| 88 | - $result = false; |
|
| 89 | - |
|
| 90 | - $url = rtrim($argument['data'], '/') . '/.well-known/' . 'CloudIdVerificationCode.txt'; |
|
| 91 | - |
|
| 92 | - $client = $this->httpClientService->newClient(); |
|
| 93 | - try { |
|
| 94 | - $response = $client->get($url); |
|
| 95 | - } catch (\Exception $e) { |
|
| 96 | - return false; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - if ($response->getStatusCode() === Http::STATUS_OK) { |
|
| 100 | - $result = true; |
|
| 101 | - $publishedCode = $response->getBody(); |
|
| 102 | - // remove new lines and spaces |
|
| 103 | - $publishedCodeSanitized = trim(preg_replace('/\s\s+/', ' ', $publishedCode)); |
|
| 104 | - $user = $this->userManager->get($argument['uid']); |
|
| 105 | - // we don't check a valid user -> give up |
|
| 106 | - if ($user === null) { |
|
| 107 | - $this->logger->error($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); |
|
| 108 | - return $result; |
|
| 109 | - } |
|
| 110 | - $userAccount = $this->accountManager->getAccount($user); |
|
| 111 | - $websiteProp = $userAccount->getProperty(IAccountManager::PROPERTY_WEBSITE); |
|
| 112 | - $websiteProp->setVerified($publishedCodeSanitized === $argument['verificationCode'] |
|
| 113 | - ? IAccountManager::VERIFIED |
|
| 114 | - : IAccountManager::NOT_VERIFIED |
|
| 115 | - ); |
|
| 116 | - $this->accountManager->updateAccount($userAccount); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - return $result; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - protected function verifyViaLookupServer(array $argument, string $dataType): bool { |
|
| 123 | - // TODO: Consider to enable for non-global-scale setups by checking 'files_sharing', 'lookupServerUploadEnabled' |
|
| 124 | - if (!$this->config->getSystemValueBool('gs.enabled', false) |
|
| 125 | - || empty($this->lookupServerUrl) |
|
| 126 | - || $this->config->getSystemValue('has_internet_connection', true) === false |
|
| 127 | - ) { |
|
| 128 | - return true; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $user = $this->userManager->get($argument['uid']); |
|
| 132 | - |
|
| 133 | - // we don't check a valid user -> give up |
|
| 134 | - if ($user === null) { |
|
| 135 | - $this->logger->info($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); |
|
| 136 | - return true; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $cloudId = $user->getCloudId(); |
|
| 140 | - $lookupServerData = $this->queryLookupServer($cloudId); |
|
| 141 | - |
|
| 142 | - // for some reasons we couldn't read any data from the lookup server, try again later |
|
| 143 | - if (empty($lookupServerData) || empty($lookupServerData[$dataType])) { |
|
| 144 | - return false; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // lookup server has verification data for wrong user data (e.g. email address), try again later |
|
| 148 | - if ($lookupServerData[$dataType]['value'] !== $argument['data']) { |
|
| 149 | - return false; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // lookup server hasn't verified the email address so far, try again later |
|
| 153 | - if ($lookupServerData[$dataType]['verified'] === IAccountManager::NOT_VERIFIED) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - try { |
|
| 158 | - $userAccount = $this->accountManager->getAccount($user); |
|
| 159 | - $property = $userAccount->getProperty($dataType); |
|
| 160 | - $property->setVerified(IAccountManager::VERIFIED); |
|
| 161 | - $this->accountManager->updateAccount($userAccount); |
|
| 162 | - } catch (PropertyDoesNotExistException $e) { |
|
| 163 | - return false; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - return true; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param string $cloudId |
|
| 171 | - * @return array |
|
| 172 | - */ |
|
| 173 | - protected function queryLookupServer($cloudId) { |
|
| 174 | - try { |
|
| 175 | - $client = $this->httpClientService->newClient(); |
|
| 176 | - $response = $client->get( |
|
| 177 | - $this->lookupServerUrl . '/users?search=' . urlencode($cloudId) . '&exactCloudId=1', |
|
| 178 | - [ |
|
| 179 | - 'timeout' => 10, |
|
| 180 | - 'connect_timeout' => 3, |
|
| 181 | - ] |
|
| 182 | - ); |
|
| 183 | - |
|
| 184 | - $body = json_decode($response->getBody(), true); |
|
| 185 | - |
|
| 186 | - if (is_array($body) && isset($body['federationId']) && $body['federationId'] === $cloudId) { |
|
| 187 | - return $body; |
|
| 188 | - } |
|
| 189 | - } catch (\Exception $e) { |
|
| 190 | - // do nothing, we will just re-try later |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - return []; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * re-add background job with new arguments |
|
| 198 | - * |
|
| 199 | - * @param IJobList $jobList |
|
| 200 | - * @param array $argument |
|
| 201 | - */ |
|
| 202 | - protected function reAddJob(IJobList $jobList, array $argument) { |
|
| 203 | - $jobList->add(VerifyUserData::class, |
|
| 204 | - [ |
|
| 205 | - 'verificationCode' => $argument['verificationCode'], |
|
| 206 | - 'data' => $argument['data'], |
|
| 207 | - 'type' => $argument['type'], |
|
| 208 | - 'uid' => $argument['uid'], |
|
| 209 | - 'try' => (int)$argument['try'] + 1, |
|
| 210 | - 'lastRun' => time() |
|
| 211 | - ] |
|
| 212 | - ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * test if it is time for the next run |
|
| 217 | - * |
|
| 218 | - * @param array $argument |
|
| 219 | - * @return bool |
|
| 220 | - */ |
|
| 221 | - protected function shouldRun(array $argument) { |
|
| 222 | - $lastRun = (int)$argument['lastRun']; |
|
| 223 | - return ((time() - $lastRun) > $this->interval); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * reset verification state after max tries are reached |
|
| 229 | - */ |
|
| 230 | - protected function resetVerificationState(): void { |
|
| 231 | - $user = $this->userManager->get($this->argument['uid']); |
|
| 232 | - if ($user !== null) { |
|
| 233 | - $userAccount = $this->accountManager->getAccount($user); |
|
| 234 | - try { |
|
| 235 | - $property = $userAccount->getProperty($this->argument['type']); |
|
| 236 | - $property->setVerified(IAccountManager::NOT_VERIFIED); |
|
| 237 | - $this->accountManager->updateAccount($userAccount); |
|
| 238 | - } catch (PropertyDoesNotExistException $e) { |
|
| 239 | - return; |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - } |
|
| 23 | + /** @var bool */ |
|
| 24 | + private bool $retainJob = true; |
|
| 25 | + |
|
| 26 | + /** @var int max number of attempts to send the request */ |
|
| 27 | + private int $maxTry = 24; |
|
| 28 | + |
|
| 29 | + /** @var int how much time should be between two tries (1 hour) */ |
|
| 30 | + private int $interval = 3600; |
|
| 31 | + private string $lookupServerUrl; |
|
| 32 | + |
|
| 33 | + public function __construct( |
|
| 34 | + private IAccountManager $accountManager, |
|
| 35 | + private IUserManager $userManager, |
|
| 36 | + private IClientService $httpClientService, |
|
| 37 | + private LoggerInterface $logger, |
|
| 38 | + ITimeFactory $timeFactory, |
|
| 39 | + private IConfig $config, |
|
| 40 | + ) { |
|
| 41 | + parent::__construct($timeFactory); |
|
| 42 | + |
|
| 43 | + $lookupServerUrl = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
| 44 | + $this->lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function start(IJobList $jobList): void { |
|
| 48 | + if ($this->shouldRun($this->argument)) { |
|
| 49 | + parent::start($jobList); |
|
| 50 | + $jobList->remove($this, $this->argument); |
|
| 51 | + if ($this->retainJob) { |
|
| 52 | + $this->reAddJob($jobList, $this->argument); |
|
| 53 | + } else { |
|
| 54 | + $this->resetVerificationState(); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + protected function run($argument) { |
|
| 60 | + $try = (int)$argument['try'] + 1; |
|
| 61 | + |
|
| 62 | + switch ($argument['type']) { |
|
| 63 | + case IAccountManager::PROPERTY_WEBSITE: |
|
| 64 | + $result = $this->verifyWebsite($argument); |
|
| 65 | + break; |
|
| 66 | + case IAccountManager::PROPERTY_TWITTER: |
|
| 67 | + case IAccountManager::PROPERTY_EMAIL: |
|
| 68 | + $result = $this->verifyViaLookupServer($argument, $argument['type']); |
|
| 69 | + break; |
|
| 70 | + default: |
|
| 71 | + // no valid type given, no need to retry |
|
| 72 | + $this->logger->error($argument['type'] . ' is no valid type for user account data.'); |
|
| 73 | + $result = true; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if ($result === true || $try > $this->maxTry) { |
|
| 77 | + $this->retainJob = false; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * verify web page |
|
| 83 | + * |
|
| 84 | + * @param array $argument |
|
| 85 | + * @return bool true if we could check the verification code, otherwise false |
|
| 86 | + */ |
|
| 87 | + protected function verifyWebsite(array $argument) { |
|
| 88 | + $result = false; |
|
| 89 | + |
|
| 90 | + $url = rtrim($argument['data'], '/') . '/.well-known/' . 'CloudIdVerificationCode.txt'; |
|
| 91 | + |
|
| 92 | + $client = $this->httpClientService->newClient(); |
|
| 93 | + try { |
|
| 94 | + $response = $client->get($url); |
|
| 95 | + } catch (\Exception $e) { |
|
| 96 | + return false; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + if ($response->getStatusCode() === Http::STATUS_OK) { |
|
| 100 | + $result = true; |
|
| 101 | + $publishedCode = $response->getBody(); |
|
| 102 | + // remove new lines and spaces |
|
| 103 | + $publishedCodeSanitized = trim(preg_replace('/\s\s+/', ' ', $publishedCode)); |
|
| 104 | + $user = $this->userManager->get($argument['uid']); |
|
| 105 | + // we don't check a valid user -> give up |
|
| 106 | + if ($user === null) { |
|
| 107 | + $this->logger->error($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); |
|
| 108 | + return $result; |
|
| 109 | + } |
|
| 110 | + $userAccount = $this->accountManager->getAccount($user); |
|
| 111 | + $websiteProp = $userAccount->getProperty(IAccountManager::PROPERTY_WEBSITE); |
|
| 112 | + $websiteProp->setVerified($publishedCodeSanitized === $argument['verificationCode'] |
|
| 113 | + ? IAccountManager::VERIFIED |
|
| 114 | + : IAccountManager::NOT_VERIFIED |
|
| 115 | + ); |
|
| 116 | + $this->accountManager->updateAccount($userAccount); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + return $result; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + protected function verifyViaLookupServer(array $argument, string $dataType): bool { |
|
| 123 | + // TODO: Consider to enable for non-global-scale setups by checking 'files_sharing', 'lookupServerUploadEnabled' |
|
| 124 | + if (!$this->config->getSystemValueBool('gs.enabled', false) |
|
| 125 | + || empty($this->lookupServerUrl) |
|
| 126 | + || $this->config->getSystemValue('has_internet_connection', true) === false |
|
| 127 | + ) { |
|
| 128 | + return true; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $user = $this->userManager->get($argument['uid']); |
|
| 132 | + |
|
| 133 | + // we don't check a valid user -> give up |
|
| 134 | + if ($user === null) { |
|
| 135 | + $this->logger->info($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $cloudId = $user->getCloudId(); |
|
| 140 | + $lookupServerData = $this->queryLookupServer($cloudId); |
|
| 141 | + |
|
| 142 | + // for some reasons we couldn't read any data from the lookup server, try again later |
|
| 143 | + if (empty($lookupServerData) || empty($lookupServerData[$dataType])) { |
|
| 144 | + return false; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // lookup server has verification data for wrong user data (e.g. email address), try again later |
|
| 148 | + if ($lookupServerData[$dataType]['value'] !== $argument['data']) { |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // lookup server hasn't verified the email address so far, try again later |
|
| 153 | + if ($lookupServerData[$dataType]['verified'] === IAccountManager::NOT_VERIFIED) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + try { |
|
| 158 | + $userAccount = $this->accountManager->getAccount($user); |
|
| 159 | + $property = $userAccount->getProperty($dataType); |
|
| 160 | + $property->setVerified(IAccountManager::VERIFIED); |
|
| 161 | + $this->accountManager->updateAccount($userAccount); |
|
| 162 | + } catch (PropertyDoesNotExistException $e) { |
|
| 163 | + return false; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + return true; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param string $cloudId |
|
| 171 | + * @return array |
|
| 172 | + */ |
|
| 173 | + protected function queryLookupServer($cloudId) { |
|
| 174 | + try { |
|
| 175 | + $client = $this->httpClientService->newClient(); |
|
| 176 | + $response = $client->get( |
|
| 177 | + $this->lookupServerUrl . '/users?search=' . urlencode($cloudId) . '&exactCloudId=1', |
|
| 178 | + [ |
|
| 179 | + 'timeout' => 10, |
|
| 180 | + 'connect_timeout' => 3, |
|
| 181 | + ] |
|
| 182 | + ); |
|
| 183 | + |
|
| 184 | + $body = json_decode($response->getBody(), true); |
|
| 185 | + |
|
| 186 | + if (is_array($body) && isset($body['federationId']) && $body['federationId'] === $cloudId) { |
|
| 187 | + return $body; |
|
| 188 | + } |
|
| 189 | + } catch (\Exception $e) { |
|
| 190 | + // do nothing, we will just re-try later |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + return []; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * re-add background job with new arguments |
|
| 198 | + * |
|
| 199 | + * @param IJobList $jobList |
|
| 200 | + * @param array $argument |
|
| 201 | + */ |
|
| 202 | + protected function reAddJob(IJobList $jobList, array $argument) { |
|
| 203 | + $jobList->add(VerifyUserData::class, |
|
| 204 | + [ |
|
| 205 | + 'verificationCode' => $argument['verificationCode'], |
|
| 206 | + 'data' => $argument['data'], |
|
| 207 | + 'type' => $argument['type'], |
|
| 208 | + 'uid' => $argument['uid'], |
|
| 209 | + 'try' => (int)$argument['try'] + 1, |
|
| 210 | + 'lastRun' => time() |
|
| 211 | + ] |
|
| 212 | + ); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * test if it is time for the next run |
|
| 217 | + * |
|
| 218 | + * @param array $argument |
|
| 219 | + * @return bool |
|
| 220 | + */ |
|
| 221 | + protected function shouldRun(array $argument) { |
|
| 222 | + $lastRun = (int)$argument['lastRun']; |
|
| 223 | + return ((time() - $lastRun) > $this->interval); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * reset verification state after max tries are reached |
|
| 229 | + */ |
|
| 230 | + protected function resetVerificationState(): void { |
|
| 231 | + $user = $this->userManager->get($this->argument['uid']); |
|
| 232 | + if ($user !== null) { |
|
| 233 | + $userAccount = $this->accountManager->getAccount($user); |
|
| 234 | + try { |
|
| 235 | + $property = $userAccount->getProperty($this->argument['type']); |
|
| 236 | + $property->setVerified(IAccountManager::NOT_VERIFIED); |
|
| 237 | + $this->accountManager->updateAccount($userAccount); |
|
| 238 | + } catch (PropertyDoesNotExistException $e) { |
|
| 239 | + return; |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | 243 | } |
@@ -32,51 +32,51 @@ |
||
| 32 | 32 | * @since 8.0.0 |
| 33 | 33 | */ |
| 34 | 34 | interface ICertificate { |
| 35 | - /** |
|
| 36 | - * @return string |
|
| 37 | - * @since 8.0.0 |
|
| 38 | - */ |
|
| 39 | - public function getName(): string; |
|
| 35 | + /** |
|
| 36 | + * @return string |
|
| 37 | + * @since 8.0.0 |
|
| 38 | + */ |
|
| 39 | + public function getName(): string; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @return string|null |
|
| 43 | - * @since 8.0.0 |
|
| 44 | - */ |
|
| 45 | - public function getCommonName(): ?string; |
|
| 41 | + /** |
|
| 42 | + * @return string|null |
|
| 43 | + * @since 8.0.0 |
|
| 44 | + */ |
|
| 45 | + public function getCommonName(): ?string; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @return string|null |
|
| 49 | - * @since 8.0.0 |
|
| 50 | - */ |
|
| 51 | - public function getOrganization(): ?string; |
|
| 47 | + /** |
|
| 48 | + * @return string|null |
|
| 49 | + * @since 8.0.0 |
|
| 50 | + */ |
|
| 51 | + public function getOrganization(): ?string; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return \DateTime |
|
| 55 | - * @since 8.0.0 |
|
| 56 | - */ |
|
| 57 | - public function getIssueDate(): \DateTime; |
|
| 53 | + /** |
|
| 54 | + * @return \DateTime |
|
| 55 | + * @since 8.0.0 |
|
| 56 | + */ |
|
| 57 | + public function getIssueDate(): \DateTime; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @return \DateTime |
|
| 61 | - * @since 8.0.0 |
|
| 62 | - */ |
|
| 63 | - public function getExpireDate(): \DateTime; |
|
| 59 | + /** |
|
| 60 | + * @return \DateTime |
|
| 61 | + * @since 8.0.0 |
|
| 62 | + */ |
|
| 63 | + public function getExpireDate(): \DateTime; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @return bool |
|
| 67 | - * @since 8.0.0 |
|
| 68 | - */ |
|
| 69 | - public function isExpired(): bool; |
|
| 65 | + /** |
|
| 66 | + * @return bool |
|
| 67 | + * @since 8.0.0 |
|
| 68 | + */ |
|
| 69 | + public function isExpired(): bool; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return string|null |
|
| 73 | - * @since 8.0.0 |
|
| 74 | - */ |
|
| 75 | - public function getIssuerName(): ?string; |
|
| 71 | + /** |
|
| 72 | + * @return string|null |
|
| 73 | + * @since 8.0.0 |
|
| 74 | + */ |
|
| 75 | + public function getIssuerName(): ?string; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @return string|null |
|
| 79 | - * @since 8.0.0 |
|
| 80 | - */ |
|
| 81 | - public function getIssuerOrganization(): ?string; |
|
| 77 | + /** |
|
| 78 | + * @return string|null |
|
| 79 | + * @since 8.0.0 |
|
| 80 | + */ |
|
| 81 | + public function getIssuerOrganization(): ?string; |
|
| 82 | 82 | } |