Hello. I'm calling method User.Service to register new users from a Flash application.
I'm using Profile core module too to add some info about the user.
The registration process works fine (all data is saved, and user is created), but no e-mail is sent.
I thought I had understood the problem in this previous post: http://groups.drupal.org/node/60208
(I'm not using Content Profile anymore...)
Because for some reason that I could not understand the registration process started sending e-mails...
But now that i rebuilt the registration without Content Profile, again no email is sent.
If I make a normal registration, then an email is sent.
My user settings are as follows:
Visitors can create accounts and no administrator approval is required.
I tried both with and without "Require e-mail verification..." activated.
Can anyone help me?
I guess I could modify the user.save method to force it to send an email, but i would like to use the normal registration workflow...
Comments
OK... I reimplemented the
OK... I reimplemented the user.service method, to one I created just to register users, and send an e-mail after.
Any review is welcome!!
Code is below:
function registerUser($account)
{
// Load the required includes for saving profile information
// with drupal_execute().
module_load_include('inc', 'user', 'user.pages');
// if uid is present then update, otherwise insert
$update = user_load($account['uid']);
$form_state = array();
// Any logged in user is by default authenticated,
// and leaving this role set in the user's roles array
// causes big problems because of a FAPI hack that controls
// this checkbox on the user create and edit form (and thus
// causes problems with drupal_execute()). Therefore we just
// force it to 0 here.
if (isset($account['roles'][2])) {
$account['roles'][2] = 0;
}
if (!isset($update->uid)) {
// register a new user
$form_state['values'] = $account;
$form_state['values']['pass'] = array(
'pass1' => $account['pass'],
'pass2' => $account['pass'],
);
$form_state['values']['op'] = t('Create new account');
$ret = drupal_execute('user_register', $form_state);
}
else
{
// if uid was already set, then it's not pretended to register a new user. so we return from the method with an error message
return t("User already registered.");
}
// Error if needed.
if ($errors = form_get_errors()) {
return services_error(implode("\n", $errors), 401);
}
else { // created successfully...
// Refresh user object.
$user = user_load(array('uid' => $form_state['user']->uid));
// set password variable (is expected in !password mail template)
$user->password = $form_state['user']->password;
// send email to new user
_user_mail_notify('register_no_approval_required', $user);
//return $form_state['user']->uid;
return t("User registered successfully.");
}
}
I think this is a bug. The
I think this is a bug. The values within $form_state['values'] aren't retained at the same key when they reach user_save() in user.module.
If you would however, like it to work without editing code, install logintoboggan.module and enable password field.