Skip to content

Commit

Permalink
[TASK] Streamline "referrer" spelling in felogin code
Browse files Browse the repository at this point in the history
All PHP code is adjusted to use
proper spelling "referrer".

Existing Fluid variables or config options
are not touched.

Resolves: #101216
Releases: main, 12.4, 11.5
Change-Id: I8d18b1f269c921d01bcd1b5c3b7017527d92e72d
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/79582
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
liayn authored and bmack committed Jul 3, 2023
1 parent 7fa9a9f commit af48487
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
22 changes: 11 additions & 11 deletions typo3/sysext/felogin/Classes/Controller/LoginController.php
Expand Up @@ -169,7 +169,7 @@ public function loginAction(): ResponseInterface
'permaloginStatus' => $this->getPermaloginStatus(),
'redirectURL' => $this->redirectHandler->getLoginFormRedirectUrl($this->configuration, $this->isRedirectDisabled()),
'redirectReferrer' => $this->request->hasArgument('redirectReferrer') ? (string)$this->request->getArgument('redirectReferrer') : '',
'referer' => $this->getRefererForLoginForm(),
'referer' => $this->getReferrerForLoginForm(),
'noRedirect' => $this->isRedirectDisabled(),
]
);
Expand Down Expand Up @@ -230,22 +230,22 @@ public function logoutAction(int $redirectPageLogout = 0): ResponseInterface
*
* The evaluated `referer` is only returned, if it is considered as valid.
*/
protected function getRefererForLoginForm(): string
protected function getReferrerForLoginForm(): string
{
// Early return, if redirectMode is not configured to respect the referer
if (!$this->isRefererRedirectEnabled()) {
// Early return, if redirectMode is not configured to respect the referrer
if (!$this->isReferrerRedirectEnabled()) {
return '';
}

$referer = (string)(
$referrer = (string)(
$this->request->getParsedBody()['referer'] ??
$this->request->getQueryParams()['referer'] ??
$this->request->getServerParams()['HTTP_REFERER'] ??
''
);

if ($this->redirectUrlValidator->isValid($referer)) {
return $referer;
if ($this->redirectUrlValidator->isValid($referrer)) {
return $referrer;
}

return '';
Expand Down Expand Up @@ -300,13 +300,13 @@ protected function isPermaloginDisabled(int $permaLogin): bool
}

/**
* Returns, if redirect based on the referer is enabled
* Returns, if redirect based on the referrer is enabled
*/
protected function isRefererRedirectEnabled(): bool
protected function isReferrerRedirectEnabled(): bool
{
$refererRedirectModes = [RedirectMode::REFERER, RedirectMode::REFERER_DOMAINS];
$referrerRedirectModes = [RedirectMode::REFERRER, RedirectMode::REFERRER_DOMAINS];
$configuredRedirectModes = GeneralUtility::trimExplode(',', $this->settings['redirectMode'] ?? '');
return count(array_intersect($configuredRedirectModes, $refererRedirectModes)) > 0;
return count(array_intersect($configuredRedirectModes, $referrerRedirectModes)) > 0;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions typo3/sysext/felogin/Classes/Redirect/RedirectHandler.php
Expand Up @@ -154,11 +154,11 @@ protected function handleSuccessfulLogin(string $redirectMode, int $redirectPage
case RedirectMode::GETPOST:
$redirectUrl = $this->requestHandler->getRedirectUrlRequestParam();
break;
case RedirectMode::REFERER:
case RedirectMode::REFERRER:
$redirectUrl = $this->redirectModeHandler->redirectModeReferrer($redirectModeReferrer);
break;
case RedirectMode::REFERER_DOMAINS:
$redirectUrl = $this->redirectModeHandler->redirectModeRefererDomains($domains, $redirectModeReferrer);
case RedirectMode::REFERRER_DOMAINS:
$redirectUrl = $this->redirectModeHandler->redirectModeReferrerDomains($domains, $redirectModeReferrer);
break;
default:
$redirectUrl = '';
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/felogin/Classes/Redirect/RedirectMode.php
Expand Up @@ -30,6 +30,6 @@ final class RedirectMode
public const GETPOST = 'getpost';
public const USER_LOGIN = 'userLogin';
public const GROUP_LOGIN = 'groupLogin';
public const REFERER = 'referer';
public const REFERER_DOMAINS = 'refererDomains';
public const REFERRER = 'referer';
public const REFERRER_DOMAINS = 'refererDomains';
}
18 changes: 9 additions & 9 deletions typo3/sysext/felogin/Classes/Redirect/RedirectModeHandler.php
Expand Up @@ -141,7 +141,7 @@ public function redirectModeReferrer(string $redirectReferrer): string
$redirectUrl = '';
if ($redirectReferrer !== 'off') {
// Avoid forced logout, when trying to login immediately after a logout
$redirectUrl = preg_replace('/[&?]logintype=[a-z]+/', '', $this->getReferer());
$redirectUrl = preg_replace('/[&?]logintype=[a-z]+/', '', $this->getReferrer());
}

return $redirectUrl ?? '';
Expand All @@ -150,7 +150,7 @@ public function redirectModeReferrer(string $redirectReferrer): string
/**
* Handle redirect mode refererDomains
*/
public function redirectModeRefererDomains(string $domains, string $redirectReferrer): string
public function redirectModeReferrerDomains(string $domains, string $redirectReferrer): string
{
$redirectUrl = '';
if ($redirectReferrer !== '') {
Expand All @@ -163,7 +163,7 @@ public function redirectModeRefererDomains(string $domains, string $redirectRefe
// Thanks to plan2.net / Martin Kutschker for implementing this feature.
// also avoid redirect when logging in after changing password
if ($domains) {
$url = $this->getReferer();
$url = $this->getReferrer();
// Is referring url allowed to redirect?
$match = [];
if (preg_match('#^http://([[:alnum:]._-]+)/#', $url, $match)) {
Expand Down Expand Up @@ -222,15 +222,15 @@ protected function buildUriForPageUid(int $pageUid): string
return $this->uriBuilder->build();
}

protected function getReferer(): string
protected function getReferrer(): string
{
$referer = '';
$requestReferer = (string)$this->serverRequestHandler->getPropertyFromGetAndPost('referer');
$referrer = '';
$requestReferrer = (string)$this->serverRequestHandler->getPropertyFromGetAndPost('referer');

if ($this->redirectUrlValidator->isValid($requestReferer)) {
$referer = $requestReferer;
if ($this->redirectUrlValidator->isValid($requestReferrer)) {
$referrer = $requestReferrer;
}

return $referer;
return $referrer;
}
}
Expand Up @@ -62,7 +62,7 @@ public function getPropertyFromGetAndPost(string $propertyName)
/**
* Returns the HTTP_REFERER from server request parameters if set
*/
public function getHttpReferer(): string
public function getHttpReferrer(): string
{
return $this->request->getServerParams()['HTTP_REFERER'] ?? '';
}
Expand Down

0 comments on commit af48487

Please sign in to comment.