From: Alexander Ebert Date: Mon, 11 Dec 2023 16:50:18 +0000 (+0100) Subject: Gracefully handle invalid license credentials X-Git-Tag: 6.0.4_dev_1~13 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=613d9faf45c99cf712aa2b976ae10df1583f58f5;p=GitHub%2FWoltLab%2FWCF.git Gracefully handle invalid license credentials See https://www.woltlab.com/community/thread/302503-button-lizensierte-produkte-f%C3%BChrt-zu-fehler/ --- diff --git a/wcfsetup/install/files/lib/acp/form/LicenseEditForm.class.php b/wcfsetup/install/files/lib/acp/form/LicenseEditForm.class.php index 5a1d93ee3c..5186b3376b 100644 --- a/wcfsetup/install/files/lib/acp/form/LicenseEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/LicenseEditForm.class.php @@ -55,6 +55,8 @@ final class LicenseEditForm extends AbstractFormBuilderForm private string $url; + private bool $failedValidation = false; + /** * @inheritDoc */ @@ -66,6 +68,10 @@ final class LicenseEditForm extends AbstractFormBuilderForm if ($url && ApplicationHandler::getInstance()->isInternalURL($url)) { $this->url = $url; } + + if (isset($_GET['failedValidation'])) { + $this->failedValidation = true; + } } /** @@ -146,6 +152,16 @@ final class LicenseEditForm extends AbstractFormBuilderForm ->fieldId('noCredentialsConfirm') ); } + + if ($this->failedValidation) { + $formField = $this->form->getNodeById('serialNo'); + if ($formField instanceof TextFormField) { + $formField->addValidationError(new FormFieldValidationError( + 'failedValidation', + 'wcf.acp.firstTimeSetup.license.credentials.error.failedValidation' + )); + } + } } /** diff --git a/wcfsetup/install/files/lib/acp/page/LicensePage.class.php b/wcfsetup/install/files/lib/acp/page/LicensePage.class.php index b7020d050e..09004c7126 100644 --- a/wcfsetup/install/files/lib/acp/page/LicensePage.class.php +++ b/wcfsetup/install/files/lib/acp/page/LicensePage.class.php @@ -2,7 +2,9 @@ namespace wcf\acp\page; +use GuzzleHttp\Exception\ConnectException; use Laminas\Diactoros\Response\RedirectResponse; +use Psr\Http\Client\ClientExceptionInterface; use wcf\acp\form\LicenseEditForm; use wcf\data\package\Package; use wcf\data\package\update\PackageUpdate; @@ -71,7 +73,20 @@ final class LicensePage extends AbstractPage // Cache valid license data for 2 minutes. || $licenseData->creationDate->getTimestamp() < (\TIME_NOW - 2 * 60) ) { - $licenseData = $licenseApi->fetchFromRemote(); + try { + $licenseData = $licenseApi->fetchFromRemote(); + } catch (ConnectException | ClientExceptionInterface) { + return new RedirectResponse( + LinkHandler::getInstance()->getControllerLink( + LicenseEditForm::class, + [ + 'failedValidation' => 1, + 'url' => LinkHandler::getInstance()->getControllerLink(LicensePage::class), + ], + ), + ); + } + $licenseApi->updateLicenseFile($licenseData); } } catch (ParsingFailed $e) {