JavaScript API Class: User
The User class represents a registered or anonymous user. It can be accessed via the "user" implicit object. Future API versions will provide more robust user management.
Properties
| Name | Type | Access |
Description |
| alert |
Number |
read/write |
The number of hours between email change alerts for this user. Returns 0 if this user has opted-out of email alerts. |
| alertMinor | Boolean |
read/write |
True if this user has opted in to receive alerts for minor edits. |
| email |
String |
read/write |
Email address for this user. |
| groups | Array | read | An array of the Groups this user is a member of. |
| hash | String |
read |
A hash value used for security purposes. Only set for the current logged-in user. |
| isAdmin |
Boolean | read |
True if this user is an Administrator. |
| isLoggedIn |
Boolean |
read | False if this is an anonymous user. |
| isRegistered |
Boolean |
read |
True if this user is in the defaut Registered group. |
| name |
String |
read/write |
This user's login name. Note that user names cannot be changed. The name can only be set for a new user that does not yet have a name. |
| password |
String |
write |
Sets the user's password. Note that an existing password cannot be retrieved. Use the passwordMatches() function to test for password validity. |
| timeZone |
String |
read/write |
The time zone this user selected in user preferences. |
| userType | String |
read/write |
Set's the user type, which can be Public, Registered, Administrator or Locked. Note that while a public user will return Public, you cannot set the type of an existing user as Public as Public users cannot be saved. User type must be set to something other than Public before save() is called on a new user. |
Functions
| Name | Return Type |
Description |
| lock() |
None |
Sets this user's status to Locked. |
| login (Boolean) | None | Logs the user in based on data in the user object on which its called. Note that this does not provide authentication - it simply logs the current user in. Use passwordMatches(..) to authenticate given a provided password before calling login(). Pass a true parameter to set the "Remember Me" cookie. Though subsequent script and API calls will honor the new login status after this call, scripts should redirect to another page on the site before displaying a page as this method may be called after steps of the current page draw have taken place. |
| logout() | None | Ends the current login session, regardless of the user object called upon. This call will also remove the "Remember Me" cookie. |
| save() | None |
Saves this user. Note that userType cannot be Public when save() is called. |
| passwordMatches(String) |
Boolean | Returns true if the String matches the stored password for this user. |
| destroy() |
None |
Permanently deletes this user. |
Example
// a function that returns a welcome message for the given user
function welcomeText(user) {
if (!user.isLoggedIn) return 'Welcome, Anonymous!';
else return 'Welcome, ' + user.name + '!';
}
Return to JavaScript API