Creating user registration on a website often becomes necessary after the framework installation. Before beginning page development, you need to designate their visibility for different categories of users.
The HLOGIN library extends the capabilities of the HLEB2 framework by adding comprehensive user registration to the site, distinguished by easy configuration and quick setup, along with convenient and diverse functionality. It supports multilingualism and several design options. Optionally, you may include a feedback form, which accompanies registration and authentication. The automatically generated admin panel contains tools for user management and display settings. After integrating registration, you can immediately focus on creating content for the site.
Several basic design types are available. You can view a demonstration of the function and appearance of registration pop-up windows by clicking here.
Step 1: Install via Composer in a HLEB2-based project:
$composer require phphleb/hlogin
Step 2: Install the library in the project. You will be prompted to select a design type from several options:
$php console phphleb/hlogin add
$composer dump-autoload
Step 3: You must have an active database connection before performing this action. In the project settings '/config/database.php', you need to add a connection or ensure it exists, and also verify its name is in the 'base.db.type' parameter.
$php console hlogin/create-login-table
After this, use the console command to create a user with administrator rights (you will be prompted to provide E-mail and password):
$php console hlogin/create-admin
If you cannot execute the console command, create the tables using the appropriate SQL query from the file /vendor/phphleb/hlogin/planB.sql. Then register an administrator and set their 'regtype' to 11.
Step 4: Now you can proceed to the main placeholder page of the website if it is the default framework page without changes and check that the authorization panels are available. If the library is installed in a HLEB2-based project not from the start and the placeholder has been removed, check the login on the page '/en/login/action/enter/' of the site (using the administrator data from the previous step).
Step 5: Installation of registration on specific pages through routing. To do this, set the following conditions in the routing files (project folder /routes/):
It is sufficient to distribute the site's routes according to these conditions (groups) so that user authorization rules are applied to them.
Note that pages not included in any of these groups with conditions are outside the registration rules, and this library is not connected to them.
Step 6: Configuration. After authorization, the administrator profile (/en/login/profile/) displays a button to access the admin panel. In it, you can configure registration panels and other parameters.
If you need to display data depending on the user registration type:
You can also add the class Phphleb\Hlogin\Container\Auth to the container and retrieve this data from it.
By default, the language used for panels is extracted from the url parameter (following the domain) or the lang attribute within the '<html lang="en">' tag. To forcefully set the design and/or language of the panels on a page:
Standard authorization buttons can be replaced with any others by disabling the default ones in the admin panel beforehand. Custom buttons can be assigned one of the following actions (for JavaScript):
Or, using attributes:
As can be understood, registration cannot be available for users with JavaScript disabled in the browser. There are hardly any left now.
If there is a need to direct a user immediately to a login or registration page, several necessary pages are automatically created:
Registration Page
/ru/login/action/registration/
Login Page
/ru/login/action/enter/
Profile Page
/ru/login/profile/
Contact Page
/ru/login/action/contact/
Admin Panel Settings Page
/ru/adminzone/registration/settings/
When validating values on the backend side submitted from registration forms, you can additionally process them with your own PHP script, if available. This way, for example, you can add a custom field to the form and check it yourself. The queries are divided into separate classes, which can be found in the folder /vendor/phphleb/hlogin/Optional/Inserted/. They can only be used after copying into the folder /app/Bootstrap/Auth/Handlers/.
Custom design is available by choosing the "blank" type in the admin panel. After this, you can copy and modify the CSS file from any existing design, connecting it to the site yourself. You can also make edits based on the design type.
By default, several switchable languages are used for registration and authorization. However, all labels can be customized to your own settings. It is important to check that lengthy words fit within the panel interface.
For backend localization, copy the necessary language files from /vendor/phphleb/hlogin/App/BackendTranslation/ to the folder /app/Bootstrap/Auth/Resources/php/ and make changes in the latter.
For frontend localization, copy the necessary language files (starting with 'hloginlang') from /vendor/phphleb/library/hlogin/web/js/ to the folder /app/Bootstrap/Auth/Resources/js/ and make changes.
You can add an additional language(s) by creating appropriately named files for backend and frontend localizations and adding it to the list of allowed languages in the 'allowed.languages' setting in the /config/main.php file (this file may be duplicated in Modules).
When creating your additional pages in the admin panel, surround their routes with access restrictions as shown below:
The creation of pages in the admin section is described in the relevant section of this documentation.
Sending emails with notifications and access recovery is done using the github.com/phphleb/muller library. In the admin panel, the sender's E-mail should be specified, for which sending from the server must be allowed. For most hostings, it is enough to create such a mailbox. The available sending E-mail is located in php.ini (sendmail_path = ... -f'email@example.com').
By default, emails are additionally logged into the folder '/storage/logs/' with the name ending in 'mail.log'. This logging can be disabled in the settings of the admin panel.
The default library used for sending emails has limited capabilities and should be replaced with a suitable mail server or another equivalent as the project evolves.
Create the class App\Bootstrap\Auth\MailServer at the path /app/Bootstrap/Auth/MailServer.php, which implements the interface Phphleb\Hlogin\App\Mail\MailInterface. Once the file is created, emails will be sent using this class, so you should first implement your own sending logic for the chosen mail server.
To update, execute the console commands:
$composer update phphleb/hlogin
$php console phphleb/hlogin add
$composer dump-autoload
During the installation process, choose the current design that is used by default.
HLOGIN library on GitHub: github.com/phphleb/hlogin
Demo registration page: auth2.phphleb.ru