Improve the workflow for missing license credentials
authorAlexander Ebert <ebert@woltlab.com>
Fri, 8 Sep 2023 10:33:49 +0000 (12:33 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 8 Sep 2023 10:33:49 +0000 (12:33 +0200)
wcfsetup/install/files/acp/templates/firstTimeSetupCompleted.tpl
wcfsetup/install/files/lib/acp/form/LicenseEditForm.class.php
wcfsetup/install/files/lib/acp/page/LicensePage.class.php

index 61bc7aa4c3f9faf8ddf358527094458fb782efd7..c0f4a57f43385d34b28eeea25ef428d606c0f020 100644 (file)
@@ -30,7 +30,7 @@
                        </div>
                        <div class="firstTimeSetup__nextStep__content">
                                <h3 class="firstTimeSetup__nextStep__title">
-                                       <a href="{link controller='PackageStartInstall'}{/link}">
+                                       <a href="{link controller='License'}{/link}">
                                                {lang}wcf.acp.firstTimeSetup.completed.apps.title{/lang}
                                        </a>
                                </h3>
index 64629d5b8aafc4649e6543cd90875b5d55b4fbe4..02f1a376da2328bfe5719a2aac9ba5d424e4172e 100644 (file)
@@ -7,6 +7,7 @@ use CuyZ\Valinor\Mapper\Source\Source;
 use CuyZ\Valinor\MapperBuilder;
 use GuzzleHttp\Exception\ConnectException;
 use GuzzleHttp\Psr7\Request;
+use Laminas\Diactoros\Response\RedirectResponse;
 use Psr\Http\Client\ClientExceptionInterface;
 use wcf\data\option\Option;
 use wcf\data\option\OptionAction;
@@ -15,6 +16,7 @@ use wcf\data\package\update\server\PackageUpdateServerAction;
 use wcf\data\package\update\server\PackageUpdateServerList;
 use wcf\form\AbstractForm;
 use wcf\form\AbstractFormBuilderForm;
+use wcf\system\application\ApplicationHandler;
 use wcf\system\form\builder\container\FormContainer;
 use wcf\system\form\builder\field\CheckboxFormField;
 use wcf\system\form\builder\field\dependency\EmptyFormFieldDependency;
@@ -22,6 +24,8 @@ use wcf\system\form\builder\field\TextFormField;
 use wcf\system\form\builder\field\validation\FormFieldValidationError;
 use wcf\system\form\builder\field\validation\FormFieldValidator;
 use wcf\system\io\HttpFactory;
+use wcf\system\request\LinkHandler;
+use wcf\system\WCF;
 
 /**
  * Set up or edit the license data.
@@ -50,6 +54,21 @@ final class LicenseEditForm extends AbstractFormBuilderForm
 
     private array $apiResponse;
 
+    private string $url;
+
+    /**
+     * @inheritDoc
+     */
+    public function readParameters()
+    {
+        parent::readParameters();
+
+        $url = $_GET['url'] ?? '';
+        if ($url && ApplicationHandler::getInstance()->isInternalURL($url)) {
+            $this->url = $url;
+        }
+    }
+
     /**
      * @inheritDoc
      */
@@ -125,6 +144,23 @@ final class LicenseEditForm extends AbstractFormBuilderForm
         }
     }
 
+    /**
+     * @inheritDoc
+     */
+    protected function setFormAction()
+    {
+        if (!isset($this->url)) {
+            parent::setFormAction();
+            return;
+        }
+
+        $this->form->action(
+            LinkHandler::getInstance()->getControllerLink(static::class, [
+                'url' => $this->url,
+            ])
+        );
+    }
+
     private function getLicenseData(string $licenseNo, string $serialNo): array
     {
         $request = new Request(
@@ -217,5 +253,21 @@ final class LicenseEditForm extends AbstractFormBuilderForm
         }
 
         $this->saved();
+
+        if (isset($this->url)) {
+            return new RedirectResponse($this->url);
+        }
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function assignVariables()
+    {
+        parent::assignVariables();
+
+        WCF::getTPL()->assign([
+            'url' => $this->url,
+        ]);
     }
 }
index 564bb57772a9dc6f5eb26ddf0483829535dfa986..70176d83fb12cbe952c34980ef015b587d7d1151 100644 (file)
@@ -51,7 +51,12 @@ final class LicensePage extends AbstractPage
 
         if (!$this->hasLicenseCredentials()) {
             return new RedirectResponse(
-                LinkHandler::getInstance()->getControllerLink(LicenseEditForm::class),
+                LinkHandler::getInstance()->getControllerLink(
+                    LicenseEditForm::class,
+                    [
+                        'url' => LinkHandler::getInstance()->getControllerLink(LicensePage::class),
+                    ],
+                ),
             );
         }