From 4d62cedade56ab52376eef0a939cf3ba2f04d478 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 17 Nov 2020 10:24:01 +0100 Subject: [PATCH] Add MultifactorManageForm::generateBackupCodes() --- .../lib/form/MultifactorManageForm.class.php | 65 ++++++++++--------- 1 file changed, 36 insertions(+), 29 deletions(-) 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 */ -- 2.20.1