Active
Project:
U Create
Version:
6.x-1.0-beta3
Component:
ucreate.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
4 May 2010 at 23:07 UTC
Updated:
4 May 2010 at 23:07 UTC
In a project I'm deploying using openatrium, I need to let a new admin create users without sending email to them. The idea is a general email will be sent out to a bunch of users once the site is set up and ready to use. I noticed that ucreate does not check the mail notification settings before sending mail.
I put in the notification logic similar to the one found in user.module and tested this alternative function for ucreate_user_create (Changes are after the comment "Notify user if successful")
function ucreate_user_create($edit) {
// Send in the language in which the user is viewing the site.
global $language;
// Sanitize the $params array which will get sent to drupal_mail.
$params = array();
// Define who the mail will be sent from.
$from = variable_get('site_mail', ini_get('sendmail_from'));
// Create account.
$account = new stdClass();
$password = user_password();
$edit['pass'] = $password;
$edit['status'] = 1;
$account = user_save($account, $edit);
// Notify user if successful.
// only if notification settings indicate a required notification
if ($account->uid) {
$default_notify = ($op != 'status_deleted' && $op != 'status_blocked');
$op = "status_activated";
$notify = variable_get('user_mail_'. $op .'_notify', $default_notify);
if ($notify) {
drupal_set_message(t('You have created an account for !name, password and login instructions have been sent to the e-mail address !email.', array('!name' => $edit['name'], '!email' => l($edit['mail'], 'mailto:'. $edit['mail']))));
$params['subject'] = t('[!site_name] We have created an account for you', array('!site_name' => variable_get('site_name', 'Drupal')));
$variables = array(
'!name' => $edit['name'],
'!site' => variable_get('site_name', 'Drupal'),
'!login_url' => user_pass_reset_url($account) .'/login',
'!url' => trim(url('<front>', array('absolute' => TRUE)), '/'),
'!password' => $password,
);
if (trim($edit['welcome_message_body'])) {
$body .= $edit['welcome_message_body'];
$body .= "\n\n================================================\n";
}
else {
$body .= t("\nHello !name,\n", $variables);
}
// @todo: Would love to use one time login link here - alas it is only valid for 24 hrs and needs to be renewed then.
$body .= t("\nWe have created an account for you on !site\n!url.\n\nYou can log in to the site with the following username and password\n\n!name\n!password\n\nPlease change your password after the first time you log in.\n\nWelcome to !site", $variables);
// Put the completed $body in the $params array for hook_mail
$params['body'] = $body;
if (!drupal_mail('ucreate', 'ucreate-create', $edit['mail'], $language, $params, $from)) {
drupal_set_message(t('Error sending notification mail to user.'), 'error');
}
}
else {
drupal_set_message(t('You have created an account for !name, password and login instructions have NOT been sent to the e-mail address !email.', array('!name' => $edit['name'], '!email' => l($edit['mail'], 'mailto:'. $edit['mail']))));
}
}
else {
drupal_set_message(t('Error creating user.'), 'error');
}
return $account;
}