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 Fields

Users contain the following fields:

Name Description
id
username
password
active
remote_key
remote_data

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

Name Description
internalKey
fullname
email
phone
mobilephone
fax
blocked
blockeduntil
blockedafter
logincount
lastlogin
thislogin
failedlogincount
sessionid
dob
gender
address
country
city
zip
state
photo
comment
website
extended

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
  6. Permissions
    1. Permissions - Administrator Policy
    2. Permissions - Resource Policy
  7. ACLs
  8. PolicyTemplates
  9. Security Tutorials
  10. Giving a User Manager Access
  11. Making Member-Only Pages
  12. Creating a Second Super Admin User
  13. Restricting an Element from Users
  14. More on the Anonymous User Group
  15. Hardening MODX Revolution
  16. Security Standards
  17. Troubleshooting Security
  18. Resetting a User Password Manually

Extending modUser