Skip to content

Commit b3c1dee

Browse files
committed
OXDEV-9078 Add success message on save 2FA settings
1 parent 801bba0 commit b3c1dee

6 files changed

Lines changed: 42 additions & 3 deletions

File tree

src/Authentication/TwoFactorAuth/Controller/AccountSecurityController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
class AccountSecurityController extends AccountController
1717
{
18+
private bool $twoFASaved = false;
19+
1820
public function __construct(
1921
private readonly TwoFAUserSettingsInterface $userSettingsService,
2022
) {
@@ -29,6 +31,7 @@ public function render(): string
2931
$user = $this->getUser();
3032
if ($user) {
3133
$this->addTplParam('twoFAEnabledForUser', $this->userSettingsService->isEnabledForUser($user->getId()));
34+
$this->addTplParam('twoFASaved', $this->twoFASaved);
3235
}
3336

3437
return $parentResult;
@@ -43,5 +46,6 @@ public function saveTwoFactorAuth(): void
4346

4447
$enabled = (bool)Registry::getRequest()->getRequestParameter('twofa_enabled');
4548
$this->userSettingsService->setEnabledForUser($user->getId(), $enabled);
49+
$this->twoFASaved = true;
4650
}
4751
}

src/Authentication/TwoFactorAuth/Controller/TwoFactorAuthController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ public function render(): string
4343
{
4444
parent::render();
4545

46-
$isResendable = $this->twoFAService instanceof TwoFAResendableInterface;
47-
$this->addTplParam('resendable', $isResendable);
46+
$this->addTplParam('resendable', $this->twoFAService instanceof TwoFAResendableInterface);
4847

49-
if ($isResendable) {
48+
if ($this->twoFAService instanceof TwoFAResendableInterface) {
5049
$userId = $this->twoFAUserService->getPendingUserId();
5150
$this->addTplParam('remainingAttempts', $this->twoFAService->getRemainingAttempts($userId));
5251
$this->addTplParam('resendCooldownRemaining', $this->twoFAService->getCooldownRemaining($userId));

tests/Integration/Authentication/TwoFactorAuth/Controller/AccountSecurityControllerTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,37 @@ public static function renderSetsTwoFAEnabledDataProvider(): Generator
5151
yield 'user has 2FA disabled' => ['userSettingEnabled' => false];
5252
}
5353

54+
#[Test]
55+
public function renderSetsTwoFASavedFalseByDefault(): void
56+
{
57+
$userId = uniqid();
58+
59+
$userStub = $this->createStub(User::class);
60+
$userStub->method('getId')->willReturn($userId);
61+
62+
$sut = $this->getSut();
63+
$sut->method('getUser')->willReturn($userStub);
64+
$sut->render();
65+
66+
$this->assertFalse($sut->getViewDataElement('twoFASaved'));
67+
}
68+
69+
#[Test]
70+
public function renderSetsTwoFASavedTrueAfterSave(): void
71+
{
72+
$userId = uniqid();
73+
74+
$userStub = $this->createStub(User::class);
75+
$userStub->method('getId')->willReturn($userId);
76+
77+
$sut = $this->getSut();
78+
$sut->method('getUser')->willReturn($userStub);
79+
$sut->saveTwoFactorAuth();
80+
$sut->render();
81+
82+
$this->assertTrue($sut->getViewDataElement('twoFASaved'));
83+
}
84+
5485
private function getSut(
5586
TwoFAUserSettingsInterface $userSettingsService = null,
5687
): AccountSecurityController {

translations/de/oesecuritymodule_lang.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@
6767
'OE_SECURITY_TWO_FACTOR_SETTINGS_TITLE' => 'Zwei-Faktor-Authentifizierung',
6868
'OE_SECURITY_TWO_FACTOR_SETTINGS_DESCRIPTION' => 'Fügen Sie Ihrem Konto eine zusätzliche Sicherheitsebene hinzu. Wenn aktiviert, müssen Sie bei jeder Anmeldung einen Bestätigungscode eingeben, der an Ihre E-Mail gesendet wird.',
6969
'OE_SECURITY_TWO_FACTOR_ENABLE' => 'Zwei-Faktor-Authentifizierung aktivieren',
70+
'OE_SECURITY_TWO_FA_SETTINGS_SAVED' => 'Die Einstellungen für die Zwei-Faktor-Authentifizierung wurden gespeichert.',
7071
];

translations/en/oesecuritymodule_lang.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@
6767
'OE_SECURITY_TWO_FACTOR_SETTINGS_TITLE' => 'Two-Factor Authentication',
6868
'OE_SECURITY_TWO_FACTOR_SETTINGS_DESCRIPTION' => 'Add an extra layer of security to your account. When enabled, you will need to enter a verification code sent to your email each time you log in.',
6969
'OE_SECURITY_TWO_FACTOR_ENABLE' => 'Enable two-factor authentication',
70+
'OE_SECURITY_TWO_FA_SETTINGS_SAVED' => 'Two-factor authentication settings have been saved.',
7071
];

views/twig/templates/account_security.html.twig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{% capture append = "oxidBlock_content" %}
2+
{% if twoFASaved %}
3+
<div class="alert alert-success">{{ translate({ ident: "OE_SECURITY_TWO_FA_SETTINGS_SAVED" }) }}</div>
4+
{% endif %}
25
<div class="container-xxl py-5">
36
<div class="row">
47
<h1 class="h3 page-header col pl-0 ml-3">

0 commit comments

Comments
 (0)