I'm trying to programatically create a user (once the user submits a form through Sprout Forms). The user doesn't seem to appear in the Users section of the CP.
I've ensured the user is being added correctly - I can even see a row in the craft_users database table. Going directly to admin/users/349 (the ID of the newly added user) shows all the user details.
It's been suggested that I need to index the new element data - but not sure how to do this.
$content = $entry->getContent();
$user = new UserModel();
$user->username = $content['email'];
$user->email = $content['email'];
$user->unverifiedEmail = $content['email'];
$user->firstName = $content['firstName'];
$user->lastName = $content['lastName'];
$user->newPassword = $content['password'];
$user->pending = true;
$success = craft()->users->saveUser($user);
if ($success) {
craft()->search->indexElementAttributes($user);
// Assign them to the default user group
craft()->userGroups->assignUserToDefaultGroup($user);
// Send the activation email
craft()->users->sendActivationEmail($user);
// Update the Element Index
craft()->search->indexElementAttributes($user);
}
craft()->search->indexElementAttributes()
shouldn't be necessary here. If you look at theid
column for the user in thecraft_users
table, do you have a matchingelementId
incraft_elements_i18n
andid
incraft_elements
?craft_elements_i18n
andcraft_elements
. Both haveenabled
set to 1.craft\app\controllers\UsersController->actionSaveUser()
just to make sure you're not missing a piece of info beforecraft()->users->saveUser()
gets called.actionSaveUser()
, even adding the private methods, and still the same result. Very strange. Are there any caches to be emptied or something?