From 350d39fe4a47587b07dc297c0479008d41dd55da Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Mon, 23 Dec 2024 15:21:57 -0800 Subject: [PATCH] Link to the front end's Set Password template when sent from the front end Resolves #16340 --- CHANGELOG-WIP.md | 1 + src/services/Users.php | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index d25a614bdff..53dcf384584 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -113,6 +113,7 @@ - The system Login template is now rendered from `/login` (per the `loginPath` config setting) if a site template doesn’t exist in the same location. ([#16344](https://github.com/craftcms/cms/pull/16344)) - When a user with an active two-step verification method logs in from the front end, they’ll be redirected to `/login` (per the `loginPath` config setting) to complete the verification process. ([#16344](https://github.com/craftcms/cms/pull/16344)) - System templates (Login, Set Password, and error message screens) now have more generic styling when rendered on the front end, and can now have custom CSS styling via the `systemTemplateCss` config setting. ([#16344](https://github.com/craftcms/cms/pull/16344)) +- Verification emails now link to the front-end Set Password form, if the email was sent from the front end. ([#16340](https://github.com/craftcms/cms/issues/16340)) - Database rows with foreign keys referencing nonexistent rows are now deleted via garbage collection. - Pages which contain image transform generation URLs now set no-cache headers. ([#16195](https://github.com/craftcms/cms/discussions/16195)) - Reduced the size of GraphQL introspection schemas. ([#16326](https://github.com/craftcms/cms/pull/16326)) diff --git a/src/services/Users.php b/src/services/Users.php index 510481b5e1f..a44674d077e 100644 --- a/src/services/Users.php +++ b/src/services/Users.php @@ -1597,9 +1597,12 @@ private function _getUserUrl(User $user, string $fePath, string $cpPath): string 'id' => $user->uid, ]; + $isCpRequest = Craft::$app->getRequest()->getIsCpRequest(); $generalConfig = Craft::$app->getConfig()->getGeneral(); + $cp = ( - $user->can('accessCp') || + Craft::$app->edition->value < CmsEdition::Pro->value || + ($isCpRequest && $user->can('accessCp')) || ($generalConfig->headlessMode && !UrlHelper::isAbsoluteUrl($fePath)) ); $scheme = UrlHelper::getSchemeForTokenizedUrl($cp); @@ -1610,7 +1613,7 @@ private function _getUserUrl(User $user, string $fePath, string $cpPath): string // Only use cpUrl() if this is a control panel request, or the base control panel URL has been explicitly set, // so UrlHelper won't use HTTP_HOST - if ($generalConfig->baseCpUrl || Craft::$app->getRequest()->getIsCpRequest()) { + if ($generalConfig->baseCpUrl || $isCpRequest) { $url = UrlHelper::cpUrl($cpPath, $params, $scheme); } else { $path = UrlHelper::prependCpTrigger($cpPath);