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 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.
Users contain the following fields:
Users also have a Profile attached to them. It contains the following fields:
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:
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();
- User Groups
- Resource Groups
- Security Tutorials
- Giving a User Manager Access
- Making Member-Only Pages
- Creating a Second Super Admin User
- Restricting an Element from Users
- More on the Anonymous User Group
- Hardening MODX Revolution
- Security Standards
- Troubleshooting Security
- Resetting a User Password Manually