The Frontend Login for Website Users (felogin) extension is a general
purpose extension for frontend logins. In addition to the actual login
box, it includes several methods for redirecting after login/logout
and includes forgot password functionality.
Screenshots
General Settings
The plugin's general settings
Redirect Configuration
Configuration of the redirection options
Hint
Be sure that in the overall Access tab under User Group Access rights the content
element and even the page itself is not set to Hide at login, otherwise the redirect
to the given page will not work.
Messages Tab
Configuration of the various messages (screenshot shows not all options)
Installation
This extension is part of the TYPO3 Core, but not installed by default.
The felogin extension requires no special configuration. All options
are available in the plugin's FlexForm as shown in the Screenshots.
Using the plugin
The felogin plugin is available through the Content Wizard as Login Form:
The Login Form plugin in the content element wizard
Choosing a user storage page for website users
In order for Website Users to be able to log in, the "Frontend login" plugin
must know where the records are stored. There are two possibilities
for setting this storage folder:
The site's integrator may have set a default value for the
User Storage Page or using the
Settings editor. If you use the default
folder to store frontend users in your project there is nothing to do here.
A very common issue is, that the felogin plugin is set to Access:
Hide at login. After the core has processed the login request, the
page will be rendered without the felogin plugin. If there are redirect options
active they will not be executed, simply because the felogin plugin is
hidden.
Of course setting the felogin plugin to Hide at login and having
redirect options together doesn't really makes sense.
Login mechanism
In order to properly use the felogin plugin and its advanced
capabilities (such as redirect options) it is important to understand
the mechanism of frontend user login in TYPO3 CMS.
If there is no frontend user logged in, the login form will be
shown.
If there is a logged in frontend user, the logout form is shown.
If the forgot password link was used, the form to reset a password
based on username or email address will be shown.
If the password reset link was followed from an email, the form to
change the password will be shown.
The login process
After the form is submitted the TYPO3 CMS authentication services will
validate the login credentials. After this process felogin will handle
the rest. This means that the felogin plugin must be visible for the
user who has logged in.
Felogin will then check any redirect options and generate the
appropriate content.
Caution
Do not use the login status of a frontend user as authorization,
but always rely on user groups.
Only use different storage folders for frontend users if this is really
necessary due to organizational reasons.
Redirect Modes
The following redirect options are supported.
Defined by Usergroup Record
Within a Website usergroup record, you can specify a page where
usergroup members will be redirected after login.
Defined by User Record
This is identical to the redirection option for "defined by Usergroup
Record" but applies to a single website user instead of an entire user
group.
After Login (TS or Flexform)
This redirect page is set either in TypoScript
(
plugin.tx_felogin_login.settings.redirectPageLogin) or in the
FlexForm of the felogin plugin.
After Logout (TS or Flexform)
Defines the redirect page after a user has logged out. Again, it can
be set in TypoScript or in the felogin plugin's FlexForm.
After Login Error (TS of Flexform)
Defines the redirect page after a login error occurs. Can be set in
TypoScript or in the felogin plugin's FlexForm.
Defined by GET/POST Parameters
Redirect the visitor based on the GET/POST parameters redirect_url.
If the TypoScript configuration
config.typolinkLinkAccessRestrictedPages is set, the GET/POST
parameter redirect_url is used.
The referrer page is used for the redirect. This basically means that
the user is sent back to the page he originally came from.
Defined by Domain entries
Same as Defined by Referrer, except that only the domains listed in
plugin.tx_felogin_login.domains are allowed. If someone is sent to the
login page coming from a domain which is not listed, the redirect will
not happen.
By using the option Use First Supported Mode from Selection you can
define several fallback methods.
Note
It is only possible to use domains, which are known to TYPO3. This means,
that domains must be configured as base in site settings for websites
in the current TYPO3 instance.
Configuration
All configuration options are available in the FlexForm, as settings of the
site set and as TypoScript setup.
The settings are interpreted in the following order, the last one takes
precedence:
You can find the available site settings in module
Site Management > Settings
You can change individual settings here. If the site settings are writable
you can hit the Save button and the settings will be written
directly to the site settings.
If the settings are not writable you can click the YAML export
button to export the settings. These can then be added by a developer with
sufficient rights.
If set, also subfolder at configured recursive levels of the User Storage Page will be used
felogin.showForgotPassword
felogin.showForgotPassword
Type
bool
Default
false
Label
Display Password Recovery Link
Category
Frontend Login
If set, the section in the template to display the link to the forgot password dialog is visible.
felogin.showPermaLogin
felogin.showPermaLogin
Type
bool
Default
false
Label
Display Remember Login Option
Category
Frontend Login
If set, the section in the template to display the option to remember the login (with a cookie) is visible.
felogin.showLogoutFormAfterLogin
felogin.showLogoutFormAfterLogin
Type
bool
Default
false
Label
Disable redirect after successful login, but display logout-form
Category
Frontend Login
If set, the logout form will be displayed immediately after successful login.
felogin.emailFrom
felogin.emailFrom
Type
string
Label
Email Sender Address
Category
Frontend Login
email address used as sender of the change password emails
felogin.emailFromName
felogin.emailFromName
Type
string
Label
Email Sender Name
Category
Frontend Login
Name used as sender of the change password emails
felogin.replyToEmail
felogin.replyToEmail
Type
string
Label
Reply-to email Address
Category
Frontend Login
Reply-to address used in the change password emails
felogin.dateFormat
felogin.dateFormat
Type
string
Default
"Y-m-d H:i"
Label
Date format
Category
Frontend Login
Format for the link is valid until message (forgot password email)
felogin.email.layoutRootPath
felogin.email.layoutRootPath
Type
string
Label
Layout root path
Category
Frontend Login
Path to layout directory used for emails
felogin.email.templateRootPath
felogin.email.templateRootPath
Type
string
Default
"EXT:felogin/Resources/Private/Email/Templates/"
Label
Template root path
Category
Frontend Login
Path to template directory used for emails
felogin.email.partialRootPath
felogin.email.partialRootPath
Type
string
Label
Partial root path
Category
Frontend Login
Path to partial directory used for emails
felogin.email.templateName
felogin.email.templateName
Type
string
Default
"PasswordRecovery"
Label
Template name for emails.
Category
Frontend Login
HTML emails get the .html file extension, plaintext emails get the .txt file extension.
felogin.redirectMode
felogin.redirectMode
Type
string
Label
Redirect Mode
Category
Frontend Login
Comma separated list of redirect modes.\
Possible values: groupLogin, userLogin, login, getpost, referer, refererDomains, loginError, logout.\
Warning: redirects only work if neither the plugin nor the page it is displayed on are set to `hide at login`.
felogin.redirectFirstMethod
felogin.redirectFirstMethod
Type
bool
Default
false
Label
Use First Supported Mode from Selection
Category
Frontend Login
If set the first method from redirectMode which is possible will be used
felogin.redirectPageLogin
felogin.redirectPageLogin
Type
int
Default
0
Label
After Successful Login Redirect to Page
Category
Frontend Login
Page id to redirect to after Login
felogin.redirectPageLoginError
felogin.redirectPageLoginError
Type
int
Default
0
Label
After Failed Login Redirect to Page
Category
Frontend Login
Page id to redirect to after Login Error
felogin.redirectPageLogout
felogin.redirectPageLogout
Type
int
Default
0
Label
After Logout Redirect to Page
Category
Frontend Login
Page id to redirect to after Logout
felogin.redirectDisable
felogin.redirectDisable
Type
bool
Default
false
Label
Disable Redirect
Category
Frontend Login
If set redirecting is disabled
felogin.forgotLinkHashValidTime
felogin.forgotLinkHashValidTime
Type
int
Default
12
Label
Time in hours how long the link for forgot password is valid
Category
Frontend Login
How many hours the link for forgot password is valid
felogin.domains
felogin.domains
Type
string
Label
Allowed Referrer-Redirect-Domains
Category
Frontend Login
Comma separated list of domains which are allowed for the referrer redirect mode
Expose the information on whether or not the account for which a new password was requested exists. By default, that information is not disclosed for privacy reasons.
felogin.view.templateRootPath
felogin.view.templateRootPath
Type
string
Label
Path to template root (frontend)
Category
Frontend Login
Path to template directory used for the plugin in the frontend. Extends the default template location.
felogin.view.partialRootPath
felogin.view.partialRootPath
Type
string
Label
Path to template partials (frontend)
Category
Frontend Login
Path to partial directory for the plugin in the frontend. Extends the default partial location.
felogin.view.layoutRootPath
felogin.view.layoutRootPath
Type
string
Label
Path to template layouts (frontend)
Category
Frontend Login
Path to layout directory used for the plugin in the frontend. Can be used to introduce a custom layout.
Migration from TypoScript setup settings to site settings
The site settings are named like the TypoScript constants used before
site sets. However the TypoScript constants are not always named the same
like the TypoScript setup settings.
To add the settings to your site settings, edit the file
config/sites/<my_site>/settings.yaml in Composer-based installations
or typo3conf/sites/<my_site>/settings.yaml in legacy installations. If
the file does not exist yet, create one. Use the setting
felogin.pid to set the storage folder. If
its subfolders should also be included, additionally use setting
felogin.recursive.
Comma separated list of redirect modes. Possible values:
groupLogin, userLogin, login, getpost, referer,
refererDomains, loginError, logout
See section on redirect modes for details.
If set and the user account cannot be found in the forgot password
dialogue, an error message will be shown that the account could not be
found.
.. warning::
Enabling this will disclose information about whether an
email address is actually used for a frontend user account! Visitors
can find out if a user is known as frontend user.
Example: Set the default storage page via TypoScript setup
In order to set the default storage page to a more dynamic value, use
the TypoScript setup. Use the TypoScript provider
or other means of ref:setting the TypoScript setup <t3tsref:using-and-setting>.
Example: Override the default storage page in the plugin's FlexForm
If you set any FlexForm setting within the content element representing the
plugin to a non-empty value it will override any other setting not matter if it
is made via site settings, TypoScript constant ot TypoScript setup. Empty values
take no effect if a default was set by other means.
In the backend module Web > Page edit the content element containing
the login form. Go to tab Plugin and sub tab General.
You should see a form similar to the following:
Settings in the tab General of the plugin tab
Choose the desired page or pages in the field with label
User Storage Page (key settings.pages).
Tip
It is sometimes hard to determine, which label in the FlexForm corresponds
to which key in the FlexForm reference.
Turn on the backend debug mode
to get a visual hint in the backend for the keys of the FlexForm field.
The corresponding FlexForm field settings.pages
in backend debug mode.
GET and POST parameters
The extension uses several GET and POST parameters to define or override
redirect settings.
noredirect
Parameter
noredirect
Evaluation
GET and POST
Data type
string
Description
If set to
1, no redirect will be processed after a successful
login.
PSR-14 events
The following PSR-14 events are available to extend the extension:
AfterUserLoggedInEvent
Trigger any kind of action when a frontend user has been successfully logged in.
More details
BeforeRedirectEvent
Notification before a redirect is made.
More details
LoginConfirmedEvent
A notification when a log in has successfully arrived at the plugin, via the
view and the controller, multiple information can be overridden in event
listeners. More details
LoginErrorOccurredEvent
A notification if something went wrong while trying to log in a user.
More details
LogoutConfirmedEvent
A notification when a log out has successfully arrived at the plugin, via
the view and the controller, multiple information can be overridden in
event listeners. More details
ModifyLoginFormViewEvent
Allows to inject custom variables into the login form.
More details
PasswordChangeEvent
Event that contains information about the password which was set,
and is about to be stored in the database.
More details
SendRecoveryEmailEvent
Event that contains the email to be sent to the user when they request a
new password. More details
Examples
In this section some common situations are described:
Send visitors to login page and redirect to original page
A common situation is that visitors who go to a page with access
restrictions should go to a login page first and after logging in
should be send back to the page they originally requested.
Assume we have a login page with id 2.
Using TypoScript we can still display links to access restricted pages
and send visitors to the login page:
(This option can also be set in the flexform configuration of the
felogin content element)
If visitors will directly enter the URL of an access restricted page
they will be sent to the first page in the rootline to which they have
access. Sending those direct visits to a login page is not a job of
the felogin plugin, but requires a custom page-not-found handler. In this sense,
we refer to Custom error handler implementation for 403 redirects.
Login link visible when not logged in and logout link visible when logged in
Again TypoScript will help you out. The page with the login form has
id=2:
Of course there can be solutions with
HMENU items, etc.
Custom error handler implementation for 403 redirects
This section explains how to utilize a custom error handler
to catch 403 restricted page errors and allow to forward
to a login form, and then redirect back to the originating
page after successful login.
You need the following site settings in the error handling
Error Handling tab of Site Configuration module
There you add the custom 403 error handler and configure
the error handler, you create in the following steps.
Look up the page ID where a login form (like with EXT:felogin) is placed
This page ID is needed in the following step, so that the error
handler will know, where to forward an unauthenticated user to, so
that a login can be performed.
Ideally, this should be done by configuring a page ID via the
site settings, and referring back to a named ID. See
PHP API: accessing site configuration
for more information. For reduced complexity, this example uses
a hard-coded page ID.
Create a new error handler RedirectLoginErrorHandler.php
Create a PHP error handler class like the following in a custom
extension, like your own sitepackage:
<?phpdeclare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/namespaceMyVendor\MySitePackage\Error\PageErrorHandler;
usePsr\Http\Message\ResponseInterface;
usePsr\Http\Message\ServerRequestInterface;
useTYPO3\CMS\Core\Context\Context;
useTYPO3\CMS\Core\Controller\ErrorPageController;
useTYPO3\CMS\Core\Error\PageErrorHandler\PageErrorHandlerInterface;
useTYPO3\CMS\Core\Http\HtmlResponse;
useTYPO3\CMS\Core\Http\RedirectResponse;
useTYPO3\CMS\Core\LinkHandling\LinkService;
useTYPO3\CMS\Core\Site\Entity\Site;
useTYPO3\CMS\Core\Utility\GeneralUtility;
useTYPO3\CMS\Frontend\Page\PageAccessFailureReasons;
/**
* An error handler that redirects to a configured page, where the login
* process is handled. Passes a configurable URL parameter (`return_url` or
* `redirect_url`) to the target page.
*/finalclassRedirectLoginErrorHandlerimplementsPageErrorHandlerInterface{
privateconst PAGE_ID_LOGIN_FORM = 656;
private readonly int $loginRedirectPid;
private readonly string $loginRedirectParameter;
private readonly Context $context;
private readonly LinkService $linkService;
private readonly ErrorPageController $errorPageController;
publicfunction__construct(private readonly int $statusCode){
$configuration = [
// TODO: Replace with $siteSettings[...] or something else'loginRedirectTarget' => 't3://page?uid=' . self::PAGE_ID_LOGIN_FORM,
'loginRedirectParameter' => 'return_url',
];
$this->context = GeneralUtility::makeInstance(Context::class);
$this->linkService = GeneralUtility::makeInstance(LinkService::class);
$this->errorPageController = GeneralUtility::makeInstance(ErrorPageController::class);
$urlParams = $this->linkService->resolve($configuration['loginRedirectTarget']);
$this->loginRedirectPid = (int)($urlParams['pageuid'] ?? 0);
$this->loginRedirectParameter = $configuration['loginRedirectParameter'];
}
publicfunctionhandlePageError(
ServerRequestInterface $request,
string $message,
array $reasons = []
): ResponseInterface{
$this->checkHandlerConfiguration();
if ($this->shouldHandleRequest($reasons)) {
return$this->handleLoginRedirect($request);
}
// Show general error message with a 403 HTTP status codereturn$this->getGenericAccessDeniedResponse($message);
}
privatefunctiongetGenericAccessDeniedResponse(string $reason): ResponseInterface{
$reason = $reason ? ' Reason: ' . $reason : '';
$content = $this->errorPageController->errorAction(
'Page Not Found',
sprintf('The page did not exist or was inaccessible.%s', $reason),
0,
$this->statusCode,
);
returnnew HtmlResponse($content, $this->statusCode);
}
privatefunctionhandleLoginRedirect(ServerRequestInterface $request): ResponseInterface{
if ($this->isLoggedIn()) {
return$this->getGenericAccessDeniedResponse(
'The requested page was not accessible with the provided credentials'
);
}
/** @var Site $site */
$site = $request->getAttribute('site');
$language = $request->getAttribute('language');
$loginUrl = $site->getRouter()->generateUri(
$this->loginRedirectPid,
[
'_language' => $language,
$this->loginRedirectParameter => (string)$request->getUri(),
]
);
returnnew RedirectResponse($loginUrl);
}
privatefunctionshouldHandleRequest(array $reasons): bool{
if (!isset($reasons['code'])) {
returnfalse;
}
$accessDeniedReasons = [
PageAccessFailureReasons::ACCESS_DENIED_PAGE_NOT_RESOLVED,
PageAccessFailureReasons::ACCESS_DENIED_SUBSECTION_NOT_RESOLVED,
];
$isAccessDenied = in_array($reasons['code'], $accessDeniedReasons, true);
return $isAccessDenied || $this->isSimulatedBackendGroup();
}
privatefunctionisLoggedIn(): bool{
if ($this->context->getPropertyFromAspect('frontend.user', 'isLoggedIn')) {
returntrue;
}
return$this->isSimulatedBackendGroup();
}
protectedfunctionisSimulatedBackendGroup(): bool{
if (!$this->context->getPropertyFromAspect('backend.user', 'isLoggedIn')) {
returnfalse;
}
// look for special "any group"
$groups = $this->context->getPropertyFromAspect('frontend.user', 'groupIds');
return $groups[1] === -2;
}
privatefunctioncheckHandlerConfiguration(): void{
if ($this->loginRedirectPid === 0) {
thrownew \RuntimeException('No loginRedirectTarget configured for LoginRedirect errorhandler', 1700813537);
}
if ($this->statusCode !== 403) {
thrownew \RuntimeException(sprintf('Invalid HTTP status code %d for LoginRedirect errorhandler', $this->statusCode), 1700813545);
}
}
}
Copied!
Adapt the constant
PAGE_ID_LOGIN_FORM to match the
page ID from the previous step.
Since there is no proper way how to do it otherwise, we put in the page ID
of the login form hard-coded into the file RedirectLoginErrorHandler.php
and define a constant
PAGE_ID_LOGIN_FORM for it. In the example
above, this is set to 656.
Hint
This example code uses PHP 8.1 syntax. Depending on the PHP version you use in
your project, you may need to adapt language features like readonly to match your
used PHP version.
In your EXT:felogin plugin, make sure you selected "Defined by GET/POST
Parameters" as first redirect mode
Plugin > Redirects tab of Login Form content element
You need to configure the login form that receives your redirect in a
way, that allows to evaluate submitted URL parameters. In EXT:felogin,
this is achieved via this Redirect Mode (which can also be set
through TypoScript configuration, see redirectMode.
Your login form will probably also need to define a specific target page
for normal logins (independent from the error handler redirect), so you
should also add a redirectMode like login to your list, and set
a target page in redirectPageLogin.
Testing the custom error handler
Clear the caches, for example via the backend module
Admin Tools > Maintenance.
Then open any access-restricted page
in an incognito browser window to be sure that
you are not logged in yet. Here we will use the example
URL https://example.org/restricted/page.
When everything is configured correctly and if you are not logged in
yet, then you should be redirected to your login page like
https://example.org/login (example page ID 656).
After entering proper frontend user credentials, you should be redirected
back to https://example.org/restricted/page, the page where you
wanted to get to initially.
Hint
When you have multiple site configurations, be sure to access
the correct one. This means where both the login form is located,
and the custom error handler is configured for.
Hint
Do not copy the generated link from the address URL after you clicked
View webpage from the backend, and then just paste it into
the URL bar of the incognito window. The reason is that when
being logged in to the backend, a possibly simulated frontend user
login can affect your tests.
Hint
Do not get confused when the URL
https://example.org/restricted/page will be forwarded to a URL
like
when you want to access the restricted page in the first place.
These are the getpost redirect parameters that are evaluated by
EXT:felogin. Now type in the user credentials of the already created
frontend user and you should get redirected to the desired
page https://example.org/restricted/page.
If there is more than one felogin plugin on a page the password
recovery option can cause problems. This is a general problem with
plugins, but in this case the cause is a small hash in the forgot
password form which is stored in the frontend user session data.
With multiple instances on a page only one of the hashes is
stored and only one of the forgot password forms will work. Make sure
there is only one felogin plugin on the page where the password
recovery form is displayed.
If usergroup access rights of the plugin are defined to
Hide at login, all felogin code (e.g. redirects, PSR-14 events)
will not be executed after a user successfully logged in.
Sitemap
Reference to the headline
Copy and freely share the link
This link target has no permanent anchor assigned.The link below can be used, but is prone to change if the page gets moved.