From: Tim Düsterhus Date: Tue, 24 Nov 2020 13:21:54 +0000 (+0100) Subject: Add email notification when using a backup code X-Git-Tag: 5.4.0_Alpha_1~555^2~33^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=bb9c9ae53b94362581587f80b7d641c21baa275f;p=GitHub%2FWoltLab%2FWCF.git Add email notification when using a backup code --- diff --git a/wcfsetup/install/files/lib/system/user/multifactor/BackupMultifactorMethod.class.php b/wcfsetup/install/files/lib/system/user/multifactor/BackupMultifactorMethod.class.php index 05d8fc4b5d..dbd7d44bc2 100644 --- a/wcfsetup/install/files/lib/system/user/multifactor/BackupMultifactorMethod.class.php +++ b/wcfsetup/install/files/lib/system/user/multifactor/BackupMultifactorMethod.class.php @@ -1,5 +1,6 @@ getAffectedRows() !== 1) { throw new \RuntimeException('Unable to invalidate the code.'); } + + $this->sendAuthenticationEmail($setup, $usedCode); + } + + /** + * Notifies the user that an emergency code has been used. + */ + private function sendAuthenticationEmail(Setup $setup, array $usedCode): void { + $sql = "SELECT COUNT(*) - COUNT(useTime) AS count + FROM wcf".WCF_N."_user_multifactor_backup + WHERE setupID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([$setup->getId()]); + + $remaining = $statement->fetchSingleColumn(); + + $email = new SimpleEmail(); + $email->setRecipient($setup->getUser()); + + $email->setSubject( + WCF::getLanguage()->getDynamicVariable('wcf.user.security.multifactor.backup.authenticationEmail.subject', [ + 'remaining' => $remaining, + 'usedCode' => $usedCode, + 'setup' => $setup, + ]) + ); + $email->setHtmlMessage( + WCF::getLanguage()->getDynamicVariable('wcf.user.security.multifactor.backup.authenticationEmail.body.html', [ + 'remaining' => $remaining, + 'usedCode' => $usedCode, + 'setup' => $setup, + ]) + ); + $email->setMessage( + WCF::getLanguage()->getDynamicVariable('wcf.user.security.multifactor.backup.authenticationEmail.body.plain', [ + 'remaining' => $remaining, + 'usedCode' => $usedCode, + 'setup' => $setup, + ]) + ); + + $email->send(); } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 994acdc89d..eaf9674fdb 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -4920,6 +4920,17 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email} {lang}wcf.user.security.multifactor.{$setup->getObjectType()->objectType}{/lang} wurde erfolgreich deaktiviert.]]> + + Hallo {$setup->getUser()->username}, + +

{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} den Notfall-Code {$usedCode[identifier]} zur Mehrfaktor-Authentifizierung genutzt. Dieser Code ist nun nicht mehr gültig. {plural value=$remaining 0='Es gibt keine weiteren gültigen Codes.' 1='Es verbleibt ein gültiger Code.' other='Es verbleiben # gültige Codes.'}

+ +

{if LANGUAGE_USE_INFORMAL_VARIANT}Du kannst{else}Sie können{/if} die Mehrfaktor-Authentifizierung in der Account-Sicherheit verwalten und dort neue Notfall-Codes generieren oder die Mehrfaktor-Authentifizierung deaktivieren.

]]>
+ getUser()->username}, + +{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} den Notfall-Code „{$usedCode[identifier]}“ zur Mehrfaktor-Authentifizierung genutzt. Dieser Code ist nun nicht mehr gültig. {plural value=$remaining 0='**Es gibt keine weiteren gültigen Codes.**' 1='Es verbleibt ein gültiger Code.' other='Es verbleiben # gültige Codes.'} {* this line ends with a space *} + +{if LANGUAGE_USE_INFORMAL_VARIANT}Du kannst{else}Sie können{/if} die Mehrfaktor-Authentifizierung in der Account-Sicherheit [URL:{link controller='AccountSecurity' isEmail=true}{/link}] verwalten und dort neue Notfall-Codes generieren oder die Mehrfaktor-Authentifizierung deaktivieren.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index f440faba8f..d0045d3e5b 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -4917,6 +4917,17 @@ Open the link below to access the user profile: {lang}wcf.user.security.multifactor.{$setup->getObjectType()->objectType}{/lang} method has successfully been disabled.]]> + + Dear {$setup->getUser()->username}, + +

You used the emergency code {$usedCode[identifier]} for multi-factor authentication. This code no longer is valid. {plural value=$remaining 0='You don't have any remaining codes.' 1='You have one remaining code.' other='You have # remaining codes.'}

+ +

You can manage multi-factor authentication within the Account Security page. Within account security you can generate new emergency codes or disable multi-factor authentication.

]]>
+ getUser()->username}, + +You used the emergency code “{$usedCode[identifier]}“ for multi-factor authentication. This code no longer is valid. {plural value=$remaining 0='**You don't have any remaining codes.**' 1='You have one remaining code.' other='You have # remaining codes.'} {* this line ends with a space *} + +You can manage multi-factor authentication within the Account Security page [URL:{link controller='AccountSecurity' isEmail=true}{/link}]. Within account security you can generate new emergency codes or disable multi-factor authentication.]]>