@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | use Symfony\Component\Console\Question\ChoiceQuestion; |
| 21 | 21 | |
| 22 | 22 | class Configure extends Command { |
| 23 | - private array $ids = []; |
|
| 23 | + private array $ids = [ ]; |
|
| 24 | 24 | |
| 25 | 25 | public function __construct( |
| 26 | 26 | private Factory $gatewayFactory, |
@@ -29,17 +29,17 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | $fqcn = $this->gatewayFactory->getFqcnList(); |
| 31 | 31 | foreach ($fqcn as $fqcn) { |
| 32 | - $this->ids[] = $fqcn::getProviderId(); |
|
| 32 | + $this->ids[ ] = $fqcn::getProviderId(); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $this->addArgument( |
| 36 | 36 | 'gateway', |
| 37 | 37 | InputArgument::OPTIONAL, |
| 38 | - 'The name of the gateway: ' . implode(', ', $this->ids) |
|
| 38 | + 'The name of the gateway: '.implode(', ', $this->ids) |
|
| 39 | 39 | ); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - #[\Override] |
|
| 42 | + #[\Override ] |
|
| 43 | 43 | protected function execute(InputInterface $input, OutputInterface $output) { |
| 44 | 44 | $gatewayName = strtolower((string)$input->getArgument('gateway')); |
| 45 | 45 | if (!in_array($gatewayName, $this->ids, true)) { |
@@ -43,17 +43,17 @@ discard block |
||
| 43 | 43 | * 400: User not found |
| 44 | 44 | * 503: Gateway wasn't configured yed |
| 45 | 45 | */ |
| 46 | - #[NoAdminRequired] |
|
| 47 | - #[ApiRoute(verb: 'GET', url: '/settings/{gateway}/verification')] |
|
| 46 | + #[NoAdminRequired ] |
|
| 47 | + #[ApiRoute(verb: 'GET', url: '/settings/{gateway}/verification') ] |
|
| 48 | 48 | public function getVerificationState(string $gateway): JSONResponse { |
| 49 | 49 | $user = $this->userSession->getUser(); |
| 50 | 50 | |
| 51 | 51 | if (is_null($user)) { |
| 52 | - return new JSONResponse(['message' => 'User not found'], Http::STATUS_BAD_REQUEST); |
|
| 52 | + return new JSONResponse([ 'message' => 'User not found' ], Http::STATUS_BAD_REQUEST); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | if (!$this->gatewayFactory->get($gateway)->isComplete()) { |
| 56 | - return new JSONResponse([], Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 56 | + return new JSONResponse([ ], Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | return new JSONResponse($this->setup->getState($user, $gateway)->jsonSerialize()); |
@@ -70,19 +70,19 @@ discard block |
||
| 70 | 70 | * 200: OK |
| 71 | 71 | * 400: User not found |
| 72 | 72 | */ |
| 73 | - #[NoAdminRequired] |
|
| 74 | - #[ApiRoute(verb: 'POST', url: '/settings/{gateway}/verification/start')] |
|
| 73 | + #[NoAdminRequired ] |
|
| 74 | + #[ApiRoute(verb: 'POST', url: '/settings/{gateway}/verification/start') ] |
|
| 75 | 75 | public function startVerification(string $gateway, string $identifier): JSONResponse { |
| 76 | 76 | $user = $this->userSession->getUser(); |
| 77 | 77 | |
| 78 | 78 | if (is_null($user)) { |
| 79 | - return new JSONResponse(['message' => 'User not found'], Http::STATUS_BAD_REQUEST); |
|
| 79 | + return new JSONResponse([ 'message' => 'User not found' ], Http::STATUS_BAD_REQUEST); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | try { |
| 83 | 83 | $state = $this->setup->startSetup($user, $gateway, $identifier); |
| 84 | 84 | } catch (VerificationException $e) { |
| 85 | - return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); |
|
| 85 | + return new JSONResponse([ 'message' => $e->getMessage() ], Http::STATUS_BAD_REQUEST); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | return new JSONResponse([ |
@@ -101,22 +101,22 @@ discard block |
||
| 101 | 101 | * 200: OK |
| 102 | 102 | * 400: User not found |
| 103 | 103 | */ |
| 104 | - #[NoAdminRequired] |
|
| 105 | - #[ApiRoute(verb: 'POST', url: '/settings/{gateway}/verification/finish')] |
|
| 104 | + #[NoAdminRequired ] |
|
| 105 | + #[ApiRoute(verb: 'POST', url: '/settings/{gateway}/verification/finish') ] |
|
| 106 | 106 | public function finishVerification(string $gateway, string $verificationCode): JSONResponse { |
| 107 | 107 | $user = $this->userSession->getUser(); |
| 108 | 108 | |
| 109 | 109 | if (is_null($user)) { |
| 110 | - return new JSONResponse(['message' => 'User not found'], Http::STATUS_BAD_REQUEST); |
|
| 110 | + return new JSONResponse([ 'message' => 'User not found' ], Http::STATUS_BAD_REQUEST); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | try { |
| 114 | 114 | $this->setup->finishSetup($user, $gateway, $verificationCode); |
| 115 | 115 | } catch (VerificationException) { |
| 116 | - return new JSONResponse([], Http::STATUS_BAD_REQUEST); |
|
| 116 | + return new JSONResponse([ ], Http::STATUS_BAD_REQUEST); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - return new JSONResponse([]); |
|
| 119 | + return new JSONResponse([ ]); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -128,13 +128,13 @@ discard block |
||
| 128 | 128 | * 200: OK |
| 129 | 129 | * 400: User not found |
| 130 | 130 | */ |
| 131 | - #[NoAdminRequired] |
|
| 132 | - #[ApiRoute(verb: 'DELETE', url: '/settings/{gateway}/verification')] |
|
| 131 | + #[NoAdminRequired ] |
|
| 132 | + #[ApiRoute(verb: 'DELETE', url: '/settings/{gateway}/verification') ] |
|
| 133 | 133 | public function revokeVerification(string $gateway): JSONResponse { |
| 134 | 134 | $user = $this->userSession->getUser(); |
| 135 | 135 | |
| 136 | 136 | if (is_null($user)) { |
| 137 | - return new JSONResponse(['message' => 'User not found'], Http::STATUS_BAD_REQUEST); |
|
| 137 | + return new JSONResponse([ 'message' => 'User not found' ], Http::STATUS_BAD_REQUEST); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | return new JSONResponse($this->setup->disable($user, $gateway)); |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | ) { |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - #[\Override] |
|
| 25 | + #[\Override ] |
|
| 26 | 26 | public function getBody(): ITemplate { |
| 27 | 27 | $template = Server::get(ITemplateManager::class)->getTemplate('twofactor_gateway', 'personal_settings'); |
| 28 | 28 | $template->assign('gateway', $this->gateway); |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | private function buildConfigKey(string $gatewayName, string $key): string { |
| 30 | - return $gatewayName . "_$key"; |
|
| 30 | + return $gatewayName."_$key"; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | private function getUserValue(IUser $user, string $gatewayName, string $key, string $default = ''): string { |
@@ -62,8 +62,8 @@ |
||
| 62 | 62 | $gateway->send( |
| 63 | 63 | $user, |
| 64 | 64 | $identifier, |
| 65 | - $this->l10n->t('%s is your verification code.', [$verificationNumber]), |
|
| 66 | - ['code' => $verificationNumber], |
|
| 65 | + $this->l10n->t('%s is your verification code.', [ $verificationNumber ]), |
|
| 66 | + [ 'code' => $verificationNumber ], |
|
| 67 | 67 | ); |
| 68 | 68 | } catch (MessageTransmissionException $ex) { |
| 69 | 69 | throw new VerificationException($ex->getMessage(), $ex->getCode(), $ex); |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | * twofactorgateway?: TwoFactorGatewayCapabilities, |
| 30 | 30 | * } |
| 31 | 31 | */ |
| 32 | - #[Override] |
|
| 32 | + #[Override ] |
|
| 33 | 33 | public function getCapabilities(): array { |
| 34 | 34 | $capabilities = [ |
| 35 | 35 | 'features' => self::FEATURES, |
@@ -33,17 +33,17 @@ discard block |
||
| 33 | 33 | parent::__construct($appConfig); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - #[\Override] |
|
| 37 | - public function send(IUser $user, string $identifier, string $message, array $extra = []): void { |
|
| 36 | + #[\Override ] |
|
| 37 | + public function send(IUser $user, string $identifier, string $message, array $extra = [ ]): void { |
|
| 38 | 38 | $this->getProvider()->send($identifier, $message); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - #[\Override] |
|
| 41 | + #[\Override ] |
|
| 42 | 42 | final public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
| 43 | 43 | $namespaces = $this->providerFactory->getFqcnList(); |
| 44 | - $schemas = []; |
|
| 44 | + $schemas = [ ]; |
|
| 45 | 45 | foreach ($namespaces as $ns) { |
| 46 | - $schemas[] = $ns::SCHEMA; |
|
| 46 | + $schemas[ ] = $ns::SCHEMA; |
|
| 47 | 47 | } |
| 48 | 48 | $names = array_column($schemas, 'name'); |
| 49 | 49 | |
@@ -51,32 +51,32 @@ discard block |
||
| 51 | 51 | $choiceQuestion = new ChoiceQuestion('Please choose a SMS provider:', $names); |
| 52 | 52 | $name = $helper->ask($input, $output, $choiceQuestion); |
| 53 | 53 | $selectedIndex = array_search($name, $names); |
| 54 | - $schema = $schemas[$selectedIndex]; |
|
| 54 | + $schema = $schemas[ $selectedIndex ]; |
|
| 55 | 55 | |
| 56 | - $provider = $this->getProvider($namespaces[$selectedIndex]::getProviderId()); |
|
| 56 | + $provider = $this->getProvider($namespaces[ $selectedIndex ]::getProviderId()); |
|
| 57 | 57 | |
| 58 | - foreach ($schema['fields'] as $field) { |
|
| 59 | - $id = $field['field']; |
|
| 60 | - $prompt = $field['prompt'] . ' '; |
|
| 61 | - $defaultVal = $field['default'] ?? null; |
|
| 62 | - $optional = (bool)($field['optional'] ?? false); |
|
| 58 | + foreach ($schema[ 'fields' ] as $field) { |
|
| 59 | + $id = $field[ 'field' ]; |
|
| 60 | + $prompt = $field[ 'prompt' ].' '; |
|
| 61 | + $defaultVal = $field[ 'default' ] ?? null; |
|
| 62 | + $optional = (bool)($field[ 'optional' ] ?? false); |
|
| 63 | 63 | |
| 64 | 64 | $answer = (string)$helper->ask($input, $output, new Question($prompt, $defaultVal)); |
| 65 | 65 | |
| 66 | 66 | if ($optional && $answer === '') { |
| 67 | - $method = 'delete' . $this->toCamel($id); |
|
| 67 | + $method = 'delete'.$this->toCamel($id); |
|
| 68 | 68 | $provider->{$method}(); |
| 69 | 69 | continue; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $method = 'set' . $this->toCamel($id); |
|
| 72 | + $method = 'set'.$this->toCamel($id); |
|
| 73 | 73 | $provider->{$method}($answer); |
| 74 | 74 | } |
| 75 | 75 | return 0; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - #[\Override] |
|
| 79 | - public function isComplete(array $schema = []): bool { |
|
| 78 | + #[\Override ] |
|
| 79 | + public function isComplete(array $schema = [ ]): bool { |
|
| 80 | 80 | if (empty($schema)) { |
| 81 | 81 | try { |
| 82 | 82 | $provider = $this->getProvider(); |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | return parent::isComplete($schema); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - #[\Override] |
|
| 92 | - public function remove(array $schema = []): void { |
|
| 91 | + #[\Override ] |
|
| 92 | + public function remove(array $schema = [ ]): void { |
|
| 93 | 93 | if (empty($schema)) { |
| 94 | 94 | $schema = static::SCHEMA; |
| 95 | 95 | } |
@@ -25,10 +25,10 @@ discard block |
||
| 25 | 25 | ) { |
| 26 | 26 | parent::__construct('twofactorauth:gateway:test'); |
| 27 | 27 | |
| 28 | - $ids = []; |
|
| 28 | + $ids = [ ]; |
|
| 29 | 29 | $fqcn = $this->gatewayFactory->getFqcnList(); |
| 30 | 30 | foreach ($fqcn as $fqcn) { |
| 31 | - $ids[] = $fqcn::getProviderId(); |
|
| 31 | + $ids[ ] = $fqcn::getProviderId(); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | $this->addArgument( |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | $this->addArgument( |
| 40 | 40 | 'gateway', |
| 41 | 41 | InputArgument::REQUIRED, |
| 42 | - 'The name of the gateway: ' . implode(', ', $ids) |
|
| 42 | + 'The name of the gateway: '.implode(', ', $ids) |
|
| 43 | 43 | ); |
| 44 | 44 | $this->addArgument( |
| 45 | 45 | 'identifier', |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | ); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - #[\Override] |
|
| 51 | + #[\Override ] |
|
| 52 | 52 | protected function execute(InputInterface $input, OutputInterface $output) { |
| 53 | 53 | $uid = $input->getArgument('uid'); |
| 54 | 54 | $user = $this->userManager->get($uid); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | return 1; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $gateway->send($user, $identifier, 'Test', ['code' => '123456']); |
|
| 69 | + $gateway->send($user, $identifier, 'Test', [ 'code' => '123456' ]); |
|
| 70 | 70 | return 0; |
| 71 | 71 | } |
| 72 | 72 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | 'name' => 'Signal', |
| 32 | 32 | 'instructions' => 'The gateway can send authentication to your Signal mobile and deskop app.', |
| 33 | 33 | 'fields' => [ |
| 34 | - ['field' => 'url', 'prompt' => 'Please enter the URL of the Signal gateway (leave blank to use default):', 'default' => 'http://localhost:5000'], |
|
| 34 | + [ 'field' => 'url', 'prompt' => 'Please enter the URL of the Signal gateway (leave blank to use default):', 'default' => 'http://localhost:5000' ], |
|
| 35 | 35 | ], |
| 36 | 36 | ]; |
| 37 | 37 | |
@@ -43,29 +43,29 @@ discard block |
||
| 43 | 43 | parent::__construct($appConfig); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - #[\Override] |
|
| 47 | - public function send(IUser $user, string $identifier, string $message, array $extra = []): void { |
|
| 46 | + #[\Override ] |
|
| 47 | + public function send(IUser $user, string $identifier, string $message, array $extra = [ ]): void { |
|
| 48 | 48 | $client = $this->clientService->newClient(); |
| 49 | 49 | // determine type of gateway |
| 50 | - $response = $client->get($this->getUrl() . '/v1/about'); |
|
| 50 | + $response = $client->get($this->getUrl().'/v1/about'); |
|
| 51 | 51 | if ($response->getStatusCode() === 200) { |
| 52 | 52 | // New style gateway https://gitlab.com/morph027/signal-cli-dbus-rest-api |
| 53 | 53 | $response = $client->post( |
| 54 | - $this->getUrl() . '/v1/send/' . $identifier, |
|
| 54 | + $this->getUrl().'/v1/send/'.$identifier, |
|
| 55 | 55 | [ |
| 56 | 56 | 'json' => [ 'message' => $message ], |
| 57 | 57 | ] |
| 58 | 58 | ); |
| 59 | 59 | $body = (string)$response->getBody(); |
| 60 | 60 | $json = json_decode($body, true); |
| 61 | - if ($response->getStatusCode() !== 201 || is_null($json) || !is_array($json) || !isset($json['timestamp'])) { |
|
| 61 | + if ($response->getStatusCode() !== 201 || is_null($json) || !is_array($json) || !isset($json[ 'timestamp' ])) { |
|
| 62 | 62 | $status = $response->getStatusCode(); |
| 63 | 63 | throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}"); |
| 64 | 64 | } |
| 65 | 65 | } else { |
| 66 | 66 | // Try old deprecated gateway https://gitlab.com/morph027/signal-web-gateway |
| 67 | 67 | $response = $client->post( |
| 68 | - $this->getUrl() . '/v1/send/' . $identifier, |
|
| 68 | + $this->getUrl().'/v1/send/'.$identifier, |
|
| 69 | 69 | [ |
| 70 | 70 | 'body' => [ |
| 71 | 71 | 'to' => $identifier, |
@@ -77,17 +77,17 @@ discard block |
||
| 77 | 77 | $body = (string)$response->getBody(); |
| 78 | 78 | $json = json_decode($body, true); |
| 79 | 79 | |
| 80 | - if ($response->getStatusCode() !== 200 || is_null($json) || !is_array($json) || !isset($json['success']) || $json['success'] !== true) { |
|
| 80 | + if ($response->getStatusCode() !== 200 || is_null($json) || !is_array($json) || !isset($json[ 'success' ]) || $json[ 'success' ] !== true) { |
|
| 81 | 81 | $status = $response->getStatusCode(); |
| 82 | 82 | throw new MessageTransmissionException("error reported by Signal gateway, status=$status, body=$body}"); |
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - #[\Override] |
|
| 87 | + #[\Override ] |
|
| 88 | 88 | public function cliConfigure(InputInterface $input, OutputInterface $output): int { |
| 89 | 89 | $helper = new QuestionHelper(); |
| 90 | - $urlQuestion = new Question(self::SCHEMA['fields'][0]['prompt'], self::SCHEMA['fields'][0]['default']); |
|
| 90 | + $urlQuestion = new Question(self::SCHEMA[ 'fields' ][ 0 ][ 'prompt' ], self::SCHEMA[ 'fields' ][ 0 ][ 'default' ]); |
|
| 91 | 91 | $url = $helper->ask($input, $output, $urlQuestion); |
| 92 | 92 | $output->writeln("Using $url."); |
| 93 | 93 | |