@@ -31,11 +31,11 @@ |
||
31 | 31 | * @since 20.0.0 |
32 | 32 | */ |
33 | 33 | interface IRootMountProvider { |
34 | - /** |
|
35 | - * Get all root mountpoints of this provider |
|
36 | - * |
|
37 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
38 | - * @since 20.0.0 |
|
39 | - */ |
|
40 | - public function getRootMounts(IStorageFactory $loader): array; |
|
34 | + /** |
|
35 | + * Get all root mountpoints of this provider |
|
36 | + * |
|
37 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
38 | + * @since 20.0.0 |
|
39 | + */ |
|
40 | + public function getRootMounts(IStorageFactory $loader): array; |
|
41 | 41 | } |
@@ -36,56 +36,56 @@ |
||
36 | 36 | * @since 18.0.0 |
37 | 37 | */ |
38 | 38 | interface IRuleMatcher extends IFileCheck { |
39 | - /** |
|
40 | - * This method is left for backwards compatibility and easier porting of |
|
41 | - * apps. Please use 'getFlows' instead (and setOperation if you implement |
|
42 | - * an IComplexOperation). |
|
43 | - * |
|
44 | - * @since 18.0.0 |
|
45 | - * @deprecated 18.0.0 |
|
46 | - */ |
|
47 | - public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array; |
|
39 | + /** |
|
40 | + * This method is left for backwards compatibility and easier porting of |
|
41 | + * apps. Please use 'getFlows' instead (and setOperation if you implement |
|
42 | + * an IComplexOperation). |
|
43 | + * |
|
44 | + * @since 18.0.0 |
|
45 | + * @deprecated 18.0.0 |
|
46 | + */ |
|
47 | + public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @throws RuntimeException |
|
51 | - * @since 18.0.0 |
|
52 | - */ |
|
53 | - public function getFlows(bool $returnFirstMatchingOperationOnly = true): array; |
|
49 | + /** |
|
50 | + * @throws RuntimeException |
|
51 | + * @since 18.0.0 |
|
52 | + */ |
|
53 | + public function getFlows(bool $returnFirstMatchingOperationOnly = true): array; |
|
54 | 54 | |
55 | - /** |
|
56 | - * this method can only be called once and is typically called by the |
|
57 | - * Flow engine, unless for IComplexOperations. |
|
58 | - * |
|
59 | - * @throws RuntimeException |
|
60 | - * @since 18.0.0 |
|
61 | - */ |
|
62 | - public function setOperation(IOperation $operation): void; |
|
55 | + /** |
|
56 | + * this method can only be called once and is typically called by the |
|
57 | + * Flow engine, unless for IComplexOperations. |
|
58 | + * |
|
59 | + * @throws RuntimeException |
|
60 | + * @since 18.0.0 |
|
61 | + */ |
|
62 | + public function setOperation(IOperation $operation): void; |
|
63 | 63 | |
64 | - /** |
|
65 | - * this method can only be called once and is typically called by the |
|
66 | - * Flow engine, unless for IComplexOperations. |
|
67 | - * |
|
68 | - * @throws RuntimeException |
|
69 | - * @since 18.0.0 |
|
70 | - */ |
|
71 | - public function setEntity(IEntity $entity): void; |
|
64 | + /** |
|
65 | + * this method can only be called once and is typically called by the |
|
66 | + * Flow engine, unless for IComplexOperations. |
|
67 | + * |
|
68 | + * @throws RuntimeException |
|
69 | + * @since 18.0.0 |
|
70 | + */ |
|
71 | + public function setEntity(IEntity $entity): void; |
|
72 | 72 | |
73 | - /** |
|
74 | - * returns the entity which might provide more information, depending on |
|
75 | - * the interfaces it implements |
|
76 | - * |
|
77 | - * @return IEntity |
|
78 | - * @since 18.0.0 |
|
79 | - */ |
|
80 | - public function getEntity(): IEntity; |
|
73 | + /** |
|
74 | + * returns the entity which might provide more information, depending on |
|
75 | + * the interfaces it implements |
|
76 | + * |
|
77 | + * @return IEntity |
|
78 | + * @since 18.0.0 |
|
79 | + */ |
|
80 | + public function getEntity(): IEntity; |
|
81 | 81 | |
82 | - /** |
|
83 | - * this method can be called once to set the event name that is currently |
|
84 | - * being processed. The workflow engine takes care of this usually, only an |
|
85 | - * IComplexOperation might want to make use of it. |
|
86 | - * |
|
87 | - * @throws RuntimeException |
|
88 | - * @since 20.0.0 |
|
89 | - */ |
|
90 | - public function setEventName(string $eventName): void; |
|
82 | + /** |
|
83 | + * this method can be called once to set the event name that is currently |
|
84 | + * being processed. The workflow engine takes care of this usually, only an |
|
85 | + * IComplexOperation might want to make use of it. |
|
86 | + * |
|
87 | + * @throws RuntimeException |
|
88 | + * @since 20.0.0 |
|
89 | + */ |
|
90 | + public function setEventName(string $eventName): void; |
|
91 | 91 | } |
@@ -36,22 +36,22 @@ |
||
36 | 36 | */ |
37 | 37 | class Version0002Date20200902144824 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 20.0.0 |
|
45 | - */ |
|
46 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
47 | - /** @var ISchemaWrapper $schema */ |
|
48 | - $schema = $schemaClosure(); |
|
49 | - |
|
50 | - $statusTable = $schema->getTable('user_status'); |
|
51 | - |
|
52 | - $statusTable->addIndex(['status_timestamp'], 'user_status_tstmp_ix'); |
|
53 | - $statusTable->addIndex(['is_user_defined', 'status'], 'user_status_iud_ix'); |
|
54 | - |
|
55 | - return $schema; |
|
56 | - } |
|
39 | + /** |
|
40 | + * @param IOutput $output |
|
41 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
42 | + * @param array $options |
|
43 | + * @return null|ISchemaWrapper |
|
44 | + * @since 20.0.0 |
|
45 | + */ |
|
46 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
47 | + /** @var ISchemaWrapper $schema */ |
|
48 | + $schema = $schemaClosure(); |
|
49 | + |
|
50 | + $statusTable = $schema->getTable('user_status'); |
|
51 | + |
|
52 | + $statusTable->addIndex(['status_timestamp'], 'user_status_tstmp_ix'); |
|
53 | + $statusTable->addIndex(['is_user_defined', 'status'], 'user_status_iud_ix'); |
|
54 | + |
|
55 | + return $schema; |
|
56 | + } |
|
57 | 57 | } |
@@ -24,30 +24,30 @@ |
||
24 | 24 | namespace OC\Files\Cache; |
25 | 25 | |
26 | 26 | class NullWatcher extends Watcher { |
27 | - private $policy; |
|
27 | + private $policy; |
|
28 | 28 | |
29 | - public function __construct() { |
|
30 | - } |
|
29 | + public function __construct() { |
|
30 | + } |
|
31 | 31 | |
32 | - public function setPolicy($policy) { |
|
33 | - $this->policy = $policy; |
|
34 | - } |
|
32 | + public function setPolicy($policy) { |
|
33 | + $this->policy = $policy; |
|
34 | + } |
|
35 | 35 | |
36 | - public function getPolicy() { |
|
37 | - return $this->policy; |
|
38 | - } |
|
36 | + public function getPolicy() { |
|
37 | + return $this->policy; |
|
38 | + } |
|
39 | 39 | |
40 | - public function checkUpdate($path, $cachedEntry = null) { |
|
41 | - return false; |
|
42 | - } |
|
40 | + public function checkUpdate($path, $cachedEntry = null) { |
|
41 | + return false; |
|
42 | + } |
|
43 | 43 | |
44 | - public function update($path, $cachedData) { |
|
45 | - } |
|
44 | + public function update($path, $cachedData) { |
|
45 | + } |
|
46 | 46 | |
47 | - public function needsUpdate($path, $cachedData) { |
|
48 | - return false; |
|
49 | - } |
|
47 | + public function needsUpdate($path, $cachedData) { |
|
48 | + return false; |
|
49 | + } |
|
50 | 50 | |
51 | - public function cleanFolder($path) { |
|
52 | - } |
|
51 | + public function cleanFolder($path) { |
|
52 | + } |
|
53 | 53 | } |
@@ -106,7 +106,7 @@ |
||
106 | 106 | $jsTrans = []; |
107 | 107 | foreach ($translations as $id => $val) { |
108 | 108 | if (is_array($val)) { |
109 | - $val = '[ ' . implode(',', $val) . ']'; |
|
109 | + $val = '[ '.implode(',', $val).']'; |
|
110 | 110 | } |
111 | 111 | $jsTrans[] = "\"$id\" : \"$val\""; |
112 | 112 | } |
@@ -22,141 +22,141 @@ |
||
22 | 22 | use UnexpectedValueException; |
23 | 23 | |
24 | 24 | class CreateJs extends Command implements CompletionAwareInterface { |
25 | - public function __construct( |
|
26 | - protected IAppManager $appManager, |
|
27 | - ) { |
|
28 | - parent::__construct(); |
|
29 | - } |
|
30 | - |
|
31 | - protected function configure() { |
|
32 | - $this |
|
33 | - ->setName('l10n:createjs') |
|
34 | - ->setDescription('Create javascript translation files for a given app') |
|
35 | - ->addArgument( |
|
36 | - 'app', |
|
37 | - InputOption::VALUE_REQUIRED, |
|
38 | - 'name of the app' |
|
39 | - ) |
|
40 | - ->addArgument( |
|
41 | - 'lang', |
|
42 | - InputOption::VALUE_OPTIONAL, |
|
43 | - 'name of the language' |
|
44 | - ); |
|
45 | - } |
|
46 | - |
|
47 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
48 | - $app = $input->getArgument('app'); |
|
49 | - $lang = $input->getArgument('lang'); |
|
50 | - |
|
51 | - $path = $this->appManager->getAppPath($app); |
|
52 | - $languages = $lang; |
|
53 | - if (empty($lang)) { |
|
54 | - $languages = $this->getAllLanguages($path); |
|
55 | - } |
|
56 | - |
|
57 | - foreach ($languages as $lang) { |
|
58 | - $this->writeFiles($app, $path, $lang, $output); |
|
59 | - } |
|
60 | - return 0; |
|
61 | - } |
|
62 | - |
|
63 | - private function getAllLanguages($path) { |
|
64 | - $result = []; |
|
65 | - foreach (new DirectoryIterator("$path/l10n") as $fileInfo) { |
|
66 | - if ($fileInfo->isDot()) { |
|
67 | - continue; |
|
68 | - } |
|
69 | - if ($fileInfo->isDir()) { |
|
70 | - continue; |
|
71 | - } |
|
72 | - if ($fileInfo->getExtension() !== 'php') { |
|
73 | - continue; |
|
74 | - } |
|
75 | - $result[] = substr($fileInfo->getBasename(), 0, -4); |
|
76 | - } |
|
77 | - |
|
78 | - return $result; |
|
79 | - } |
|
80 | - |
|
81 | - private function writeFiles($app, $path, $lang, OutputInterface $output) { |
|
82 | - [$translations, $plurals] = $this->loadTranslations($path, $lang); |
|
83 | - $this->writeJsFile($app, $path, $lang, $output, $translations, $plurals); |
|
84 | - $this->writeJsonFile($path, $lang, $output, $translations, $plurals); |
|
85 | - } |
|
86 | - |
|
87 | - private function writeJsFile($app, $path, $lang, OutputInterface $output, $translations, $plurals) { |
|
88 | - $jsFile = "$path/l10n/$lang.js"; |
|
89 | - if (file_exists($jsFile)) { |
|
90 | - $output->writeln("File already exists: $jsFile"); |
|
91 | - return; |
|
92 | - } |
|
93 | - $content = "OC.L10N.register(\n \"$app\",\n {\n "; |
|
94 | - $jsTrans = []; |
|
95 | - foreach ($translations as $id => $val) { |
|
96 | - if (is_array($val)) { |
|
97 | - $val = '[ ' . implode(',', $val) . ']'; |
|
98 | - } |
|
99 | - $jsTrans[] = "\"$id\" : \"$val\""; |
|
100 | - } |
|
101 | - $content .= implode(",\n ", $jsTrans); |
|
102 | - $content .= "\n},\n\"$plurals\");\n"; |
|
103 | - |
|
104 | - file_put_contents($jsFile, $content); |
|
105 | - $output->writeln("Javascript translation file generated: $jsFile"); |
|
106 | - } |
|
107 | - |
|
108 | - private function writeJsonFile($path, $lang, OutputInterface $output, $translations, $plurals) { |
|
109 | - $jsFile = "$path/l10n/$lang.json"; |
|
110 | - if (file_exists($jsFile)) { |
|
111 | - $output->writeln("File already exists: $jsFile"); |
|
112 | - return; |
|
113 | - } |
|
114 | - $content = ['translations' => $translations, 'pluralForm' => $plurals]; |
|
115 | - file_put_contents($jsFile, json_encode($content)); |
|
116 | - $output->writeln("Json translation file generated: $jsFile"); |
|
117 | - } |
|
118 | - |
|
119 | - private function loadTranslations($path, $lang) { |
|
120 | - $phpFile = "$path/l10n/$lang.php"; |
|
121 | - $TRANSLATIONS = []; |
|
122 | - $PLURAL_FORMS = ''; |
|
123 | - if (!file_exists($phpFile)) { |
|
124 | - throw new UnexpectedValueException("PHP translation file <$phpFile> does not exist."); |
|
125 | - } |
|
126 | - require $phpFile; |
|
127 | - |
|
128 | - return [$TRANSLATIONS, $PLURAL_FORMS]; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Return possible values for the named option |
|
133 | - * |
|
134 | - * @param string $optionName |
|
135 | - * @param CompletionContext $context |
|
136 | - * @return string[] |
|
137 | - */ |
|
138 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
139 | - return []; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Return possible values for the named argument |
|
144 | - * |
|
145 | - * @param string $argumentName |
|
146 | - * @param CompletionContext $context |
|
147 | - * @return string[] |
|
148 | - */ |
|
149 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
150 | - if ($argumentName === 'app') { |
|
151 | - return $this->appManager->getAllAppsInAppsFolders(); |
|
152 | - } elseif ($argumentName === 'lang') { |
|
153 | - $appName = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
154 | - try { |
|
155 | - return $this->getAllLanguages($this->appManager->getAppPath($appName)); |
|
156 | - } catch (AppPathNotFoundException) { |
|
157 | - return []; |
|
158 | - } |
|
159 | - } |
|
160 | - return []; |
|
161 | - } |
|
25 | + public function __construct( |
|
26 | + protected IAppManager $appManager, |
|
27 | + ) { |
|
28 | + parent::__construct(); |
|
29 | + } |
|
30 | + |
|
31 | + protected function configure() { |
|
32 | + $this |
|
33 | + ->setName('l10n:createjs') |
|
34 | + ->setDescription('Create javascript translation files for a given app') |
|
35 | + ->addArgument( |
|
36 | + 'app', |
|
37 | + InputOption::VALUE_REQUIRED, |
|
38 | + 'name of the app' |
|
39 | + ) |
|
40 | + ->addArgument( |
|
41 | + 'lang', |
|
42 | + InputOption::VALUE_OPTIONAL, |
|
43 | + 'name of the language' |
|
44 | + ); |
|
45 | + } |
|
46 | + |
|
47 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
48 | + $app = $input->getArgument('app'); |
|
49 | + $lang = $input->getArgument('lang'); |
|
50 | + |
|
51 | + $path = $this->appManager->getAppPath($app); |
|
52 | + $languages = $lang; |
|
53 | + if (empty($lang)) { |
|
54 | + $languages = $this->getAllLanguages($path); |
|
55 | + } |
|
56 | + |
|
57 | + foreach ($languages as $lang) { |
|
58 | + $this->writeFiles($app, $path, $lang, $output); |
|
59 | + } |
|
60 | + return 0; |
|
61 | + } |
|
62 | + |
|
63 | + private function getAllLanguages($path) { |
|
64 | + $result = []; |
|
65 | + foreach (new DirectoryIterator("$path/l10n") as $fileInfo) { |
|
66 | + if ($fileInfo->isDot()) { |
|
67 | + continue; |
|
68 | + } |
|
69 | + if ($fileInfo->isDir()) { |
|
70 | + continue; |
|
71 | + } |
|
72 | + if ($fileInfo->getExtension() !== 'php') { |
|
73 | + continue; |
|
74 | + } |
|
75 | + $result[] = substr($fileInfo->getBasename(), 0, -4); |
|
76 | + } |
|
77 | + |
|
78 | + return $result; |
|
79 | + } |
|
80 | + |
|
81 | + private function writeFiles($app, $path, $lang, OutputInterface $output) { |
|
82 | + [$translations, $plurals] = $this->loadTranslations($path, $lang); |
|
83 | + $this->writeJsFile($app, $path, $lang, $output, $translations, $plurals); |
|
84 | + $this->writeJsonFile($path, $lang, $output, $translations, $plurals); |
|
85 | + } |
|
86 | + |
|
87 | + private function writeJsFile($app, $path, $lang, OutputInterface $output, $translations, $plurals) { |
|
88 | + $jsFile = "$path/l10n/$lang.js"; |
|
89 | + if (file_exists($jsFile)) { |
|
90 | + $output->writeln("File already exists: $jsFile"); |
|
91 | + return; |
|
92 | + } |
|
93 | + $content = "OC.L10N.register(\n \"$app\",\n {\n "; |
|
94 | + $jsTrans = []; |
|
95 | + foreach ($translations as $id => $val) { |
|
96 | + if (is_array($val)) { |
|
97 | + $val = '[ ' . implode(',', $val) . ']'; |
|
98 | + } |
|
99 | + $jsTrans[] = "\"$id\" : \"$val\""; |
|
100 | + } |
|
101 | + $content .= implode(",\n ", $jsTrans); |
|
102 | + $content .= "\n},\n\"$plurals\");\n"; |
|
103 | + |
|
104 | + file_put_contents($jsFile, $content); |
|
105 | + $output->writeln("Javascript translation file generated: $jsFile"); |
|
106 | + } |
|
107 | + |
|
108 | + private function writeJsonFile($path, $lang, OutputInterface $output, $translations, $plurals) { |
|
109 | + $jsFile = "$path/l10n/$lang.json"; |
|
110 | + if (file_exists($jsFile)) { |
|
111 | + $output->writeln("File already exists: $jsFile"); |
|
112 | + return; |
|
113 | + } |
|
114 | + $content = ['translations' => $translations, 'pluralForm' => $plurals]; |
|
115 | + file_put_contents($jsFile, json_encode($content)); |
|
116 | + $output->writeln("Json translation file generated: $jsFile"); |
|
117 | + } |
|
118 | + |
|
119 | + private function loadTranslations($path, $lang) { |
|
120 | + $phpFile = "$path/l10n/$lang.php"; |
|
121 | + $TRANSLATIONS = []; |
|
122 | + $PLURAL_FORMS = ''; |
|
123 | + if (!file_exists($phpFile)) { |
|
124 | + throw new UnexpectedValueException("PHP translation file <$phpFile> does not exist."); |
|
125 | + } |
|
126 | + require $phpFile; |
|
127 | + |
|
128 | + return [$TRANSLATIONS, $PLURAL_FORMS]; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Return possible values for the named option |
|
133 | + * |
|
134 | + * @param string $optionName |
|
135 | + * @param CompletionContext $context |
|
136 | + * @return string[] |
|
137 | + */ |
|
138 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
139 | + return []; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Return possible values for the named argument |
|
144 | + * |
|
145 | + * @param string $argumentName |
|
146 | + * @param CompletionContext $context |
|
147 | + * @return string[] |
|
148 | + */ |
|
149 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
150 | + if ($argumentName === 'app') { |
|
151 | + return $this->appManager->getAllAppsInAppsFolders(); |
|
152 | + } elseif ($argumentName === 'lang') { |
|
153 | + $appName = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
154 | + try { |
|
155 | + return $this->getAllLanguages($this->appManager->getAppPath($appName)); |
|
156 | + } catch (AppPathNotFoundException) { |
|
157 | + return []; |
|
158 | + } |
|
159 | + } |
|
160 | + return []; |
|
161 | + } |
|
162 | 162 | } |
@@ -73,7 +73,7 @@ |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | $providers = $this->registry->getProviderStates($user); |
76 | - $state2fa = array_reduce($providers, function (bool $carry, bool $state) { |
|
76 | + $state2fa = array_reduce($providers, function(bool $carry, bool $state) { |
|
77 | 77 | return $carry || $state; |
78 | 78 | }, false); |
79 | 79 |
@@ -17,61 +17,61 @@ |
||
17 | 17 | |
18 | 18 | class RememberBackupCodesJob extends TimedJob { |
19 | 19 | |
20 | - public function __construct( |
|
21 | - private IRegistry $registry, |
|
22 | - private IUserManager $userManager, |
|
23 | - ITimeFactory $timeFactory, |
|
24 | - private IManager $notificationManager, |
|
25 | - private IJobList $jobList, |
|
26 | - ) { |
|
27 | - parent::__construct($timeFactory); |
|
28 | - $this->time = $timeFactory; |
|
20 | + public function __construct( |
|
21 | + private IRegistry $registry, |
|
22 | + private IUserManager $userManager, |
|
23 | + ITimeFactory $timeFactory, |
|
24 | + private IManager $notificationManager, |
|
25 | + private IJobList $jobList, |
|
26 | + ) { |
|
27 | + parent::__construct($timeFactory); |
|
28 | + $this->time = $timeFactory; |
|
29 | 29 | |
30 | - $this->setInterval(60 * 60 * 24 * 14); |
|
31 | - $this->setTimeSensitivity(self::TIME_INSENSITIVE); |
|
32 | - } |
|
30 | + $this->setInterval(60 * 60 * 24 * 14); |
|
31 | + $this->setTimeSensitivity(self::TIME_INSENSITIVE); |
|
32 | + } |
|
33 | 33 | |
34 | - protected function run($argument) { |
|
35 | - $uid = $argument['uid']; |
|
36 | - $user = $this->userManager->get($uid); |
|
34 | + protected function run($argument) { |
|
35 | + $uid = $argument['uid']; |
|
36 | + $user = $this->userManager->get($uid); |
|
37 | 37 | |
38 | - if ($user === null) { |
|
39 | - // We can't run with an invalid user |
|
40 | - $this->jobList->remove(self::class, $argument); |
|
41 | - return; |
|
42 | - } |
|
38 | + if ($user === null) { |
|
39 | + // We can't run with an invalid user |
|
40 | + $this->jobList->remove(self::class, $argument); |
|
41 | + return; |
|
42 | + } |
|
43 | 43 | |
44 | - $providers = $this->registry->getProviderStates($user); |
|
45 | - $state2fa = array_reduce($providers, function (bool $carry, bool $state) { |
|
46 | - return $carry || $state; |
|
47 | - }, false); |
|
44 | + $providers = $this->registry->getProviderStates($user); |
|
45 | + $state2fa = array_reduce($providers, function (bool $carry, bool $state) { |
|
46 | + return $carry || $state; |
|
47 | + }, false); |
|
48 | 48 | |
49 | - /* |
|
49 | + /* |
|
50 | 50 | * If no provider is active or if the backup codes are already generate |
51 | 51 | * we can remove the job |
52 | 52 | */ |
53 | - if ($state2fa === false || (isset($providers['backup_codes']) && $providers['backup_codes'] === true)) { |
|
54 | - // Backup codes already generated lets remove this job |
|
55 | - $this->jobList->remove(self::class, $argument); |
|
56 | - return; |
|
57 | - } |
|
53 | + if ($state2fa === false || (isset($providers['backup_codes']) && $providers['backup_codes'] === true)) { |
|
54 | + // Backup codes already generated lets remove this job |
|
55 | + $this->jobList->remove(self::class, $argument); |
|
56 | + return; |
|
57 | + } |
|
58 | 58 | |
59 | - $date = new \DateTime(); |
|
60 | - $date->setTimestamp($this->time->getTime()); |
|
59 | + $date = new \DateTime(); |
|
60 | + $date->setTimestamp($this->time->getTime()); |
|
61 | 61 | |
62 | - $notification = $this->notificationManager->createNotification(); |
|
63 | - $notification->setApp('twofactor_backupcodes') |
|
64 | - ->setUser($user->getUID()) |
|
65 | - ->setObject('create', 'codes') |
|
66 | - ->setSubject('create_backupcodes'); |
|
67 | - $this->notificationManager->markProcessed($notification); |
|
62 | + $notification = $this->notificationManager->createNotification(); |
|
63 | + $notification->setApp('twofactor_backupcodes') |
|
64 | + ->setUser($user->getUID()) |
|
65 | + ->setObject('create', 'codes') |
|
66 | + ->setSubject('create_backupcodes'); |
|
67 | + $this->notificationManager->markProcessed($notification); |
|
68 | 68 | |
69 | - if (!$user->isEnabled()) { |
|
70 | - // Don't recreate a notification for a user that can not read it |
|
71 | - $this->jobList->remove(self::class, $argument); |
|
72 | - return; |
|
73 | - } |
|
74 | - $notification->setDateTime($date); |
|
75 | - $this->notificationManager->notify($notification); |
|
76 | - } |
|
69 | + if (!$user->isEnabled()) { |
|
70 | + // Don't recreate a notification for a user that can not read it |
|
71 | + $this->jobList->remove(self::class, $argument); |
|
72 | + return; |
|
73 | + } |
|
74 | + $notification->setDateTime($date); |
|
75 | + $this->notificationManager->notify($notification); |
|
76 | + } |
|
77 | 77 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function discover(string $remote, string $service, bool $skipCache = false): array { |
70 | 70 | // Check the cache first |
71 | 71 | if ($skipCache === false) { |
72 | - $cacheData = $this->cache->get($remote . '#' . $service); |
|
72 | + $cacheData = $this->cache->get($remote.'#'.$service); |
|
73 | 73 | if ($cacheData) { |
74 | 74 | $data = json_decode($cacheData, true); |
75 | 75 | if (\is_array($data)) { |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | |
83 | 83 | // query the remote server for available services |
84 | 84 | try { |
85 | - $response = $this->client->get($remote . '/ocs-provider/', [ |
|
85 | + $response = $this->client->get($remote.'/ocs-provider/', [ |
|
86 | 86 | 'timeout' => 10, |
87 | 87 | 'connect_timeout' => 10, |
88 | 88 | ]); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | // Write into cache |
100 | - $this->cache->set($remote . '#' . $service, json_encode($discoveredServices), 60 * 60 * 24); |
|
100 | + $this->cache->set($remote.'#'.$service, json_encode($discoveredServices), 60 * 60 * 24); |
|
101 | 101 | return $discoveredServices; |
102 | 102 | } |
103 | 103 | |
@@ -130,6 +130,6 @@ discard block |
||
130 | 130 | * @return bool |
131 | 131 | */ |
132 | 132 | protected function isSafeUrl(string $url): bool { |
133 | - return (bool)preg_match('/^[\/\.\-A-Za-z0-9]+$/', $url); |
|
133 | + return (bool) preg_match('/^[\/\.\-A-Za-z0-9]+$/', $url); |
|
134 | 134 | } |
135 | 135 | } |
@@ -16,98 +16,98 @@ |
||
16 | 16 | use OCP\OCS\IDiscoveryService; |
17 | 17 | |
18 | 18 | class DiscoveryService implements IDiscoveryService { |
19 | - /** @var ICache */ |
|
20 | - private ICache $cache; |
|
19 | + /** @var ICache */ |
|
20 | + private ICache $cache; |
|
21 | 21 | |
22 | - /** @var IClient */ |
|
23 | - private IClient $client; |
|
22 | + /** @var IClient */ |
|
23 | + private IClient $client; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param ICacheFactory $cacheFactory |
|
27 | - * @param IClientService $clientService |
|
28 | - */ |
|
29 | - public function __construct(ICacheFactory $cacheFactory, |
|
30 | - IClientService $clientService, |
|
31 | - ) { |
|
32 | - $this->cache = $cacheFactory->createDistributed('ocs-discovery'); |
|
33 | - $this->client = $clientService->newClient(); |
|
34 | - } |
|
25 | + /** |
|
26 | + * @param ICacheFactory $cacheFactory |
|
27 | + * @param IClientService $clientService |
|
28 | + */ |
|
29 | + public function __construct(ICacheFactory $cacheFactory, |
|
30 | + IClientService $clientService, |
|
31 | + ) { |
|
32 | + $this->cache = $cacheFactory->createDistributed('ocs-discovery'); |
|
33 | + $this->client = $clientService->newClient(); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Discover OCS end-points |
|
39 | - * |
|
40 | - * If no valid discovery data is found the defaults are returned |
|
41 | - * |
|
42 | - * @param string $remote |
|
43 | - * @param string $service the service you want to discover |
|
44 | - * @param bool $skipCache We won't check if the data is in the cache. This is useful if a background job is updating the status |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function discover(string $remote, string $service, bool $skipCache = false): array { |
|
48 | - // Check the cache first |
|
49 | - if ($skipCache === false) { |
|
50 | - $cacheData = $this->cache->get($remote . '#' . $service); |
|
51 | - if ($cacheData) { |
|
52 | - $data = json_decode($cacheData, true); |
|
53 | - if (\is_array($data)) { |
|
54 | - return $data; |
|
55 | - } |
|
56 | - } |
|
57 | - } |
|
37 | + /** |
|
38 | + * Discover OCS end-points |
|
39 | + * |
|
40 | + * If no valid discovery data is found the defaults are returned |
|
41 | + * |
|
42 | + * @param string $remote |
|
43 | + * @param string $service the service you want to discover |
|
44 | + * @param bool $skipCache We won't check if the data is in the cache. This is useful if a background job is updating the status |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function discover(string $remote, string $service, bool $skipCache = false): array { |
|
48 | + // Check the cache first |
|
49 | + if ($skipCache === false) { |
|
50 | + $cacheData = $this->cache->get($remote . '#' . $service); |
|
51 | + if ($cacheData) { |
|
52 | + $data = json_decode($cacheData, true); |
|
53 | + if (\is_array($data)) { |
|
54 | + return $data; |
|
55 | + } |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - $discoveredServices = []; |
|
59 | + $discoveredServices = []; |
|
60 | 60 | |
61 | - // query the remote server for available services |
|
62 | - try { |
|
63 | - $response = $this->client->get($remote . '/ocs-provider/', [ |
|
64 | - 'timeout' => 10, |
|
65 | - 'connect_timeout' => 10, |
|
66 | - ]); |
|
67 | - if ($response->getStatusCode() === Http::STATUS_OK) { |
|
68 | - $decodedServices = json_decode($response->getBody(), true); |
|
69 | - if (\is_array($decodedServices)) { |
|
70 | - $discoveredServices = $this->getEndpoints($decodedServices, $service); |
|
71 | - } |
|
72 | - } |
|
73 | - } catch (\Exception $e) { |
|
74 | - // if we couldn't discover the service or any end-points we return a empty array |
|
75 | - } |
|
61 | + // query the remote server for available services |
|
62 | + try { |
|
63 | + $response = $this->client->get($remote . '/ocs-provider/', [ |
|
64 | + 'timeout' => 10, |
|
65 | + 'connect_timeout' => 10, |
|
66 | + ]); |
|
67 | + if ($response->getStatusCode() === Http::STATUS_OK) { |
|
68 | + $decodedServices = json_decode($response->getBody(), true); |
|
69 | + if (\is_array($decodedServices)) { |
|
70 | + $discoveredServices = $this->getEndpoints($decodedServices, $service); |
|
71 | + } |
|
72 | + } |
|
73 | + } catch (\Exception $e) { |
|
74 | + // if we couldn't discover the service or any end-points we return a empty array |
|
75 | + } |
|
76 | 76 | |
77 | - // Write into cache |
|
78 | - $this->cache->set($remote . '#' . $service, json_encode($discoveredServices), 60 * 60 * 24); |
|
79 | - return $discoveredServices; |
|
80 | - } |
|
77 | + // Write into cache |
|
78 | + $this->cache->set($remote . '#' . $service, json_encode($discoveredServices), 60 * 60 * 24); |
|
79 | + return $discoveredServices; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * get requested end-points from the requested service |
|
84 | - * |
|
85 | - * @param array $decodedServices |
|
86 | - * @param string $service |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - protected function getEndpoints(array $decodedServices, string $service): array { |
|
90 | - $discoveredServices = []; |
|
82 | + /** |
|
83 | + * get requested end-points from the requested service |
|
84 | + * |
|
85 | + * @param array $decodedServices |
|
86 | + * @param string $service |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + protected function getEndpoints(array $decodedServices, string $service): array { |
|
90 | + $discoveredServices = []; |
|
91 | 91 | |
92 | - if (isset($decodedServices['services'][$service]['endpoints'])) { |
|
93 | - foreach ($decodedServices['services'][$service]['endpoints'] as $endpoint => $url) { |
|
94 | - if ($this->isSafeUrl($url)) { |
|
95 | - $discoveredServices[$endpoint] = $url; |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
92 | + if (isset($decodedServices['services'][$service]['endpoints'])) { |
|
93 | + foreach ($decodedServices['services'][$service]['endpoints'] as $endpoint => $url) { |
|
94 | + if ($this->isSafeUrl($url)) { |
|
95 | + $discoveredServices[$endpoint] = $url; |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | - return $discoveredServices; |
|
101 | - } |
|
100 | + return $discoveredServices; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Returns whether the specified URL includes only safe characters, if not |
|
105 | - * returns false |
|
106 | - * |
|
107 | - * @param string $url |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - protected function isSafeUrl(string $url): bool { |
|
111 | - return (bool)preg_match('/^[\/\.\-A-Za-z0-9]+$/', $url); |
|
112 | - } |
|
103 | + /** |
|
104 | + * Returns whether the specified URL includes only safe characters, if not |
|
105 | + * returns false |
|
106 | + * |
|
107 | + * @param string $url |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + protected function isSafeUrl(string $url): bool { |
|
111 | + return (bool)preg_match('/^[\/\.\-A-Za-z0-9]+$/', $url); |
|
112 | + } |
|
113 | 113 | } |
@@ -39,14 +39,14 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * actions that user backends can define |
41 | 41 | */ |
42 | - public const CREATE_USER = 1; // 1 << 0 |
|
43 | - public const SET_PASSWORD = 16; // 1 << 4 |
|
44 | - public const CHECK_PASSWORD = 256; // 1 << 8 |
|
45 | - public const GET_HOME = 4096; // 1 << 12 |
|
46 | - public const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
47 | - public const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
48 | - public const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
49 | - public const COUNT_USERS = 268435456; // 1 << 28 |
|
42 | + public const CREATE_USER = 1; // 1 << 0 |
|
43 | + public const SET_PASSWORD = 16; // 1 << 4 |
|
44 | + public const CHECK_PASSWORD = 256; // 1 << 8 |
|
45 | + public const GET_HOME = 4096; // 1 << 12 |
|
46 | + public const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
47 | + public const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
48 | + public const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
49 | + public const COUNT_USERS = 268435456; // 1 << 28 |
|
50 | 50 | |
51 | 51 | protected $possibleActions = [ |
52 | 52 | self::CREATE_USER => 'createUser', |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * compared with self::CREATE_USER etc. |
87 | 87 | */ |
88 | 88 | public function implementsActions($actions) { |
89 | - return (bool)($this->getSupportedActions() & $actions); |
|
89 | + return (bool) ($this->getSupportedActions() & $actions); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -14,136 +14,136 @@ |
||
14 | 14 | * capabilities. |
15 | 15 | */ |
16 | 16 | abstract class Backend implements UserInterface { |
17 | - /** |
|
18 | - * error code for functions not provided by the user backend |
|
19 | - */ |
|
20 | - public const NOT_IMPLEMENTED = -501; |
|
17 | + /** |
|
18 | + * error code for functions not provided by the user backend |
|
19 | + */ |
|
20 | + public const NOT_IMPLEMENTED = -501; |
|
21 | 21 | |
22 | - /** |
|
23 | - * actions that user backends can define |
|
24 | - */ |
|
25 | - public const CREATE_USER = 1; // 1 << 0 |
|
26 | - public const SET_PASSWORD = 16; // 1 << 4 |
|
27 | - public const CHECK_PASSWORD = 256; // 1 << 8 |
|
28 | - public const GET_HOME = 4096; // 1 << 12 |
|
29 | - public const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
30 | - public const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
31 | - public const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
32 | - public const COUNT_USERS = 268435456; // 1 << 28 |
|
22 | + /** |
|
23 | + * actions that user backends can define |
|
24 | + */ |
|
25 | + public const CREATE_USER = 1; // 1 << 0 |
|
26 | + public const SET_PASSWORD = 16; // 1 << 4 |
|
27 | + public const CHECK_PASSWORD = 256; // 1 << 8 |
|
28 | + public const GET_HOME = 4096; // 1 << 12 |
|
29 | + public const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
30 | + public const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
31 | + public const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
32 | + public const COUNT_USERS = 268435456; // 1 << 28 |
|
33 | 33 | |
34 | - protected $possibleActions = [ |
|
35 | - self::CREATE_USER => 'createUser', |
|
36 | - self::SET_PASSWORD => 'setPassword', |
|
37 | - self::CHECK_PASSWORD => 'checkPassword', |
|
38 | - self::GET_HOME => 'getHome', |
|
39 | - self::GET_DISPLAYNAME => 'getDisplayName', |
|
40 | - self::SET_DISPLAYNAME => 'setDisplayName', |
|
41 | - self::PROVIDE_AVATAR => 'canChangeAvatar', |
|
42 | - self::COUNT_USERS => 'countUsers', |
|
43 | - ]; |
|
34 | + protected $possibleActions = [ |
|
35 | + self::CREATE_USER => 'createUser', |
|
36 | + self::SET_PASSWORD => 'setPassword', |
|
37 | + self::CHECK_PASSWORD => 'checkPassword', |
|
38 | + self::GET_HOME => 'getHome', |
|
39 | + self::GET_DISPLAYNAME => 'getDisplayName', |
|
40 | + self::SET_DISPLAYNAME => 'setDisplayName', |
|
41 | + self::PROVIDE_AVATAR => 'canChangeAvatar', |
|
42 | + self::COUNT_USERS => 'countUsers', |
|
43 | + ]; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Get all supported actions |
|
47 | - * @return int bitwise-or'ed actions |
|
48 | - * |
|
49 | - * Returns the supported actions as int to be |
|
50 | - * compared with self::CREATE_USER etc. |
|
51 | - */ |
|
52 | - public function getSupportedActions() { |
|
53 | - $actions = 0; |
|
54 | - foreach ($this->possibleActions as $action => $methodName) { |
|
55 | - if (method_exists($this, $methodName)) { |
|
56 | - $actions |= $action; |
|
57 | - } |
|
58 | - } |
|
45 | + /** |
|
46 | + * Get all supported actions |
|
47 | + * @return int bitwise-or'ed actions |
|
48 | + * |
|
49 | + * Returns the supported actions as int to be |
|
50 | + * compared with self::CREATE_USER etc. |
|
51 | + */ |
|
52 | + public function getSupportedActions() { |
|
53 | + $actions = 0; |
|
54 | + foreach ($this->possibleActions as $action => $methodName) { |
|
55 | + if (method_exists($this, $methodName)) { |
|
56 | + $actions |= $action; |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - return $actions; |
|
61 | - } |
|
60 | + return $actions; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Check if backend implements actions |
|
65 | - * @param int $actions bitwise-or'ed actions |
|
66 | - * @return boolean |
|
67 | - * |
|
68 | - * Returns the supported actions as int to be |
|
69 | - * compared with self::CREATE_USER etc. |
|
70 | - */ |
|
71 | - public function implementsActions($actions) { |
|
72 | - return (bool)($this->getSupportedActions() & $actions); |
|
73 | - } |
|
63 | + /** |
|
64 | + * Check if backend implements actions |
|
65 | + * @param int $actions bitwise-or'ed actions |
|
66 | + * @return boolean |
|
67 | + * |
|
68 | + * Returns the supported actions as int to be |
|
69 | + * compared with self::CREATE_USER etc. |
|
70 | + */ |
|
71 | + public function implementsActions($actions) { |
|
72 | + return (bool)($this->getSupportedActions() & $actions); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * delete a user |
|
77 | - * @param string $uid The username of the user to delete |
|
78 | - * @return bool |
|
79 | - * |
|
80 | - * Deletes a user |
|
81 | - */ |
|
82 | - public function deleteUser($uid) { |
|
83 | - return false; |
|
84 | - } |
|
75 | + /** |
|
76 | + * delete a user |
|
77 | + * @param string $uid The username of the user to delete |
|
78 | + * @return bool |
|
79 | + * |
|
80 | + * Deletes a user |
|
81 | + */ |
|
82 | + public function deleteUser($uid) { |
|
83 | + return false; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Get a list of all users |
|
88 | - * |
|
89 | - * @param string $search |
|
90 | - * @param null|int $limit |
|
91 | - * @param null|int $offset |
|
92 | - * @return string[] an array of all uids |
|
93 | - */ |
|
94 | - public function getUsers($search = '', $limit = null, $offset = null) { |
|
95 | - return []; |
|
96 | - } |
|
86 | + /** |
|
87 | + * Get a list of all users |
|
88 | + * |
|
89 | + * @param string $search |
|
90 | + * @param null|int $limit |
|
91 | + * @param null|int $offset |
|
92 | + * @return string[] an array of all uids |
|
93 | + */ |
|
94 | + public function getUsers($search = '', $limit = null, $offset = null) { |
|
95 | + return []; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * check if a user exists |
|
100 | - * @param string $uid the username |
|
101 | - * @return boolean |
|
102 | - */ |
|
103 | - public function userExists($uid) { |
|
104 | - return false; |
|
105 | - } |
|
98 | + /** |
|
99 | + * check if a user exists |
|
100 | + * @param string $uid the username |
|
101 | + * @return boolean |
|
102 | + */ |
|
103 | + public function userExists($uid) { |
|
104 | + return false; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * get the user's home directory |
|
109 | - * @param string $uid the username |
|
110 | - * @return string|boolean |
|
111 | - */ |
|
112 | - public function getHome(string $uid) { |
|
113 | - return false; |
|
114 | - } |
|
107 | + /** |
|
108 | + * get the user's home directory |
|
109 | + * @param string $uid the username |
|
110 | + * @return string|boolean |
|
111 | + */ |
|
112 | + public function getHome(string $uid) { |
|
113 | + return false; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * get display name of the user |
|
118 | - * @param string $uid user ID of the user |
|
119 | - * @return string display name |
|
120 | - */ |
|
121 | - public function getDisplayName($uid) { |
|
122 | - return $uid; |
|
123 | - } |
|
116 | + /** |
|
117 | + * get display name of the user |
|
118 | + * @param string $uid user ID of the user |
|
119 | + * @return string display name |
|
120 | + */ |
|
121 | + public function getDisplayName($uid) { |
|
122 | + return $uid; |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Get a list of all display names and user ids. |
|
127 | - * |
|
128 | - * @param string $search |
|
129 | - * @param int|null $limit |
|
130 | - * @param int|null $offset |
|
131 | - * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
132 | - */ |
|
133 | - public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
134 | - $displayNames = []; |
|
135 | - $users = $this->getUsers($search, $limit, $offset); |
|
136 | - foreach ($users as $user) { |
|
137 | - $displayNames[$user] = $user; |
|
138 | - } |
|
139 | - return $displayNames; |
|
140 | - } |
|
125 | + /** |
|
126 | + * Get a list of all display names and user ids. |
|
127 | + * |
|
128 | + * @param string $search |
|
129 | + * @param int|null $limit |
|
130 | + * @param int|null $offset |
|
131 | + * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
132 | + */ |
|
133 | + public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
134 | + $displayNames = []; |
|
135 | + $users = $this->getUsers($search, $limit, $offset); |
|
136 | + foreach ($users as $user) { |
|
137 | + $displayNames[$user] = $user; |
|
138 | + } |
|
139 | + return $displayNames; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Check if a user list is available or not |
|
144 | - * @return boolean if users can be listed or not |
|
145 | - */ |
|
146 | - public function hasUserListings() { |
|
147 | - return false; |
|
148 | - } |
|
142 | + /** |
|
143 | + * Check if a user list is available or not |
|
144 | + * @return boolean if users can be listed or not |
|
145 | + */ |
|
146 | + public function hasUserListings() { |
|
147 | + return false; |
|
148 | + } |
|
149 | 149 | } |
@@ -95,7 +95,7 @@ |
||
95 | 95 | foreach ($policies as $policy) { |
96 | 96 | header( |
97 | 97 | sprintf( |
98 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
98 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;'.$secureCookie.'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
99 | 99 | $cookiePrefix, |
100 | 100 | $policy, |
101 | 101 | $cookieParams['path'], |
@@ -13,76 +13,76 @@ |
||
13 | 13 | use OCP\AppFramework\Middleware; |
14 | 14 | |
15 | 15 | class SameSiteCookieMiddleware extends Middleware { |
16 | - /** @var Request */ |
|
17 | - private $request; |
|
16 | + /** @var Request */ |
|
17 | + private $request; |
|
18 | 18 | |
19 | - /** @var ControllerMethodReflector */ |
|
20 | - private $reflector; |
|
19 | + /** @var ControllerMethodReflector */ |
|
20 | + private $reflector; |
|
21 | 21 | |
22 | - public function __construct(Request $request, |
|
23 | - ControllerMethodReflector $reflector) { |
|
24 | - $this->request = $request; |
|
25 | - $this->reflector = $reflector; |
|
26 | - } |
|
22 | + public function __construct(Request $request, |
|
23 | + ControllerMethodReflector $reflector) { |
|
24 | + $this->request = $request; |
|
25 | + $this->reflector = $reflector; |
|
26 | + } |
|
27 | 27 | |
28 | - public function beforeController($controller, $methodName) { |
|
29 | - $requestUri = $this->request->getScriptName(); |
|
30 | - $processingScript = explode('/', $requestUri); |
|
31 | - $processingScript = $processingScript[count($processingScript) - 1]; |
|
28 | + public function beforeController($controller, $methodName) { |
|
29 | + $requestUri = $this->request->getScriptName(); |
|
30 | + $processingScript = explode('/', $requestUri); |
|
31 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
32 | 32 | |
33 | - if ($processingScript !== 'index.php') { |
|
34 | - return; |
|
35 | - } |
|
33 | + if ($processingScript !== 'index.php') { |
|
34 | + return; |
|
35 | + } |
|
36 | 36 | |
37 | - $noSSC = $this->reflector->hasAnnotation('NoSameSiteCookieRequired'); |
|
38 | - if ($noSSC) { |
|
39 | - return; |
|
40 | - } |
|
37 | + $noSSC = $this->reflector->hasAnnotation('NoSameSiteCookieRequired'); |
|
38 | + if ($noSSC) { |
|
39 | + return; |
|
40 | + } |
|
41 | 41 | |
42 | - if (!$this->request->passesLaxCookieCheck()) { |
|
43 | - throw new LaxSameSiteCookieFailedException(); |
|
44 | - } |
|
45 | - } |
|
42 | + if (!$this->request->passesLaxCookieCheck()) { |
|
43 | + throw new LaxSameSiteCookieFailedException(); |
|
44 | + } |
|
45 | + } |
|
46 | 46 | |
47 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
48 | - if ($exception instanceof LaxSameSiteCookieFailedException) { |
|
49 | - $response = new Response(); |
|
50 | - $response->setStatus(Http::STATUS_FOUND); |
|
51 | - $response->addHeader('Location', $this->request->getRequestUri()); |
|
47 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
48 | + if ($exception instanceof LaxSameSiteCookieFailedException) { |
|
49 | + $response = new Response(); |
|
50 | + $response->setStatus(Http::STATUS_FOUND); |
|
51 | + $response->addHeader('Location', $this->request->getRequestUri()); |
|
52 | 52 | |
53 | - $this->setSameSiteCookie(); |
|
53 | + $this->setSameSiteCookie(); |
|
54 | 54 | |
55 | - return $response; |
|
56 | - } |
|
55 | + return $response; |
|
56 | + } |
|
57 | 57 | |
58 | - throw $exception; |
|
59 | - } |
|
58 | + throw $exception; |
|
59 | + } |
|
60 | 60 | |
61 | - protected function setSameSiteCookie() { |
|
62 | - $cookieParams = $this->request->getCookieParams(); |
|
63 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
64 | - $policies = [ |
|
65 | - 'lax', |
|
66 | - 'strict', |
|
67 | - ]; |
|
61 | + protected function setSameSiteCookie() { |
|
62 | + $cookieParams = $this->request->getCookieParams(); |
|
63 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
64 | + $policies = [ |
|
65 | + 'lax', |
|
66 | + 'strict', |
|
67 | + ]; |
|
68 | 68 | |
69 | - // Append __Host to the cookie if it meets the requirements |
|
70 | - $cookiePrefix = ''; |
|
71 | - if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
72 | - $cookiePrefix = '__Host-'; |
|
73 | - } |
|
69 | + // Append __Host to the cookie if it meets the requirements |
|
70 | + $cookiePrefix = ''; |
|
71 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
72 | + $cookiePrefix = '__Host-'; |
|
73 | + } |
|
74 | 74 | |
75 | - foreach ($policies as $policy) { |
|
76 | - header( |
|
77 | - sprintf( |
|
78 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
79 | - $cookiePrefix, |
|
80 | - $policy, |
|
81 | - $cookieParams['path'], |
|
82 | - $policy |
|
83 | - ), |
|
84 | - false |
|
85 | - ); |
|
86 | - } |
|
87 | - } |
|
75 | + foreach ($policies as $policy) { |
|
76 | + header( |
|
77 | + sprintf( |
|
78 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
79 | + $cookiePrefix, |
|
80 | + $policy, |
|
81 | + $cookieParams['path'], |
|
82 | + $policy |
|
83 | + ), |
|
84 | + false |
|
85 | + ); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | } |