Skip to content

Commit 7d8f987

Browse files
committed
5124: Cleaned up
1 parent 4f23686 commit 7d8f987

File tree

8 files changed

+38
-52
lines changed

8 files changed

+38
-52
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Versioning](https://semver.org/spec/v2.0.0.html).
88

99
## [Unreleased]
1010

11+
- [PR-375](https://github.com/itk-dev/os2loop/pull/375)
12+
Added Cura login module
13+
1114
## [1.2.5]
1215

1316
- [374](https://github.com/itk-dev/os2loop/pull/374)

web/profiles/custom/os2loop/modules/os2loop_cura_login/os2loop_cura_login.info.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
name: 'OS2Loop Cura login'
1+
name: "OS2Loop Cura login"
22
type: module
3-
description: 'OS2Loop Cura login'
4-
package: 'OS2Loop'
3+
description: "OS2Loop Cura login"
4+
package: "OS2Loop"
55
core_version_requirement: ^10 || ^11
66
dependencies:
77
- drupal:user
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
os2loop_cura_login.settings:
2-
title: 'OS2Loop Cura login settings'
2+
title: "OS2Loop Cura login settings"
33
route_name: os2loop_cura_login.settings
4-
description: 'Configure OS2Loop Cura login settings'
4+
description: "Configure OS2Loop Cura login settings"
55
parent: os2loop.group.admin
66
weight: 100
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
os2loop_cura_login.start:
2-
path: '/os2loop-cura-login/start'
2+
path: "/os2loop-cura-login/start"
33
defaults:
4-
_title: 'Start Cura login'
4+
_title: "Start Cura login"
55
_controller: '\Drupal\os2loop_cura_login\Controller\Os2loopCuraLoginController::start'
66
methods: [GET, POST]
77
requirements:
8-
_role: 'anonymous'
8+
_role: "anonymous"
99

1010
os2loop_cura_login.authenticate:
11-
path: '/os2loop-login-hack/authenticate'
11+
path: "/os2loop-login-hack/authenticate"
1212
defaults:
13-
_title: 'Authenticate with Cura login'
13+
_title: "Authenticate with Cura login"
1414
_controller: '\Drupal\os2loop_cura_login\Controller\Os2loopCuraLoginController::authenticate'
1515
methods: [GET]
1616
requirements:
17-
_role: 'anonymous'
17+
_role: "anonymous"
1818

1919
os2loop_cura_login.settings:
20-
path: '/admin/config/os2loop/os2loop_cura_login/settings'
20+
path: "/admin/config/os2loop/os2loop_cura_login/settings"
2121
defaults:
2222
_form: '\Drupal\os2loop_cura_login\Form\SettingsForm'
23-
_title: 'OS2Loop Cura login settings'
23+
_title: "OS2Loop Cura login settings"
2424
requirements:
25-
_permission: 'administer site settings'
25+
_permission: "administer site settings"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
services:
22
logger.channel.os2loop_cura_login:
33
parent: logger.channel_base
4-
arguments: ['os2loop_cura_login']
4+
arguments: ["os2loop_cura_login"]

web/profiles/custom/os2loop/modules/os2loop_cura_login/src/Controller/Os2loopCuraLoginController.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ public function __construct(
5959
*/
6060
public function start(Request $request): Response {
6161
try {
62-
$content = NULL;
62+
$content = NULL;
6363
try {
6464
$content = (string) $request->getContent();
65-
} catch (\Exception) {}
65+
}
66+
catch (\Exception) {
67+
}
6668
$this->debug('@debug', [
6769
'@debug' => json_encode([
6870
'method' => $request->getMethod(),
@@ -221,9 +223,11 @@ private function getUserinfo(User $user): array {
221223
];
222224
}
223225

224-
public function log($level, \Stringable|string $message, array $context = []): void
225-
{
226-
// Lifted from LoggerChannel
226+
/**
227+
* {@inheritdoc}
228+
*/
229+
public function log($level, \Stringable|string $message, array $context = []): void {
230+
// Lifted from LoggerChannel.
227231
$levels = [
228232
LogLevel::EMERGENCY => RfcLogLevel::EMERGENCY,
229233
LogLevel::ALERT => RfcLogLevel::ALERT,
@@ -235,7 +239,7 @@ public function log($level, \Stringable|string $message, array $context = []): v
235239
LogLevel::DEBUG => RfcLogLevel::DEBUG,
236240
];
237241
$rfcLogLevel = $levels[$level] ?? RfcLogLevel::ERROR;
238-
if ((int)$this->config->get('log_level') >= $rfcLogLevel) {
242+
if ((int) $this->config->get('log_level') >= $rfcLogLevel) {
239243
$this->logger->log($level, $message, $context);
240244
}
241245
}

web/profiles/custom/os2loop/modules/os2loop_cura_login/src/Drush/Commands/Os2loopCuraLoginCommands.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@
22

33
namespace Drupal\os2loop_cura_login\Drush\Commands;
44

5-
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
65
use Drupal\Component\Datetime\TimeInterface;
76
use Drupal\Core\DependencyInjection\AutowireTrait;
87
use Drupal\Core\Url;
9-
use Drupal\Core\Utility\Token;
108
use Drush\Attributes as CLI;
119
use Drush\Commands\DrushCommands;
1210
use Firebase\JWT\JWT;
13-
use Http\Client\HttpClient;
1411
use Psr\Http\Client\ClientInterface;
15-
use Symfony\Component\DependencyInjection\ContainerInterface;
1612
use Symfony\Component\HttpFoundation\Request;
1713

1814
/**
1915
* A Drush commandfile.
2016
*/
21-
final class Os2loopCuraLoginCommands extends DrushCommands
22-
{
17+
final class Os2loopCuraLoginCommands extends DrushCommands {
2318
use AutowireTrait;
2419

2520
/**
@@ -42,10 +37,10 @@ public function __construct(
4237
public function commandName(
4338
$username,
4439
$options = [
45-
'get' => null,
46-
'secret' => null,
40+
'get' => NULL,
41+
'secret' => NULL,
4742
'algorithm' => 'HS256',
48-
]
43+
],
4944
) {
5045
// https://github.com/firebase/php-jwt?tab=readme-ov-file#example
5146
$payload = [
@@ -62,11 +57,12 @@ public function commandName(
6257
if ($name = $options['get']) {
6358
$method = Request::METHOD_GET;
6459
$routeParameters[$name] = $jwt;
65-
} else {
60+
}
61+
else {
6662
$method = Request::METHOD_POST;
6763
$requestOptions['body'] = $jwt;
6864
}
69-
$url = Url::fromRoute('os2loop_cura_login.start', $routeParameters)->setAbsolute()->toString(true)->getGeneratedUrl();
65+
$url = Url::fromRoute('os2loop_cura_login.start', $routeParameters)->setAbsolute()->toString(TRUE)->getGeneratedUrl();
7066
$this->io()->writeln($method === Request::METHOD_POST
7167
? sprintf('POST\'ing to %s', $url)
7268
: sprintf('GET\'ing %s', $url),
@@ -78,7 +74,7 @@ public function commandName(
7874
$url,
7975
$request->getStatusCode(),
8076
$request->getBody()->getContents(),
81-
], true);
77+
], TRUE);
8278
die(__FILE__ . ':' . __LINE__ . ':' . __METHOD__);
8379
}
8480

web/profiles/custom/os2loop/modules/os2loop_cura_login/src/Form/SettingsForm.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
8080
'#default_value' => $config->get('log_level') ?? RfcLogLevel::ERROR,
8181
];
8282

83-
$authenticationStartUrl = Url::fromRoute('os2loop_cura_login.start')->setAbsolute()->toString(true)->getGeneratedUrl();
83+
$authenticationStartUrl = Url::fromRoute('os2loop_cura_login.start')->setAbsolute()->toString(TRUE)->getGeneratedUrl();
8484
$form['info'] = [
8585
'#theme' => 'item_list',
8686
'#items' => [
@@ -89,7 +89,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
8989
];
9090

9191
if ($name = $config->get('token_param_name')) {
92-
$authenticationStartUrl = Url::fromRoute('os2loop_cura_login.start', [$name => ''])->setAbsolute()->toString(true)->getGeneratedUrl();
92+
$authenticationStartUrl = Url::fromRoute('os2loop_cura_login.start', [$name => ''])->setAbsolute()->toString(TRUE)->getGeneratedUrl();
9393
$authenticationStartUrl = str_replace(urlencode(''), '', $authenticationStartUrl);
9494
$form['info']['#items'][] = [
9595
'#markup' => $this->t('Use <a href=":url">:url</a> as <code>linkURL</code> for <core>GET</core>.', [':url' => $authenticationStartUrl]),
@@ -99,23 +99,6 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
9999
return parent::buildForm($form, $form_state);
100100
}
101101

102-
/**
103-
* {@inheritdoc}
104-
*/
105-
public function validateForm(array &$form, FormStateInterface $form_state): void {
106-
// @todo Validate the form here.
107-
// Example:
108-
// @code
109-
// if ($form_state->getValue('example') === 'wrong') {
110-
// $form_state->setErrorByName(
111-
// 'message',
112-
// $this->t('The value is not correct.'),
113-
// );
114-
// }
115-
// @endcode
116-
parent::validateForm($form, $form_state);
117-
}
118-
119102
/**
120103
* {@inheritdoc}
121104
*/

0 commit comments

Comments
 (0)