* @inheritDoc
*/
public function createManagementForm(IFormDocument $form, ?Setup $setup, $returnData = null): void {
+ if ($returnData !== null) {
+ \assert(\is_array($returnData));
+ \assert(
+ isset($returnData['action']) &&
+ ($returnData['action'] === 'add' || $returnData['action'] === 'delete')
+ );
+ \assert(isset($returnData['deviceName']));
+ $form->successMessage('wcf.user.security.multifactor.totp.success.'.$returnData['action'], [
+ 'deviceName' => $returnData['deviceName'],
+ ]);
+ }
+
$form->addDefaultButton(false);
$newDeviceContainer = NewDeviceContainer::create()
->label('wcf.user.security.multifactor.totp.newDevice')
/**
* @inheritDoc
*/
- public function processManagementForm(IFormDocument $form, Setup $setup): void {
+ public function processManagementForm(IFormDocument $form, Setup $setup): array {
$formData = $form->getData();
\assert(
);
if (!empty($formData['delete'])) {
+ // Fetch deviceName for success message.
+ $sql = "SELECT deviceName
+ FROM wcf".WCF_N."_user_multifactor_totp
+ WHERE setupID = ?
+ AND deviceID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute([
+ $setup->getId(),
+ $formData['delete'],
+ ]);
+ $deviceName = $statement->fetchSingleColumn();
+
+ // Remove the device.
$sql = "DELETE FROM wcf".WCF_N."_user_multifactor_totp
WHERE setupID = ?
AND deviceID = ?";
$formData['delete'],
]);
+ // Check the contract that the last device may not be removed.
$sql = "SELECT COUNT(*)
FROM wcf".WCF_N."_user_multifactor_totp
WHERE setupID = ?";
if (!$statement->fetchSingleColumn()) {
throw new \LogicException('Unreachable');
}
+
+ return [
+ 'action' => 'delete',
+ 'deviceName' => $deviceName,
+ ];
}
else {
$defaultName = WCF::getLanguage()->getDynamicVariable('wcf.user.security.multifactor.totp.deviceName.default');
+ $deviceName = $formData['data']['deviceName'] ?: $defaultName;
+
$sql = "INSERT INTO wcf".WCF_N."_user_multifactor_totp
(setupID, deviceID, deviceName, secret, minCounter, createTime)
VALUES (?, ?, ?, ?, ?, ?)";
$statement->execute([
$setup->getId(),
Hex::encode(\random_bytes(16)),
- $formData['data']['deviceName'] ?: $defaultName,
+ $deviceName,
$formData['data']['secret'],
$formData['data']['code']['minCounter'],
\TIME_NOW,
]);
+
+ return [
+ 'action' => 'add',
+ 'deviceName' => $deviceName,
+ ];
}
}
<li>{if LANGUAGE_USE_INFORMAL_VARIANT}Scanne{else}Scannen Sie{/if} den QR-Code in der App.</li>
<li>{if LANGUAGE_USE_INFORMAL_VARIANT}Gib{else}Geben Sie{/if} den durch die App generierten 6-stelligen Einmalcode ein.</li>
</ol>]]></item>
+ <item name="wcf.user.security.multifactor.totp.success.add"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Dein{else}Ihr{/if} Smartphone <strong>{$deviceName}</strong> wurde erfolgreich hinterlegt.]]></item>
<item name="wcf.user.security.multifactor.totp.createTime"><![CDATA[Eingerichtet]]></item>
<item name="wcf.user.security.multifactor.totp.useTime"><![CDATA[Zuletzt Benutzt]]></item>
<item name="wcf.user.security.multifactor.totp.lastDevice"><![CDATA[Wenn Sie ihr Smartphone wechseln möchten, fügen Sie bitte zunächst Ihr neues Smartphone hinzu, bevor Sie Ihr letztes Gerät <strong>{$deviceName}</strong> entfernen. Verwenden Sie bitte die <a href="{link controller='AccountSecurity'}{/link}">Übersicht in der Benutzerkonto-Sicherheit</a>, wenn Sie die Mehrfaktor-Authentifizierung deaktivieren möchten.]]></item>
<item name="wcf.user.security.multifactor.totp.lastDevice.title"><![CDATA[Letztes Gerät]]></item>
+ <item name="wcf.user.security.multifactor.totp.success.delete"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Dein{else}Ihr{/if} Smartphone <strong>{$deviceName}</strong> wurde erfolgreich entfernt.]]></item>
</category>
<category name="wcf.user.trophy">
<item name="wcf.user.trophy.trophyPoints"><![CDATA[Trophäen]]></item>
<li>Scan the QR code within the app.</li>
<li>Enter the 6 digit one time code generated by the app.</li>
</ol>]]></item>
+ <item name="wcf.user.security.multifactor.totp.success.add"><![CDATA[Your smartphone <strong>{$deviceName}</strong> has successfully been added.]]></item>
<item name="wcf.user.security.multifactor.totp.createTime"><![CDATA[Set Up]]></item>
<item name="wcf.user.security.multifactor.totp.useTime"><![CDATA[Last Used]]></item>
<item name="wcf.user.security.multifactor.totp.lastDevice"><![CDATA[Please add your new device before removing your last device <strong>{$deviceName}</strong> if you want to switch phones. Use the <a href="{link controller='AccountSecurity'}{/link}">Overview in Account Security</a> if you want to disable multi-factor authentication.]]></item>
<item name="wcf.user.security.multifactor.totp.lastDevice.title"><![CDATA[Last Device]]></item>
+ <item name="wcf.user.security.multifactor.totp.success.delete"><![CDATA[Your smartphone <strong>{$deviceName}</strong> has successfully been removed.]]></item>
</category>
<category name="wcf.user.trophy">
<item name="wcf.user.trophy.trophyPoints"><![CDATA[Trophies]]></item>