function inline_registration_submit in Inline Registration 5
Same name and namespace in other branches
- 6 inline_registration.module \inline_registration_submit()
- 7 inline_registration.module \inline_registration_submit()
Submit routine for inline registration form.
File
- ./
inline_registration.module, line 88
Code
function inline_registration_submit($form_id, &$form_values) {
// Most of this was ripped from user_register_submit().
// Not sure why we couldn't just pass the $form_values into user_register_submit(),
// but it didn't work well for me so I ripped off the code. Suggestions welcome.
global $base_url;
$mail = $form_values['mail'];
$name = $form_values['name'];
if (!variable_get('user_email_verification', TRUE)) {
$pass = $form_values['pass'];
}
else {
$pass = user_password();
}
$notify = FALSE;
$from = variable_get('site_mail', ini_get('sendmail_from'));
if (isset($form_values['roles'])) {
$roles = array_filter($form_values['roles']);
// Remove unset roles
}
//the unset below is needed to prevent these form values from being saved as user data
unset($form_values['form_token'], $form_values['submit'], $form_values['op'], $form_values['notify'], $form_values['form_id'], $form_values['affiliates'], $form_values['destination']);
$merge_data = array(
'pass' => $pass,
'init' => $mail,
'roles' => $roles,
);
$account = user_save('', array_merge($form_values, $merge_data));
watchdog('user', t('New user: %name %email.', array(
'%name' => $name,
'%email' => '<' . $mail . '>',
)), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $account->uid . '/edit'));
// Set the node uid and name to the newly created user so node will be properly attributed to the new user when saved
$form_values['name'] = $account->name;
$form_values['uid'] = $account->uid;
$variables = array(
'!username' => $name,
'!site' => variable_get('site_name', 'Drupal'),
'!password' => $pass,
'!uri' => $base_url,
'!uri_brief' => substr($base_url, strlen('http://')),
'!mailto' => $mail,
'!date' => format_date(time()),
'!login_uri' => url('user', NULL, NULL, TRUE),
'!edit_uri' => url('user/' . $account->uid . '/edit', NULL, NULL, TRUE),
'!login_url' => user_pass_reset_url($account),
);
if (!variable_get('user_email_verification', TRUE) && $account->status) {
// No e-mail verification is required, create new user account, and login user immediately.
$subject = _user_mail_text('welcome_subject', $variables);
$body = _user_mail_text('welcome_body', $variables);
drupal_mail('user-register-welcome', $mail, $subject, $body, $from);
user_authenticate($account->name, trim($pass));
$edit = array();
user_module_invoke('login', $edit, $account);
return '';
}
else {
if ($account->status || $notify) {
// Create new user account, no administrator approval required.
$subject = $notify ? _user_mail_text('admin_subject', $variables) : _user_mail_text('welcome_subject', $variables);
$body = $notify ? _user_mail_text('admin_body', $variables) : _user_mail_text('welcome_body', $variables);
drupal_mail($notify ? 'user-register-notify' : 'user-register-welcome', $mail, $subject, $body, $from);
if ($notify) {
drupal_set_message(t('Password and further instructions have been e-mailed to the new user %user.', array(
'%user' => $name,
)));
}
else {
drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.'));
return '';
}
}
else {
// Create new user account, administrator approval required.
$subject = _user_mail_text('approval_subject', $variables);
$body = _user_mail_text('approval_body', $variables);
drupal_mail('user-register-approval-user', $mail, $subject, $body, $from);
drupal_mail('user-register-approval-admin', $from, $subject, t("!username has applied for an account.\n\n!edit_uri", $variables), $from);
drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, your password and further instructions have been sent to your e-mail address.'));
return '';
}
}
}