importUser

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.

Using the importUser hook has been deprecated and will no longer work in Contao 5.0.

Parameters

  1. string $username

    The unknown username.

  2. string $password

    The password submitted in the login form.

  3. string $table

    The user model table, either tl_member (for front end) or tl_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;
    }
}

References