Port the functionality from HM1 where the user gets mailed the login to their new site.

Comments

adrian’s picture

This is how we did it in HM1

Basically you will be taking the --site_admin_email (or something like that) item passed to drupal,
and creating a user account using this.

If you can, please see if you can change this so that it sends the confirmation mail. with the single use link instead.

if (!function_exists('user_load')) {
	include_once(drupal_get_path('module', 'user') . '/user.module');
}
$admin_user = user_load(array('uid' => 1));
if ($GLOBALS['hm_client_email'] && !$admin_user->uid) {
  $user = new stdClass();
  $edit['name'] = 'admin';
  $edit['pass'] = user_password();
  $edit['mail'] = $GLOBALS['hm_client_email'];
  $edit['status'] = 1;
  $user = user_save($user,  $edit);
	
	if (file_exists("hm/profiles/$profile/welcome_mail.inc")) {
    include("hm/profiles/$profile/welcome_mail.inc");
    include_once('hm/hm.inc');
	  // Send mail
	  $variables = array(
	    '!username' => $edit['name'], 
	    '!password' => $edit['pass'], 
	    '!uri' => 'http://' . $GLOBALS['hm_temporary_url'] . '/user/login'
	  );
	  $from = $mail['from'];
	  $admin_email = $GLOBALS['hm_admin_email'];
	  $client_email = $GLOBALS['hm_client_email'];

	  drupal_mail('hm_welcome_email', $admin_email, t($mail['subject'], $variables), t($mail['body'], $variables), $from);
	  print "Initial user registration mail sent to $admin_email\n";
	  if ($client_email && ($client_email != $admin_email)) {
		  drupal_mail('hm_welcome_email', $client_email, t($mail['subject'], $variables), t($mail['body'], $variables), $from);
		  print "Initial user registration mail sent to $client_email\n";
	  }
	
	}
	else {
		print "Welcome mail not available, initial account not created\n";
	}
 
}
adrian’s picture

This seems to have become a fairly important piece of code, as it needs to be done to get D6 working properly (as the install also creates a placeholder account for you)

The mail bit at the bottom can be replaced with this code from user.module



  $account = $form_values['account'];
  $from = variable_get('site_mail', ini_get('sendmail_from'));

  // Mail one time login URL and instructions.
  $variables = array('!username' => $account->name, '!site' => variable_get('site_name', 'Drupal'), '!login_url' => user_pass_reset_url($account), '!uri' => $base_url, '!uri_brief' => preg_replace('!^https?://!', '', $base_url), '!mailto' => $account->mail, '!date' => format_date(time()), '!login_uri' => url('user', NULL, NULL, TRUE), '!edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE));
  $subject = _user_mail_text('pass_subject', $variables);
  $body = _user_mail_text('pass_body', $variables);
  $mail_success = drupal_mail('user-pass', $account->mail, $subject, $body, $from);

adrian’s picture

Status: Active » Needs work

just committed a basic starting point

i'm still not receiving emails, but it's definitely my mail admin side of things that is broken.

still need configurable welcome messages and a lot of tidying up.

benkant’s picture

Adrian's code in HEAD is working for me. The admin user is created and the email is sent.

I'll work on the custom email message, something like hm1, as it uses the password reset mail text at the moment.

benkant’s picture

Status: Needs work » Fixed

Done user account creation.

See http://drupal.org/node/324066 for customer user email.

anarcat’s picture

Project: Hostmaster (Aegir) » Hosting

put in the right project.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.