Jump to main content Jump to doc navigation

Event: OnBeforeManagerLogin

Fires before the login process is started for a user when logging in to the manager context. This event can be used to DENY the login process. By default it is denying the logging in.

To allow logging in when using this event please use:

$modx->event->output(true);
// before Revo 2.3.0 you should use instead:
$modx->event->_output = true;
  • Service: 2 - Manager Access Events
  • Group: None

Event Parameters

Name Description
username The provided username.
password The provided password.
attributes An array of:
- & rememberme - Boolean set if user wants password to be remembered. Passed by reference
- & lifetime - The session cookie lifetime for this login. Passed by reference
- & loginContext - The context key this login is occurring in. Passed by reference
- & addContexts - Additional contexts in which the login is also occuring in. Passed by reference

Event Login Workflow

  1. OnBeforeWebLogin || OnBeforeManagerLogin - Inside this event the developer can check for erroneous parameters which will disallow further logging in process. If plugins executed by this event return something except true, the logging in will be aborted with the specified error.
  2. OnUserNotFound - This event is executed only if the provided username is not found inside MODX database. The developer can provide it's own modUser object in the event output to continue the login process.
  3. OnWebAuthentication || OnManagerAuthentication - Inside this event the developer can check for parameters which will override the default checking by password and allow further logging in process. If one of the plugins executed from this event return true, the user is considered verified and logged in.
  4. OnWebLogin || OnManagerLogin - This event is fired after the logging in process has finished and the user is considered logged in. It doesn't change the logging in process behaviour.

Examples of

Such a plugin will display in the "Error log" who, with what password, and where he tried to enter:

<?php
$eventName = $modx->event->name;
switch($eventName) {
    case 'OnBeforeManagerLogin':
        $modx->log(modX::LOG_LEVEL_ERROR, 'A user with a name tried to log in '.$username.' and password '.$password.print_r($attributes));
        break;
}

This will make the user inactive when he tries to log in:

<?php
$eventName = $modx->event->name;
switch($eventName) {
    case 'OnBeforeManagerLogin':
        if ($username == 'manager'){
            $user = $modx->getObject('modUser', array('username' => $username));
            $user->set('active', '0');
            $user->save();
        }
        break;
}

See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • eydolan
  • Following Sea
  • Lefthandmedia
  • Murray Wood
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

$311 per month—let's make that $500!

Learn more