From: Tim Düsterhus Date: Tue, 17 Nov 2020 09:24:01 +0000 (+0100) Subject: Add MultifactorManageForm::generateBackupCodes() X-Git-Tag: 5.4.0_Alpha_1~555^2~47^2~12 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4d62cedade56ab52376eef0a939cf3ba2f04d478;p=GitHub%2FWoltLab%2FWCF.git Add MultifactorManageForm::generateBackupCodes() --- diff --git a/wcfsetup/install/files/lib/form/MultifactorManageForm.class.php b/wcfsetup/install/files/lib/form/MultifactorManageForm.class.php index 38130188aa..1afd08e3c8 100644 --- a/wcfsetup/install/files/lib/form/MultifactorManageForm.class.php +++ b/wcfsetup/install/files/lib/form/MultifactorManageForm.class.php @@ -122,35 +122,7 @@ class MultifactorManageForm extends AbstractFormBuilderForm { WCF::getDB()->beginTransaction(); if (!$this->hasBackupCodes()) { - $backupMethod = $this->getBackupCodesObjectType(); - $backupProcessor = $backupMethod->getProcessor(); - - // Create Form - $form = FormDocument::create('backupCodes'); - $backupProcessor->createManagementForm($form, null, []); - $form->build(); - - // Process Form - $form->requestData([ - 'generateCodes' => 'generateCodes', - ]); - $form->readValues(); - $backupSetupId = Setup::allocateSetUpId($backupMethod, WCF::getUser()); - $returnData = $backupProcessor->processManagementForm($form, $backupSetupId); - $form->cleanup(); - - // Re-create form - $form = FormDocument::create('backupCodes'); - $backupProcessor->createManagementForm($form, $backupSetupId, $returnData); - /** @var IFormParentNode $container */ - $container = $form->getNodeById('existingCodesContainer'); - $container->insertBefore( - TemplateFormNode::create('initialBackup') - ->templateName('__multifactorManageInitialBackup'), - 'existingCodes' - ); - $form->build(); - $this->backupForm = $form; + $this->generateBackupCodes(); } WCF::getDB()->commitTransaction(); @@ -173,6 +145,41 @@ class MultifactorManageForm extends AbstractFormBuilderForm { return $setup !== null; } + /** + * Generates the backup codes after initial setup. + */ + protected function generateBackupCodes(): void { + $backupMethod = $this->getBackupCodesObjectType(); + $backupProcessor = $backupMethod->getProcessor(); + + // Create Form + $form = FormDocument::create('backupCodes'); + $backupProcessor->createManagementForm($form, null, []); + $form->build(); + + // Process Form + $form->requestData([ + 'generateCodes' => 'generateCodes', + ]); + $form->readValues(); + $backupSetupId = Setup::allocateSetUpId($backupMethod, WCF::getUser()); + $returnData = $backupProcessor->processManagementForm($form, $backupSetupId); + $form->cleanup(); + + // Re-create form + $form = FormDocument::create('backupCodes'); + $backupProcessor->createManagementForm($form, $backupSetupId, $returnData); + /** @var IFormParentNode $container */ + $container = $form->getNodeById('existingCodesContainer'); + $container->insertBefore( + TemplateFormNode::create('initialBackup') + ->templateName('__multifactorManageInitialBackup'), + 'existingCodes' + ); + $form->build(); + $this->backupForm = $form; + } + /** * @inheritDoc */