Skip to content

Commit e8bd09d

Browse files
author
roadiz-ci
committed
Merge branch hotfix/2.7.12
1 parent a919e13 commit e8bd09d

8 files changed

Lines changed: 46 additions & 43 deletions

composer.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,26 @@
2323
"php": ">=8.3",
2424
"doctrine/orm": "~2.20.0",
2525
"endroid/qr-code": "^4.0",
26-
"roadiz/core-bundle": "2.6.*",
27-
"roadiz/rozier-bundle": "2.6.*",
26+
"roadiz/core-bundle": "2.7.*",
27+
"roadiz/rozier-bundle": "2.7.*",
2828
"scheb/2fa-backup-code": "^7.5",
2929
"scheb/2fa-bundle": "^7.5",
3030
"scheb/2fa-google-authenticator": "^7.5",
3131
"scheb/2fa-totp": "^7.5",
3232
"scheb/2fa-trusted-device": "^7.5",
33-
"symfony/framework-bundle": "7.3.*"
33+
"symfony/framework-bundle": "7.4.*"
3434
},
3535
"require-dev": {
3636
"php-coveralls/php-coveralls": "^2.4",
37-
"phpstan/phpstan": "^1.5.3",
37+
"phpstan/phpstan": "^2.1.36",
3838
"phpstan/phpdoc-parser": "<2",
39-
"phpstan/phpstan-doctrine": "^1.3",
39+
"phpstan/phpstan-doctrine": "^2.0.13",
4040
"phpunit/phpunit": "^9.6",
41-
"roadiz/doc-generator": "2.6.*",
42-
"roadiz/entity-generator": "2.6.*",
43-
"roadiz/jwt": "2.6.*",
44-
"roadiz/random": "2.6.*",
45-
"symfony/stopwatch": "7.3.*"
41+
"roadiz/doc-generator": "2.7.*",
42+
"roadiz/entity-generator": "2.7.*",
43+
"roadiz/jwt": "2.7.*",
44+
"roadiz/random": "2.7.*",
45+
"symfony/stopwatch": "7.4.*"
4646
},
4747
"config": {
4848
"optimize-autoloader": true,
@@ -69,8 +69,8 @@
6969
},
7070
"extra": {
7171
"branch-alias": {
72-
"dev-main": "2.6.x-dev",
73-
"dev-develop": "2.7.x-dev"
72+
"dev-main": "2.7.x-dev",
73+
"dev-develop": "2.8.x-dev"
7474
}
7575
}
7676
}

src/Controller/BackupCodesAdminController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ final class BackupCodesAdminController extends AbstractController
1717
{
1818
public function __construct(
1919
private readonly TwoFactorUserProviderInterface $twoFactorUserProvider,
20+
private readonly TokenStorageInterface $tokenStorage,
2021
) {
2122
}
2223

23-
public function backupCodesAdminAction(Request $request, TokenStorageInterface $tokenStorage): Response
24+
public function backupCodesAdminAction(Request $request): Response
2425
{
2526
$this->denyAccessUnlessGranted('ROLE_BACKEND_USER');
2627

2728
if ($this->isGranted('IS_IMPERSONATOR')) {
2829
throw $this->createAccessDeniedException('You cannot impersonate to access this page.');
2930
}
3031

31-
$user = $tokenStorage->getToken()->getUser();
32+
$user = $this->tokenStorage->getToken()?->getUser();
3233
if (!$user instanceof User) {
3334
throw $this->createAccessDeniedException('You must be logged in to access this page.');
3435
}

src/Controller/QrCodeController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ public function __construct(
2525
private readonly TwoFactorUserProviderInterface $twoFactorUserProvider,
2626
private readonly TotpAuthenticatorInterface $totpAuthenticator,
2727
private readonly GoogleAuthenticatorInterface $googleAuthenticator,
28+
private readonly TokenStorageInterface $tokenStorage,
2829
) {
2930
}
3031

31-
public function totpQrCodeAction(TokenStorageInterface $tokenStorage): Response
32+
public function totpQrCodeAction(): Response
3233
{
3334
$this->denyAccessUnlessGranted('ROLE_BACKEND_USER');
3435

3536
if ($this->isGranted('IS_IMPERSONATOR')) {
3637
throw $this->createAccessDeniedException('You cannot impersonate to access this page.');
3738
}
3839

39-
$user = $tokenStorage->getToken()->getUser();
40+
$user = $this->tokenStorage->getToken()?->getUser();
4041
if (!$user instanceof User) {
4142
throw $this->createAccessDeniedException('You must be logged in to access this page.');
4243
}

src/Controller/TwoFactorAdminController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use RZ\Roadiz\TwoFactorBundle\Form\TwoFactorCodeActivationType;
1010
use RZ\Roadiz\TwoFactorBundle\Security\Provider\AuthenticatorTwoFactorProvider;
1111
use RZ\Roadiz\TwoFactorBundle\Security\Provider\TwoFactorUserProviderInterface;
12-
use Scheb\TwoFactorBundle\Model\Totp\TwoFactorInterface;
1312
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1413
use Symfony\Component\Form\Extension\Core\Type\FormType;
1514
use Symfony\Component\Form\FormError;
@@ -22,18 +21,19 @@ final class TwoFactorAdminController extends AbstractController
2221
public function __construct(
2322
private readonly TwoFactorUserProviderInterface $twoFactorUserProvider,
2423
private readonly AuthenticatorTwoFactorProvider $authenticatorTwoFactorProvider,
24+
private readonly TokenStorageInterface $tokenStorage,
2525
) {
2626
}
2727

28-
public function twoFactorAdminAction(Request $request, TokenStorageInterface $tokenStorage): Response
28+
public function twoFactorAdminAction(Request $request): Response
2929
{
3030
$this->denyAccessUnlessGranted('ROLE_BACKEND_USER');
3131

3232
if ($this->isGranted('IS_IMPERSONATOR')) {
3333
throw $this->createAccessDeniedException('You cannot impersonate to access this page.');
3434
}
3535

36-
$user = $tokenStorage->getToken()->getUser();
36+
$user = $this->tokenStorage->getToken()?->getUser();
3737
if (!$user instanceof User) {
3838
throw $this->createAccessDeniedException('You must be logged in to access this page.');
3939
}
@@ -51,7 +51,7 @@ public function twoFactorAdminAction(Request $request, TokenStorageInterface $to
5151
$assignation['form'] = $form->createView();
5252
} elseif (!$twoFactorUser->isTotpAuthenticationEnabled()) {
5353
// Only display QR code if user has started 2FA activation
54-
$assignation['displayQrCodeTotp'] = $twoFactorUser instanceof TwoFactorInterface;
54+
$assignation['displayQrCodeTotp'] = true;
5555
$form = $this->createForm(TwoFactorCodeActivationType::class);
5656
$form->handleRequest($request);
5757
if ($form->isSubmitted() && $form->isValid()) {
@@ -77,11 +77,11 @@ public function twoFactorAdminAction(Request $request, TokenStorageInterface $to
7777
return $this->render('@RoadizTwoFactor/admin/two_factor.html.twig', $assignation);
7878
}
7979

80-
public function twoFactorDisableAction(Request $request, TokenStorageInterface $tokenStorage): Response
80+
public function twoFactorDisableAction(Request $request): Response
8181
{
8282
$this->denyAccessUnlessGranted('ROLE_BACKEND_USER');
8383

84-
$user = $tokenStorage->getToken()->getUser();
84+
$user = $this->tokenStorage->getToken()?->getUser();
8585
if (!$user instanceof User) {
8686
throw $this->createAccessDeniedException('You must be logged in to access this page.');
8787
}

src/Entity/TwoFactorUser.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ public function getTotpAuthenticationUsername(): string
138138
#[\Override]
139139
public function getTotpAuthenticationConfiguration(): ?TotpConfigurationInterface
140140
{
141+
if (null === $this->secret) {
142+
throw new \RuntimeException('Secret cannot be null');
143+
}
144+
141145
// You could persist the other configuration options in the user entity to make it individual per user.
142146
return new TotpConfiguration($this->secret, $this->getAlgorithm(), $this->getPeriod(), $this->getDigits());
143147
}
@@ -176,7 +180,7 @@ public function getGoogleAuthenticatorSecret(): ?string
176180
public function isBackupCode(string $code): bool
177181
{
178182
// Loop over all backup codes and check if the code is valid
179-
foreach ($this->backupCodes as $backupCode) {
183+
foreach ($this->backupCodes ?? [] as $backupCode) {
180184
if (password_verify($code, (string) $backupCode)) {
181185
return true;
182186
}
@@ -192,10 +196,10 @@ public function isBackupCode(string $code): bool
192196
public function invalidateBackupCode(string $code): void
193197
{
194198
// Loop over all backup codes and check if the code is valid to invalidate it
195-
foreach ($this->backupCodes as $key => $backupCode) {
199+
foreach ($this->backupCodes ?? [] as $key => $backupCode) {
196200
if (password_verify($code, (string) $backupCode)) {
197201
unset($this->backupCodes[$key]);
198-
$this->backupCodes = array_values($this->backupCodes);
202+
$this->backupCodes = array_values($this->backupCodes ?? []);
199203
}
200204
}
201205
}

templates/admin/backup_codes.html.twig

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
{% if backupCodes %}
1515
<h2>{% trans %}store_your_backup_codes{% endtrans %}</h2>
1616
<div>
17-
{% apply spaceless %}
1817
<pre>
19-
{% for code in backupCodes %}
18+
{%- for code in backupCodes -%}
2019
<code>{{ code }}</code><br>
21-
{% endfor %}
20+
{%- endfor -%}
2221
</pre>
23-
{% endapply %}
2422

2523
<p><a href="{{ path('2fa_admin_two_factor') }}"
2624
class="uk-button"><i class="uk-icon-rz-back-parent"></i> {% trans %}back_to.two_factor{% endtrans %}</a></p>
@@ -32,7 +30,7 @@
3230
{{ form_widget(form) }}
3331
<fieldset data-uk-margin>
3432
<legend class="uk-alert uk-alert-warning"><i class="uk-icon uk-icon-warning"></i> {% trans %}are_you_sure.generate.two_factor_backup_codes.erasing_any_existing{% endtrans %}</legend>
35-
{% apply spaceless %}
33+
<div class="uk-button-group">
3634
<a href="{{ path('2fa_admin_two_factor') }}"
3735
class="uk-button"><i class="uk-icon-rz-back-parent"></i> {% trans %}cancel{% endtrans %}</a>
3836
<button class="uk-button uk-button-warning" type="submit">
@@ -41,7 +39,7 @@
4139
{%- trans -%}generate_backup_codes{%- endtrans -%}
4240
</span></span>
4341
</button>
44-
{% endapply %}
42+
</div>
4543
</fieldset>
4644
{{ form_end(form) }}
4745
{% endif %}

templates/admin/disable_two_factor.html.twig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
{{ form_widget(form) }}
2020
<fieldset data-uk-margin>
2121
<legend class="uk-alert uk-alert-danger"><i class="uk-icon uk-icon-warning"></i> {% trans %}are_you_sure.disable.two_factor{% endtrans %}</legend>
22-
{% apply spaceless %}
22+
23+
<div class="uk-button-group">
2324
<a href="{{ path('2fa_admin_two_factor') }}"
2425
class="uk-button"><i class="uk-icon-rz-back-parent"></i> {% trans %}cancel{% endtrans %}</a>
2526
<button class="uk-button uk-button-danger" type="submit">
@@ -28,7 +29,7 @@
2829
{%- trans -%}disable_two_factor{%- endtrans -%}
2930
</span></span>
3031
</button>
31-
{% endapply %}
32+
</div>
3233
</fieldset>
3334
{{ form_end(form) }}
3435
{% endif %}

templates/admin/two_factor.html.twig

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{{ form_widget(form) }}
1414
<fieldset data-uk-margin>
1515
<legend class="uk-alert uk-alert-info"><i class="uk-icon uk-icon-warning"></i> {% trans %}are_you_sure.activate.two_factor{% endtrans %}</legend>
16-
{% apply spaceless %}
16+
<div class="uk-button-group">
1717
<a href="{{ path('usersHomePage') }}"
1818
class="uk-button"><i class="uk-icon-rz-back-parent"></i> {% trans %}cancel{% endtrans %}</a>
1919
<button class="uk-button uk-button-primary" type="submit">
@@ -22,7 +22,7 @@
2222
{%- trans -%}begin_activation{%- endtrans -%}
2323
</span></span>
2424
</button>
25-
{% endapply %}
25+
</div>
2626
</fieldset>
2727
{{ form_end(form) }}
2828
{% elseif displayQrCodeTotp %}
@@ -37,14 +37,12 @@
3737
{{ form_start(totpForm) }}
3838
{{ form_widget(totpForm) }}
3939
<fieldset data-uk-margin>
40-
{% apply spaceless %}
41-
<button class="uk-button uk-button-primary" type="submit">
42-
<span class="icon-container"><i class="uk-icon-lock"></i></span>
43-
<span class="label"><span class="label-text">
44-
{%- trans -%}submit_totp_code{%- endtrans -%}
45-
</span></span>
46-
</button>
47-
{% endapply %}
40+
<button class="uk-button uk-button-primary" type="submit">
41+
<span class="icon-container"><i class="uk-icon-lock"></i></span>
42+
<span class="label">
43+
<span class="label-text">{%- trans -%}submit_totp_code{%- endtrans -%}</span>
44+
</span>
45+
</button>
4846
</fieldset>
4947
{{ form_end(totpForm) }}
5048
</div>

0 commit comments

Comments
 (0)