x

Main chapters

  1. LimeSurvey Cloud vs LimeSurvey CE
  2. LimeSurvey Cloud - Quick start guide
  3. LimeSurvey CE - Installation
  4. How to design a good survey (Guide)
  5. Getting started
  6. LimeSurvey configuration
  7. Introduction - Surveys
  8. View survey settings
  9. View survey menu
  10. View survey structure
  11. Introduction - Questions
  12. Introduction - Question Groups
  13. Introduction - Surveys - Management
  14. Survey toolbar options
  15. Multilingual survey
  16. Quick start guide - ExpressionScript
  17. Advanced features
  18. General FAQ
  19. Troubleshooting
  20. Workarounds
  21. License
  22. Version change log
  23. Plugins - Advanced
 Actions

CreateNewUser

From LimeSurvey Manual

 Hint: This feature is available starting in version 5.0.0

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:
  • users_name (string): Username
  • full_name (string): Full name
  • email (string): Email address
  • lang (string): Language preference
  • password (string): Raw password
  • status (optional bool): User active status
  • expires (optional string): Expiration date

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