Jump to main content Jump to doc navigation

Event: OnBeforeManagerLogin

Fires before a user logs in to the Manager Context. By default the login continues. To deny it, the Plugin must set a non-empty event output other than true, usually an error message:

// block the login and pass the reason
$modx->event->output('Login is not allowed.');

The login aborts and shows that message. If no Plugin sets the output, or the output is true, the login proceeds. A value returned from Plugin code does not block the login; it goes to the error log.

  • Service: 2 - Manager Access Events
  • Group: Security

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 occurring in. Passed by reference

Event Login Workflow

  1. OnBeforeWebLogin || OnBeforeManagerLogin — block the login here (see above).
  2. OnUserNotFound — runs only if the username is not found in the MODX database. Provide your own modUser in the event output to continue the login.
  3. OnWebAuthentication || OnManagerAuthentication — override the default password check here. A Plugin returning true marks the user as verified and logged in.
  4. OnWebLogin || OnManagerLogin — fires after the login finishes; it does not change login behavior.

Examples

<?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, true));
        break;
}
<?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
  • CrewMark
  • Fabian Christen
  • Sepia River Studios
  • Dannevang Digital
  • Alex
  • A. Moreno
  • Chris Fickling
  • Stéphane Jäggi
  • Murray Wood
  • Anton Tarasov
  • JT Skaggs
  • deJaya
  • Lefthandmedia
  • eydolan
  • Following Sea
  • Guido Gallenkamp
  • YJ
  • Raffy
  • Snow Creative
  • Nick Clark
  • Guest
  • Helen
  • krisznet
  • Yanni
  • Richard

Budget

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

Learn more