Skip to content

Commit

Permalink
Merge pull request #27 from lorenzulrich/task/cleanup-language-labels
Browse files Browse the repository at this point in the history
Cleanup look, finish translations, add German translation
  • Loading branch information
JamesAlias authored Feb 7, 2024
2 parents de151b2 + 6371c76 commit 4d899a9
Show file tree
Hide file tree
Showing 12 changed files with 332 additions and 62 deletions.
60 changes: 55 additions & 5 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Neos\Error\Messages\Message;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\I18n\Translator;
use Neos\Flow\Mvc\Exception\StopActionException;
use Neos\Flow\Mvc\FlashMessage\FlashMessageService;
use Neos\Flow\Persistence\Exception\IllegalObjectTypeException;
Expand Down Expand Up @@ -61,6 +62,12 @@ class BackendController extends AbstractModuleController
*/
protected $tOTPService;

/**
* @Flow\Inject
* @var Translator
*/
protected $translator;

protected $defaultViewObjectName = FusionView::class;

/**
Expand Down Expand Up @@ -130,15 +137,35 @@ public function createAction(string $secret, string $secondFactorFromApp): void
$isValid = TOTPService::checkIfOtpIsValid($secret, $secondFactorFromApp);

if (!$isValid) {
$this->addFlashMessage('Submitted OTP was not correct', '', Message::SEVERITY_WARNING);
$this->addFlashMessage(
$this->translator->translateById(
'module.new.flashMessage.submittedOtpIncorrect',
[],
null,
null,
'Backend',
'Sandstorm.NeosTwoFactorAuthentication'
),
'',
Message::SEVERITY_WARNING
);
$this->redirect('new');
}

$this->secondFactorRepository->createSecondFactorForAccount($secret, $this->securityContext->getAccount());

$this->secondFactorSessionStorageService->setAuthenticationStatus(AuthenticationStatus::AUTHENTICATED);

$this->addFlashMessage('Successfully created otp');
$this->addFlashMessage(
$this->translator->translateById(
'module.new.flashMessage.successfullyRegisteredOtp',
[],
null,
null,
'Backend',
'Sandstorm.NeosTwoFactorAuthentication'
)
);
$this->redirect('index');
}

Expand All @@ -159,14 +186,37 @@ public function deleteAction(SecondFactor $secondFactor): void
&& count($this->secondFactorRepository->findByAccount($account)) <= 1
) {
$this->addFlashMessage(
'Can not remove last second factor! Second factor is enforced, you need at least one!',
'Error',
$this->translator->translateById(
'module.index.delete.flashMessage.cannotRemoveLastSecondFactor',
[],
null,
null,
'Backend',
'Sandstorm.NeosTwoFactorAuthentication'
),
$this->translator->translateById(
'module.index.delete.flashMessage.errorHeader',
[],
null,
null,
'Backend',
'Sandstorm.NeosTwoFactorAuthentication'
),
Message::SEVERITY_ERROR
);
} else {
$this->secondFactorRepository->remove($secondFactor);
$this->persistenceManager->persistAll();
$this->addFlashMessage('Second factor was deleted');
$this->addFlashMessage(
$this->translator->translateById(
'module.index.delete.flashMessage.secondFactorDeleted',
[],
null,
null,
'Backend',
'Sandstorm.NeosTwoFactorAuthentication'
)
);
}
}

Expand Down
52 changes: 48 additions & 4 deletions Classes/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Configuration\Exception\InvalidConfigurationTypeException;
use Neos\Flow\I18n\Translator;
use Neos\Flow\Mvc\Controller\ActionController;
use Neos\Flow\Mvc\Exception\StopActionException;
use Neos\Flow\Mvc\FlashMessage\FlashMessageService;
Expand Down Expand Up @@ -75,6 +76,12 @@ class LoginController extends ActionController
*/
protected $tOTPService;

/**
* @Flow\Inject
* @var Translator
*/
protected $translator;

/**
* This action decides which tokens are already authenticated
* and decides which is next to authenticate
Expand Down Expand Up @@ -109,8 +116,25 @@ public function checkSecondFactorAction(string $otp): void
if ($isValidOtp) {
$this->secondFactorSessionStorageService->setAuthenticationStatus(AuthenticationStatus::AUTHENTICATED);
} else {
// FIXME: not visible in View!
$this->addFlashMessage('Invalid OTP!', 'Error', Message::SEVERITY_ERROR);
$this->addFlashMessage(
$this->translator->translateById(
'login.flashMessage.invalidOtp',
[],
null,
null,
'Main',
'Sandstorm.NeosTwoFactorAuthentication'
),
$this->translator->translateById(
'login.flashMessage.errorHeader',
[],
null,
null,
'Main',
'Sandstorm.NeosTwoFactorAuthentication'
),
Message::SEVERITY_ERROR
);
}

$originalRequest = $this->securityContext->getInterceptedRequest();
Expand Down Expand Up @@ -161,15 +185,35 @@ public function createSecondFactorAction(string $secret, string $secondFactorFro
$isValid = TOTPService::checkIfOtpIsValid($secret, $secondFactorFromApp);

if (!$isValid) {
$this->addFlashMessage('Submitted OTP was not correct.', '', Message::SEVERITY_WARNING);
$this->addFlashMessage(
$this->translator->translateById(
'login.flashMessage.submittedOtpIncorrect',
[],
null,
null,
'Main',
'Sandstorm.NeosTwoFactorAuthentication'
),
'',
Message::SEVERITY_WARNING
);
$this->redirect('setupSecondFactor');
}

$account = $this->securityContext->getAccount();

$this->secondFactorRepository->createSecondFactorForAccount($secret, $account);

$this->addFlashMessage('Successfully created otp.');
$this->addFlashMessage(
$this->translator->translateById(
'login.flashMessage.successfullyRegisteredOtp',
[],
null,
null,
'Main',
'Sandstorm.NeosTwoFactorAuthentication'
),
);

$this->secondFactorSessionStorageService->setAuthenticationStatus(AuthenticationStatus::AUTHENTICATED);

Expand Down
6 changes: 5 additions & 1 deletion Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ Neos:
controller: 'Sandstorm\NeosTwoFactorAuthentication\Controller\BackendController'
label: 'Sandstorm.NeosTwoFactorAuthentication:Backend:module.label'
description: 'Sandstorm.NeosTwoFactorAuthentication:Backend:module.description'
icon: 'fas fa-lock'
icon: 'fas fa-qrcode'

userInterface:
translation:
autoInclude:
'Sandstorm.NeosTwoFactorAuthentication':
- '*'

backendLoginForm:
stylesheets:
'Sandstorm.NeosTwoFactorAuthentication:AdditionalStyles': 'resource://Sandstorm.NeosTwoFactorAuthentication/Public/Styles/Login.css'

Flow:
http:
middlewares:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ prototype(Sandstorm.NeosTwoFactorAuthentication:Component.FlashMessages) < proto
renderer = afx`
<ul id="neos-notifications-inline">
<Neos.Fusion:Loop items={props.flashMessages} itemName="flashMessage">
<li data-type={String.toLowerCase(props.flashMessage.severity)}>{flashMessage}</li>
<li data-type={String.toLowerCase(flashMessage.severity)}>{flashMessage}</li>
</Neos.Fusion:Loop>
</ul>
`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
prototype(Sandstorm.NeosTwoFactorAuthentication:Component.LoginFlashMessages) < prototype(Neos.Fusion:Component) {
flashMessages = ${[]}

renderer = afx`
<Neos.Fusion:Loop items={props.flashMessages} itemName="flashMessage">
<div class={'neos-two-factor-flashmessage neos-two-factor-flashmessage-' + String.toLowerCase(flashMessage.severity)}>{flashMessage}</div>
</Neos.Fusion:Loop>
`
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ prototype(Sandstorm.NeosTwoFactorAuthentication:Component.SecondFactorList) < pr
<table class="neos-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>{I18n.id('module.index.list.header.name').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()}</th>
<th>{I18n.id('module.index.list.header.type').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()}</th>
<th>&nbsp;</th>
</tr>
</thead>
Expand Down Expand Up @@ -44,7 +44,7 @@ prototype(Sandstorm.NeosTwoFactorAuthentication:Component.SecondFactorList.Entry
<td>{props.factorAndPerson.secondFactor.typeAsName}</td>
<td>
<button class="neos-button neos-button-danger" data-toggle="modal"
href={'#user-' + props.iterator.index} title="todo" data-neos-toggle="tooltip">
href={'#user-' + props.iterator.index} title={I18n.id('module.index.list.action.delete').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()} data-neos-toggle="tooltip">
<i class="fas fa-trash-alt icon-white"></i>
</button>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ prototype(Sandstorm.NeosTwoFactorAuthentication:Page.SetupSecondFactorPage) < pr
</h1>

<div class="neos-login-body neos">
<Sandstorm.NeosTwoFactorAuthentication:Component.FlashMessages flashMessages={props.flashMessages} />
<Sandstorm.NeosTwoFactorAuthentication:Component.LoginFlashMessages flashMessages={props.flashMessages} />
<Neos.Fusion.Form:Form form.target.action="setupSecondFactor">
<Neos.Fusion.Form:Hidden field.name="secret" field.value={secret}/>

<div class="neos-control-group">
<img src={qrCode} style="width: 100%; max-width: 400px"/>
</div>
Expand All @@ -95,8 +94,8 @@ prototype(Sandstorm.NeosTwoFactorAuthentication:Page.SetupSecondFactorPage) < pr
/>
</div>

<div class="neos-control-group">
<Neos.Fusion.Form:Button>
<div class="neos-control-group neos-actions">
<Neos.Fusion.Form:Button attributes.class="neos-span5 neos-pull-right neos-button neos-login-btn">
{I18n.id('module.new.submit-otp').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()}
</Neos.Fusion.Form:Button>
</div>
Expand Down
86 changes: 86 additions & 0 deletions Resources/Private/Translations/de/Backend.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="Sandstorm.NeosTwoFactorAuthentication" source-language="en" datatype="plaintext" target-language="de">
<body>
<trans-unit id="module.label" xml:space="preserve">
<source>Two-Factor Authentication</source>
<target>Zwei-Faktor-Authentifizierung</target>
</trans-unit>
<trans-unit id="module.description" xml:space="preserve">
<source>This module allows registering and managing a second factor for the backend login.</source>
<target>Dieses Modul erlaubt die Einrichtung und Verwaltung eines zweiten Faktors für das Backend-Login.</target>
</trans-unit>

<trans-unit id="module.index.title" xml:space="preserve">
<source>List of all registered second factors</source>
<target>Liste aller registrierten zweiten Faktoren</target>
</trans-unit>
<trans-unit id="module.index.list.header.name" xml:space="preserve">
<source>Name</source>
<target>Name</target>
</trans-unit>
<trans-unit id="module.index.list.header.type" xml:space="preserve">
<source>Type</source>
<target>Typ</target>
</trans-unit>
<trans-unit id="module.index.list.action.delete" xml:space="preserve">
<source>Delete second factor</source>
<target>Zweiten Faktor löschen</target>
</trans-unit>
<trans-unit id="module.index.create" xml:space="preserve">
<source>Create second factor</source>
<target>Zweiten Faktor erstellen</target>
</trans-unit>

<trans-unit id="module.index.delete.header" xml:space="preserve">
<source>Do you really want to delete the second factor?</source>
<target>Wollen Sie den zweiten Faktor wirklich löschen?</target>
</trans-unit>
<trans-unit id="module.index.delete.text" xml:space="preserve">
<source>Deleting a second factor can not be undone.</source>
<target>Das Löschen eines zweiten Faktors kann nicht rückgängig gemacht werden.</target>
</trans-unit>
<trans-unit id="module.index.delete.cancel" xml:space="preserve">
<source>Cancel</source>
<target>Abbrechen</target>
</trans-unit>
<trans-unit id="module.index.delete.confirm" xml:space="preserve">
<source>Delete second factor</source>
<target>Zweiten Faktor löschen</target>
</trans-unit>
<trans-unit id="module.index.delete.flashMessage.errorHeader" xml:space="preserve">
<source>Error</source>
<target>Fehler</target>
</trans-unit>
<trans-unit id="module.index.delete.flashMessage.secondFactorDeleted" xml:space="preserve">
<source>The second factor was deleted.</source>
<target>Der zweite Faktor wurde gelöscht.</target>
</trans-unit>
<trans-unit id="module.index.delete.flashMessage.cannotRemoveLastSecondFactor" xml:space="preserve">
<source>Cannot remove the last second factor because the two-factor authentication is enforced.</source>
<target>Der letzte zweite Faktor kann nicht gelöscht werden, da die Zwei-Faktor-Authentifizierung erzwungen wird.</target>
</trans-unit>

<trans-unit id="module.new.title" xml:space="preserve">
<source>Register new second factor</source>
<target>Neuen zweiten Faktor registrieren</target>
</trans-unit>
<trans-unit id="module.new.description" xml:space="preserve">
<source>To register a new second factor, scan the QR code with any TOTP app (e.g. Google Authenticator, Microsoft Authenticator, Authy) and enter the code.</source>
<target>Scannen Sie den QR-Code in Ihrer TOTP-App (z.B. Google Authenticator, Microsoft Authenticator, Authy) und geben Sie den Code ein, um einen neuen zweiten Faktor zu registrieren.</target>
</trans-unit>
<trans-unit id="module.new.submit-otp" xml:space="preserve">
<source>Register new OTP</source>
<target>Neues OTP registrieren</target>
</trans-unit>
<trans-unit id="module.new.flashMessage.submittedOtpIncorrect" xml:space="preserve">
<source>Submitted OTP was incorrect.</source>
<target>Das eingegebene OTP ist nicht korrekt.</target>
</trans-unit>
<trans-unit id="module.new.flashMessage.successfullyRegisteredOtp" xml:space="preserve">
<source>OTP was registered successfully.</source>
<target>Das OTP wurde erfolgreich registriert.</target>
</trans-unit>
</body>
</file>
</xliff>
27 changes: 27 additions & 0 deletions Resources/Private/Translations/de/Main.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="Sandstorm.NeosTwoFactorAuthentication" source-language="en" datatype="plaintext" target-language="de">
<body>
<trans-unit id="otp-placeholder" xml:space="preserve">
<source>OTP from App</source>
<target>OTP aus App</target>
</trans-unit>
<trans-unit id="login.flashMessage.errorHeader" xml:space="preserve">
<source>Error</source>
<target>Fehler</target>
</trans-unit>
<trans-unit id="login.flashMessage.invalidOtp" xml:space="preserve">
<source>The provided OTP is invalid.</source>
<target>Das eingegebene OTP ist ungültig.</target>
</trans-unit>
<trans-unit id="login.flashMessage.submittedOtpIncorrect" xml:space="preserve">
<source>Submitted OTP was incorrect.</source>
<target>Das eingegebene OTP ist nicht korrekt.</target>
</trans-unit>
<trans-unit id="login.flashMessage.successfullyRegisteredOtp" xml:space="preserve">
<source>OTP was registered successfully.</source>
<target>Das OTP wurde erfolgreich registriert.</target>
</trans-unit>
</body>
</file>
</xliff>
Loading

0 comments on commit 4d899a9

Please sign in to comment.