Skip to content

Commit c5c4792

Browse files
authored
Merge pull request #33 from sandstorm/feature/show-otp-secret-code-when-creating-new-second-factor
FEATURE: Show OTP secret code at 2FA setup after login and in backend module
2 parents abaa3c4 + acf2729 commit c5c4792

File tree

11 files changed

+441
-37
lines changed

11 files changed

+441
-37
lines changed

Classes/Controller/BackendController.php

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

55
use Neos\Error\Messages\Message;
66
use Neos\Flow\Annotations as Flow;
7+
use Neos\Flow\Configuration\ConfigurationManager;
8+
use Neos\Flow\Configuration\Exception\InvalidConfigurationTypeException;
79
use Neos\Flow\I18n\Translator;
810
use Neos\Flow\Mvc\Exception\StopActionException;
911
use Neos\Flow\Mvc\FlashMessage\FlashMessageService;
@@ -118,6 +120,8 @@ public function newAction(): void
118120
$qrCode = $this->tOTPService->generateQRCodeForTokenAndAccount($otp, $this->securityContext->getAccount());
119121

120122
$this->view->assignMultiple([
123+
'styles' => array_filter($this->getNeosSettings()['userInterface']['backendLoginForm']['stylesheets']),
124+
'scripts' => array_filter($this->getNeosSettings()['userInterface']['backendLoginForm']['scripts']),
121125
'secret' => $secret,
122126
'qrCode' => $qrCode,
123127
'flashMessages' => $this->flashMessageService
@@ -221,4 +225,17 @@ public function deleteAction(SecondFactor $secondFactor): void
221225

222226
$this->redirect('index');
223227
}
228+
229+
/**
230+
* @return array
231+
* @throws InvalidConfigurationTypeException
232+
*/
233+
protected function getNeosSettings(): array
234+
{
235+
$configurationManager = $this->objectManager->get(ConfigurationManager::class);
236+
return $configurationManager->getConfiguration(
237+
ConfigurationManager::CONFIGURATION_TYPE_SETTINGS,
238+
'Neos.Neos'
239+
);
240+
}
224241
}

Classes/Controller/LoginController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function askForSecondFactorAction(?string $username = null): void
9595

9696
$this->view->assignMultiple([
9797
'styles' => array_filter($this->getNeosSettings()['userInterface']['backendLoginForm']['stylesheets']),
98+
'scripts' => array_filter($this->getNeosSettings()['userInterface']['backendLoginForm']['scripts']),
9899
'username' => $username,
99100
'site' => $currentSite,
100101
'flashMessages' => $this->flashMessageService
@@ -162,6 +163,7 @@ public function setupSecondFactorAction(?string $username = null): void
162163

163164
$this->view->assignMultiple([
164165
'styles' => array_filter($this->getNeosSettings()['userInterface']['backendLoginForm']['stylesheets']),
166+
'scripts' => array_filter($this->getNeosSettings()['userInterface']['backendLoginForm']['scripts']),
165167
'username' => $username,
166168
'site' => $currentSite,
167169
'secret' => $secret,

Classes/Domain/Model/Dto/SecondFactorDto.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Sandstorm\NeosTwoFactorAuthentication\Domain\Model\Dto;
44

55
use Neos\Neos\Domain\Model\User;
6-
use Neos\Party\Domain\Model\Person;
76
use Sandstorm\NeosTwoFactorAuthentication\Domain\Model\SecondFactor;
87

98
class SecondFactorDto

Configuration/Settings.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Neos:
1111
label: 'Sandstorm.NeosTwoFactorAuthentication:Backend:module.label'
1212
description: 'Sandstorm.NeosTwoFactorAuthentication:Backend:module.description'
1313
icon: 'fas fa-qrcode'
14+
additionalResources:
15+
styleSheets:
16+
- 'resource://Sandstorm.NeosTwoFactorAuthentication/Public/Styles/Login.css'
17+
javaScripts:
18+
- 'resource://Sandstorm.NeosTwoFactorAuthentication/Public/index.js'
1419

1520
userInterface:
1621
translation:
@@ -21,6 +26,8 @@ Neos:
2126
backendLoginForm:
2227
stylesheets:
2328
'Sandstorm.NeosTwoFactorAuthentication:AdditionalStyles': 'resource://Sandstorm.NeosTwoFactorAuthentication/Public/Styles/Login.css'
29+
scripts:
30+
'Sandstorm.NeosTwoFactorAuthentication:AdditionalScripts': 'resource://Sandstorm.NeosTwoFactorAuthentication/Public/index.js'
2431

2532
Flow:
2633
http:

Resources/Private/Fusion/Integration/Controller/Backend/New.fusion

Lines changed: 94 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,100 @@ Sandstorm.NeosTwoFactorAuthentication.BackendController.new = Sandstorm.NeosTwoF
77

88
content = Neos.Fusion:Component {
99
renderer = afx`
10-
<Neos.Fusion.Form:Form form.target.action="create">
11-
<Neos.Fusion.Form:Hidden field.name="secret" field.value={secret}/>
12-
13-
<div class="neos-control-group">
14-
<img src={qrCode} style="width: 100%; max-width: 400px"/>
15-
</div>
16-
17-
<div class="neos-control-group">
18-
<Neos.Fusion.Form:Input
19-
field.name="secondFactorFromApp"
20-
attributes.required="required"
21-
attributes.id="secondFactorFromApp"
22-
attributes.placeholder={I18n.id('otp-placeholder').package('Sandstorm.NeosTwoFactorAuthentication')}
23-
attributes.class="neos-span5"
24-
attributes.aria-label={I18n.id('otp-placeholder').package('Sandstorm.NeosTwoFactorAuthentication')}
25-
attributes.autocomplete="off"
26-
/>
27-
</div>
28-
29-
<div class="neos-control-group">
30-
<Neos.Fusion.Form:Button>
31-
{I18n.id('module.new.submit-otp').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()}
32-
</Neos.Fusion.Form:Button>
33-
</div>
34-
</Neos.Fusion.Form:Form>
10+
<Neos.Fusion.Form:Form form.target.action="create">
11+
<div class="neos-control-group">
12+
<img src={qrCode} style="width: 100%; max-width: 400px"/>
13+
</div>
14+
15+
<div class="neos-control-group neos-two-factor__secret-wrapper">
16+
<Neos.Fusion.Form:Hidden attributes.id="secret" field.name="secret" field.value={secret}/>
17+
18+
<div class="neos-actions">
19+
<button type="button" class="neos-button neos-login-btn neos-two-factor__secret__show__button">
20+
{I18n.id('form.secret.show').package('Sandstorm.NeosTwoFactorAuthentication')}
21+
</button>
22+
</div>
23+
24+
<dialog>
25+
<div>
26+
<div class="neos-two-factor__secret">
27+
<p>
28+
{
29+
Array.join(
30+
Array.map(
31+
String.split(secret, ''),
32+
char => Type.isNumeric(char) ? '<span class="neos-two-factor__secret__number">' + char + '</span>' : '<span>' + char + '</span>'
33+
),
34+
''
35+
)
36+
}
37+
</p>
38+
39+
<div class="neos-two-factor__secret__overflow-indicator--left" aria-hidden="true">
40+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
41+
<!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.-->
42+
<path d="M9.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l192 192c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L77.3 256 246.6 86.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-192 192z"/>
43+
</svg>
44+
</div>
45+
<div class="neos-two-factor__secret__overflow-indicator--right" aria-hidden="true">
46+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512">
47+
<!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.-->
48+
<path d="M310.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L242.7 256 73.4 86.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l192 192z"/>
49+
</svg>
50+
</div>
51+
</div>
52+
53+
<div class="neos-two-factor__dialog__actions neos-actions">
54+
<button type="button" class="neos-two-factor__secret__copy__button neos-button neos-login-btn">
55+
<span class="neos-two-factor__secret__copy__button__icon">
56+
<i>
57+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512">
58+
<!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.-->
59+
<path d="M280 64l40 0c35.3 0 64 28.7 64 64l0 320c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 128C0 92.7 28.7 64 64 64l40 0 9.6 0C121 27.5 153.3 0 192 0s71 27.5 78.4 64l9.6 0zM64 112c-8.8 0-16 7.2-16 16l0 320c0 8.8 7.2 16 16 16l256 0c8.8 0 16-7.2 16-16l0-320c0-8.8-7.2-16-16-16l-16 0 0 24c0 13.3-10.7 24-24 24l-88 0-88 0c-13.3 0-24-10.7-24-24l0-24-16 0zm128-8a24 24 0 1 0 0-48 24 24 0 1 0 0 48z"/>
60+
</svg>
61+
</i>
62+
</span>
63+
<span class="neos-two-factor__secret__copy__button__icon neos-two-factor__hidden">
64+
<i>
65+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
66+
<!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.-->
67+
<path d="M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"/>
68+
</svg>
69+
</i>
70+
</span>
71+
{I18n.id('form.secret.copy').package('Sandstorm.NeosTwoFactorAuthentication')}
72+
</button>
73+
<button type="button" class="neos-two-factor__secret__close__button neos-button neos-login-btn">
74+
{I18n.id('form.secret.close').package('Sandstorm.NeosTwoFactorAuthentication')}
75+
</button>
76+
</div>
77+
</div>
78+
</dialog>
79+
</div>
80+
81+
<div class="neos-control-group">
82+
<Neos.Fusion.Form:Input
83+
field.name="secondFactorFromApp"
84+
attributes.required="required"
85+
attributes.id="secondFactorFromApp"
86+
attributes.placeholder={I18n.id('otp-placeholder').package('Sandstorm.NeosTwoFactorAuthentication')}
87+
attributes.aria-label={I18n.id('otp-placeholder').package('Sandstorm.NeosTwoFactorAuthentication')}
88+
attributes.autocomplete="off"
89+
/>
90+
</div>
91+
92+
<div class="neos-control-group">
93+
<Neos.Fusion.Form:Button>
94+
{I18n.id('module.new.submit-otp').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()}
95+
</Neos.Fusion.Form:Button>
96+
</div>
97+
</Neos.Fusion.Form:Form>
98+
99+
<Neos.Fusion:Loop items={props.scripts}>
100+
<script @children="attributes.src">
101+
<Neos.Fusion:ResourceUri path={item}/>
102+
</script>
103+
</Neos.Fusion:Loop>
35104
`
36105
}
37106
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
Sandstorm.NeosTwoFactorAuthentication.LoginController.setupSecondFactor = Sandstorm.NeosTwoFactorAuthentication:Page.SetupSecondFactorPage {
22
site = ${site}
33
styles = ${styles}
4+
scripts = ${scripts}
45
username = ${username}
56
flashMessages = ${flashMessages}
67
qrCode = ${qrCode}
8+
secret = ${secret}
79
}

0 commit comments

Comments
 (0)