CreateNewUser
From LimeSurvey Manual
createNewUser Plugin Event
The createNewUser event is a plugin hook that fires when a new user is being created through the admin interface. This event allows authentication plugins to intercept the user creation process and create users in external systems (like LDAP directories) or customize the user creation flow.
Event Location
- Original dispatch:
application/controllers/UserManagementController.php(line 1599)
Input Parameters (Set Before Event Dispatch)
These parameters are initialized before the event is sent to plugins:
| Parameter | Type | Description |
|---|---|---|
errorCode |
int | Set to AuthPluginBase::ERROR_NOT_ADDED initially
|
errorMessageTitle |
string | Set to "Failed to add user" |
errorMessageBody |
string | Set to "Plugin is not active" |
preCollectedUserArray |
array | User data passed from the form containing:
|
Output Parameters (Set by Plugins)
Plugins must set these parameters to signal success or failure.
On Success
| Parameter | Type | Required | Description |
|---|---|---|---|
errorCode |
int | Yes | Must be set to AuthPluginBase::ERROR_NONE (value: 0)
|
newUserID |
int | Yes | The database UID of the newly created user |
newPassword |
string | No | The password assigned to the user |
newEmail |
string | No | Email address of the created user |
newFullName |
string | No | Full name of the created user |
On Failure
| Parameter | Type | Required | Description |
|---|---|---|---|
errorCode |
int | Yes | One of the error constants from AuthPluginBase (see list below)
|
errorMessageTitle |
string | Yes | User-friendly error title |
errorMessageBody |
string | Yes | Detailed error message |
Error Codes (from AuthPluginBase)
ERROR_NONE = 0 // Success
ERROR_NOT_ADDED = 5 // User was not added
ERROR_INVALID_EMAIL = 110 // Invalid email format
ERROR_ALREADY_EXISTING_USER = 120 // User already exists
ERROR_LDAP_CONNECTION = 130 // LDAP connection failed
ERROR_LDAP_NO_EMAIL = 140 // Email not found in LDAP
ERROR_LDAP_NO_FULLNAME = 150 // Full name not found in LDAP
ERROR_LDAP_NO_BIND = 160 // LDAP bind failed
ERROR_LDAP_NO_SEARCH_RESULT = 170 // User not found in LDAP
Example Plugin Implementation
Both application/core/plugins/Authdb/Authdb.php and application/core/plugins/AuthLDAP/AuthLDAP.php implement this event. Here's the typical pattern:
public function createNewUser()
{
$oEvent = $this->getEvent();
$preCollectedUserArray = $oEvent->get('preCollectedUserArray', []);
// Validate user data
// Create user in your system
// Handle errors
if ($success) {
$oEvent->set('newUserID', $userId);
$oEvent->set('newPassword', $password);
$oEvent->set('newEmail', $email);
$oEvent->set('newFullName', $fullName);
$oEvent->set('errorCode', self::ERROR_NONE);
} else {
$oEvent->set('errorCode', self::ERROR_LDAP_NO_BIND);
$oEvent->set('errorMessageTitle', 'Connection failed');
$oEvent->set('errorMessageBody', 'Error details here');
}
}
After Event Processing
After all plugins have handled the event, UserManagementController.php (lines 1657–1660) checks:
- If
errorCode !== ERROR_NONE, the creation fails and displays the error messages - If
errorCode === ERROR_NONE, permissions are set and the new user ID is returned