Additionally/Extensions/HLOGIN - registration module

HLOGIN - Registration Module

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.


#Installation

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


#Connection

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/):

use App\Middlewares\Hlogin\Registrar;
use 
Phphleb\Hlogin\App\RegType;

Route::toGroup()->middleware(Registrar::class, data: [RegType::UNDEFINED_USER'>=']);
// Routes in this group will be available to all unregistered and registered users
// except those that were marked deleted and banned.
Route::endGroup();

Route::toGroup()->middleware(Registrar::class, data: [RegType::PRIMARY_USER'>=']);
// Routes in this group will be available to those who pre-registered (but didn't confirm E-mail),
// as well as to all registered users (including administrators).
Route::endGroup();

Route::toGroup()->middleware(Registrar::class, data: [RegType::REGISTERED_USER'>=']);
// Routes in this group will be available to all users who have completed full registration
// (confirmed by E-mail including administrators).
Route::endGroup();

Route::toGroup()->middleware(Registrar::class, data: [RegType::REGISTERED_COMMANDANT'>=']);
// Routes in this group will be available only to administrators.
Route::endGroup();

Route::toGroup()->middleware(Registrar::class, data: [RegType::PRIMARY_USER'>='Registrar::NO_PANEL]);
// Routes with check registration without displaying standard panels and buttons.
Route::endGroup();

Route::toGroup()->middleware(Registrar::class, data: [RegType::PRIMARY_USER'>='Registrar::NO_BUTTON]);
// Routes with check registration without displaying standard buttons.
Route::endGroup();

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.


#Additional Information

If you need to display data depending on the user registration type:

use Phphleb\Hlogin\App\AuthUser;

$user AuthUser::current();
if (
$user) {
    
// Status for the confirmed user.
    
$confirm $user->isConfirm();

    
// Obtaining the user's E-mail.
    
$email $user->getEmail();

    
// Result of the administrator check.
    
$isAdmin $user->isSuperAdmin();
    
// ... //
} else {
    
// The current user is not authorized.
}

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:

<?php

use Phphleb\Hlogin\App\PanelData;

// Force setting the panel design type on the page.
PanelData::setLocalDesign('base');

// Forced installation of the panel language on the page.
PanelData::setLocalLang('en');

#Panel Management

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):

<script>
    
// Setting the design for the page via JS.
    // For example, this way you can set the `special` type for visually
    // impaired users without refreshing the page in the browser.
    
hloginSetDesignToPopups('special');

    
// Returns the design type to its original state.
    
hloginRevertDesignToPopups();

    
// Close all registration popups.
    
hloginCloseAllPopups();

    
// Open a specific window, in this case user registration.
    
hloginVariableOpenPopup('UserRegister');
    
// Or 'UserEnter', 'UserProfile', 'ContactMessage'

    // Displays an arbitrary custom message in the window (current design).
    
hloginOpenMessage('Title''Message <b>text</b>');

    
// If this function exists, it will be called every time a popup is opened, passing the popup type.
    
function hloginPopupVariableFunction(popupType) {
        
// Custom code. (popupType = 'UserRegister' / 'UserEnter' / 'UserPassword' / 'ContactMessage')
    
}
</
script>

Or, using attributes:

<div>
    <
button class="hlogin-init-action" data-type="UserEnter">Enter</button>
    <
button class="hlogin-init-action" data-type="UserProfile">Profile</button>
    <
button class="hlogin-init-action" data-type="UserRegister">Register</button>
    <
button class="hlogin-init-action" data-type="ContactMessage">Contact Message</button>
    <
button class="hlogin-init-action" data-type="ChangeDesign" data-value="dark">Change Design (dark)</button>
    <
button class="hlogin-init-action" data-type="DefaultDesign">Default Design</button>
    <
button class="hlogin-init-action" data-type="ChangeLang" data-value="de">Change Lang (de)</button>
    <
button class="hlogin-init-action" data-type="DefaultLang">Default Lang</button>
    <
button class="hlogin-init-action" data-type="CustomMessage" data-value="Test message" data-title="Title message">
        
Custom Message
    
</button>
</
div>

As can be understood, registration cannot be available for users with JavaScript disabled in the browser. There are hardly any left now.


#Specific Pages

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/


#Additional Data Processing

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/.


#Design

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.

.hlogin-over-panel[data-design='base'input {
    
/* CSS rules for the "input" block of the "base" design */
}
.
hlogin-over-panel[data-design='dark'input {
    
/* CSS rules for the "input" block of the "dark" design */
}

#Localization

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).


#Adminzone

When creating your additional pages in the admin panel, surround their routes with access restrictions as shown below:

use App\Middlewares\Hlogin\Registrar;
use 
Phphleb\Hlogin\App\RegType;

Route::toGroup()->middleware(Registrar::class, data: [RegType::REGISTERED_COMMANDANT'=']);
    
// Routes in this group will only be available to administrators.
Route::endGroup();

The creation of pages in the admin section is described in the relevant section of this documentation.


#Sending Emails

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.


#Mail Server

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.


#Library Update

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.


#Links

HLOGIN library on GitHub: github.com/phphleb/hlogin

Demo registration page: auth2.phphleb.ru

Page translated: chatgpt 4-o
Back to top