Jump to main content Jump to doc navigation

What is a User?

A User is simply a representation of a login in MODX Revolution.

Users can also be assigned to User Groups, which can have ACLs attached to them to provide Access Controls.

User Settings

User Settings in MODX Revolution will automatically override any System or Context settings with the same key for that user. They can also be completely unique settings as well. The order of inheritance for Settings is:

System Settings -> Context Settings -> User Settings

To edit the user settings, navigate to Security -> Manage Users -> Update User (right-click) -> Settings (tab)

You can change user-specific settings only after you've created the user. The "Settings" tab is not visible when you first create the user.

Users in the Front-End

When a user is logged into the frontend of your site, their username and ID can be accessed by the following Properties:

[[+modx.user.id]] - Prints the ID
[[+modx.user.username]] - Prints the username

If a user is not logged in, ID will be blank, and Username will be "(anonymous)".

As of MODX 2.4.0, the default Username can be set in the Systems Settings with the default_username setting.

Remember Keep in mind that confusing caveat: just because you have logged into the manager does not mean that you are logged into the web front-end. The user-specific settings and the getOption API method obeys this same rule, so if you're not logged in, then the System Settings -> Context Settings -> User Settings cannot fully apply.

User Field

Users contain the following fields:

Name Description
id The ID of the user.
username The username of the user.
password The user's encrypted password.
active Either 1 or 0. If not active, the user will not be able to log in.
remote_key A remote user Key used by remote authentication apps.
remote_data A JSON array of data used by remote authentication apps.

Users also have a Profile attached to them. It contains the following fields:

Name Description
internalKey The ID of the user.
fullname The full name of the user.
email The email of the user.
phone The phone number.
mobilephone The cellphone number.
fax The fax number.
blocked Either 1 or 0. If blocked is set to true, the user will not be able to log in.
blockeduntil A timestamp that, when set, will prevent the user from logging in until this date.
blockedafter A timestamp that, when set, will prevent the user from logging in after this date.
logincount The number of logins for this user.
lastlogin The last time the user logged in.
thislogin The time the user logged in in their current session.
failedlogincount The number of times the user has failed to log in since last logging in.
sessionid The User's session ID that maps to the session table.
dob The date of birth.
gender 0 for neither, 1 for male and 2 for female.
address The physical address.
country The country of the user.
city The city of the user.
zip The zip or postal code for the user.
state The physical state or province of the user.
photo An optional field for a photo. Not used in the UI.
comment An optional comment field for comments on the User.
website The website of the user.
extended A JSON array that can be used to store extra fields for the User.

Grabbing the User via the API

The current user can be retrieved in the API via the $modx->user reference. For example, this snippet outputs the username of the user:

return $modx->user->get('username');

Note that to grab Profile fields, you'll need to first get the modUserProfile object via the Profile alias. For example, this snippet grabs the email of the user and returns it:

$profile = $modx->user->getOne('Profile');
return $profile ? $profile->get('email') : '';

If the User is not logged in, $modx->user will still be available as an object, but will return 0 as the ID and (Anonymous) as the username.

Using Extended Fields

Values in the extended field return as an array. They can be manipulated like so:

/* get the extended field named "color": */
$fields = $profile->get('extended');
$color = $fields['color'];
/* set the color field to red */
$fields = $profile->get('extended');
$fields['color'] = 'red';
$profile->set('extended',$fields);
$profile->save();

See Also

  1. Users
  2. User Groups
  3. Resource Groups
  4. Roles
  5. Policies
    1. Permissions
      1. Permissions - Administrator Policy
      2. Permissions - Resource Policy
    2. ACLs
    3. PolicyTemplates
  6. Security Tutorials
    1. Giving a User Manager Access
    2. Making Member-Only Pages
    3. Creating a Second Super Admin User
    4. Restricting an Element from Users
    5. More on the Anonymous User Group
  7. Hardening MODX Revolution
  8. Troubleshooting Security
    1. Resetting a User Password Manually
  9. Extending modUser

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
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Digital Penguin
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • Following Sea
  • Anton Tarasov
  • eydolan
  • Raffy
  • Lefthandmedia
  • Murray Wood
  • Snow Creative
  • Nick Clark
  • Helen
  • JT Skaggs
  • krisznet
  • YJ
  • Yanni
  • Richard

Budget

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

Learn more