? 896576-5_ucreate_D7.patch ? ucreate_drupal_7_port_0.patch Index: README.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/ucreate/README.txt,v retrieving revision 1.3 diff -u -p -r1.3 README.txt --- README.txt 1 Sep 2010 18:35:54 -0000 1.3 +++ README.txt 1 Sep 2010 18:57:52 -0000 @@ -3,7 +3,7 @@ U Create module -Drupal 6.x compatible +Drupal 7.x compatible =============================================================================== Index: ucreate.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/ucreate/ucreate.info,v retrieving revision 1.2 diff -u -p -r1.2 ucreate.info --- ucreate.info 1 Sep 2010 18:35:54 -0000 1.2 +++ ucreate.info 1 Sep 2010 18:57:52 -0000 @@ -1,4 +1,5 @@ ;$Id: ucreate.info,v 1.2 2010/09/01 18:35:54 alexb Exp $ name = U Create description = Lets non-admins create user accounts for other people. -core=6.x \ No newline at end of file +core=7.x +files[] = ucreate.module \ No newline at end of file Index: ucreate.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/ucreate/ucreate.module,v retrieving revision 1.6 diff -u -p -r1.6 ucreate.module --- ucreate.module 1 Sep 2010 18:52:12 -0000 1.6 +++ ucreate.module 1 Sep 2010 18:57:52 -0000 @@ -11,7 +11,7 @@ function ucreate_help($path, $arg) { switch ($path) { case 'user/add': - return '

'. t('Create a new user. A notification e-mail will be sent to the e-mail address specified.') .'

'; + return '

' . t('Create a new user. A notification e-mail will be sent to the e-mail address specified.') . '

'; } } @@ -27,13 +27,6 @@ function ucreate_menu() { 'description' => 'Add a user to this web site.', 'access arguments' => array('create users'), ); - $items['admin/user/ucreate'] = array( - 'page callback' => 'drupal_get_form', - 'page arguments' => array('ucreate_settings_form'), - 'title' => 'U create settings', - 'description' => 'Configure default roles for users created by U create module.', - 'access arguments' => array('administer site configuration'), - ); $items['user/%user/block'] = array( 'page callback' => 'drupal_get_form', @@ -45,7 +38,6 @@ function ucreate_menu() { 'type' => MENU_LOCAL_TASK, ); - $items['user/%user/activate'] = array( 'page callback' => 'drupal_get_form', 'page arguments' => array('ucreate_block_form', 1, 'activate'), @@ -60,10 +52,19 @@ function ucreate_menu() { } /** - * Implementation of hook_perm(). + * Implementation of hook_permission(). */ -function ucreate_perm() { - return array('create users', 'block users', 'assign user roles'); +function ucreate_permission() { + return array( + 'create users' => array( + 'title' => t('Create users'), + 'description' => t('Allows non-admin users to create other users'), + ), + 'block users' => array( + 'title' => t('Block users'), + 'description' => t('Allows non-admin users to block other users'), + ) + ); } /** @@ -82,12 +83,12 @@ function ucreate_access_suspend($access_ if (($op == 'activate' && $account->status == 0) || ($op == 'block' && $account->status == 1)) { // Only show if action is possible - return true; + return TRUE; } } } } - return false; + return FALSE; } @@ -130,30 +131,7 @@ function ucreate_user_form() { '#title' => t('E-mail (confirm)'), '#required' => TRUE, ); - if (user_access('assign user roles') || user_access('administer users')) { - $form['roles'] = array( - '#type' => 'checkboxes', - '#title' => t('User roles'), - ); - $default_roles = variable_get('ucreate_default_roles', array()); - foreach (user_roles() as $rid => $role) { - // Exclude 'anonymous user' - if ($rid !== 1) { - $form['roles'][$rid] = array( - '#title' => $role, - '#type' => 'checkbox', - '#default_value' => in_array($rid, $default_roles, TRUE) || $rid === 2, - '#disabled' => $rid === 2 ? TRUE : FALSE, - ); - } - } - } - else { - $form['roles'] = array( - '#type' => 'value', - '#value' => drupal_map_assoc(variable_get('ucreate_default_roles', array())), - ); - } + // The personal welcome message will be added to the top of the mail. // @todo: Ideal would be offering the full notification message for edit // * updated by ajax call back (we shouldn't show tokens to users) @@ -178,11 +156,11 @@ function ucreate_user_form() { * Element validator for usernames. */ function ucreate_validate_name($element, &$form_state) { - if ($account = user_load(array('name' => $element['#value']))) { - $name = user_access('access user profiles') ? l($account->name, 'user/'. $account->uid) : $account->name; + if ($account = user_load_by_name(array('name' => $element['#value']))) { + $name = user_access('access user profiles') ? l($account->name, 'user/' . $account->uid) : $account->name; form_set_error('name', t('User @name already exists.', array('@name' => $name))); } - else if ($error = user_validate_name($element['#value'])) { + elseif ($error = user_validate_name($element['#value'])) { form_set_error('name', $error); } } @@ -194,10 +172,10 @@ function ucreate_validate_mail($element, if ($form_state['values']['mail_confirm'] !== $element['#value']) { form_set_error('mail_confirm', t('E-mail addresses don\'t match')); } - else if (user_load(array('mail' => $element['#value']))) { + elseif (user_load_by_mail(array('mail' => $element['#value']))) { form_set_error('mail', t('User with this e-mail address already exists.')); } - else if ($error = user_validate_mail($element['#value'])) { + elseif ($error = user_validate_mail($element['#value'])) { form_set_error('mail', $error); } } @@ -206,18 +184,6 @@ function ucreate_validate_mail($element, * Submit handler for ucreate_user_form(). */ function ucreate_user_form_submit($form, &$form_state) { - // If user roles were handled through a UI element, process accordingly. - // This sucks. See user_save() for why this is necessary. - if ($form['roles']['#type'] != 'value') { - $rids = array(); - foreach ($form_state['values']['roles'] as $rid => $enabled) { - if (!empty($enabled)) { - $rids[$rid] = $rid; - } - } - $form_state['values']['roles'] = $rids; - } - ucreate_user_create($form_state['values']); } @@ -240,7 +206,7 @@ function ucreate_block_form($form, $user if ($op == 'block') { $message = t('Are you sure you would like to suspend !user\'s account?', array('!user' => theme('username', $account))); } - else if ($op == 'activate') { + elseif ($op == 'activate') { $message = t('Are you sure you would like to activate !user\'s account?', array('!user' => theme('username', $account))); } $form = confirm_form($form, $message, $path, ''); @@ -253,20 +219,20 @@ function ucreate_block_form($form, $user * @todo: send email if user is blocked/activated. */ function ucreate_block_form_submit($form, &$form_state) { - if ($account = user_load(array('uid' => $form_state['values']['uid']))) { + if ($account = user_load($uid)) { if ($form_state['values']['operation'] == 'block') { $account = user_save($account, array('status' => 0)); if ($account->status == 0) { drupal_set_message(t('The account !user was suspended.', array('!user' => theme('username', $account)))); - drupal_goto('user/'. $account->uid); + drupal_goto('user/' . $account->uid); return; } } - else if ($form_state['values']['operation'] == 'activate') { + elseif ($form_state['values']['operation'] == 'activate') { $account = user_save($account, array('status' => 1)); if ($account->status == 1) { drupal_set_message(t('The account !user was activated.', array('!user' => theme('username', $account)))); - drupal_goto('user/'. $account->uid); + drupal_goto('user/' . $account->uid); return; } } @@ -300,22 +266,22 @@ function ucreate_user_create($edit) { // Notify user if successful. if ($account->uid) { - drupal_set_message(t('You have created an account for @name. The username and password have been sent along with log in instructions to the e-mail address !email.', array('@name' => $edit['name'], '!email' => l($edit['mail'], 'mailto:'. $edit['mail'])))); + drupal_set_message(t('You have created an account for @name. The username and password have been sent along with log in instructions 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', + '!login_url' => user_pass_reset_url($account) . '/login', '!url' => trim(url('', array('absolute' => TRUE)), '/'), '!password' => $password, ); if (trim($edit['welcome_message_body'])) { - $body .= $edit['welcome_message_body']; + $body = $edit['welcome_message_body']; $body .= "\n\n================================================\n"; } else { - $body .= t("\nHello !name,\n", $variables); + $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);