importUser
Details
This page shows version 4.x. The current version can be found here.
The importUser hook is triggered when a username cannot be found in the
database. It passes the username, the password and the table name as arguments
and expects a boolean return value.
Note
Using the importUser hook has been deprecated and will no longer work in Contao 5.0.
Parameters
string
$usernameThe unknown username.
string
$passwordThe password submitted in the login form.
string
$tableThe user model table, either
tl_member(for front end) ortl_user(for back end).
Return Values
A record must exist in the database for Contao to load a user. Return true if
you added the user to the respective table, or false if not.
Example
// src/EventListener/ImportUserListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('importUser')]
class ImportUserListener
{
public function __invoke(string $username, string $password, string $table): bool
{
if ('tl_member' === $table) {
// Import user from an LDAP server
if ($this->importUserFromLdap($username, $password)) {
return true;
}
}
return false;
}
}