Add MultifactorManageForm::generateBackupCodes()
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 17 Nov 2020 09:24:01 +0000 (10:24 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 18 Nov 2020 12:56:38 +0000 (13:56 +0100)
wcfsetup/install/files/lib/form/MultifactorManageForm.class.php

index 38130188aaa0b23a9d2f94efecfceeea7a2d3e0b..1afd08e3c898b7cdcc8c1b34abd9815b1d652001 100644 (file)
@@ -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
         */