--- logintoboggan.module 2007-04-28 01:38:49.000000000 -0400 +++ logintoboggan.module2 2007-07-04 19:58:12.906250000 -0400 @@ -177,9 +177,30 @@ function logintoboggan_form_alter($form_ case 'user_register': $mail = variable_get('email_reg_confirm', 0); $pass = !variable_get('user_email_verification', TRUE); - if (!user_access('administer users') && ($mail || $pass)) { + $tobaggon_role_choice = variable_get('toboggan_choose_role', 0); + if (!user_access('administer users') && ($mail || $pass || $tobaggon_role_choice)) { $form['#validate'] += array('logintoboggan_user_register_validate' => array()); $form['#submit'] = array('logintoboggan_user_register_submit' => array($form_id, &$form_values)); + + //Display checkboxes for the user role if option is enabled. + if ($tobaggon_role_choice) { + $roles = user_roles(1); + $allowed_roles = variable_get('toboggan_choose_role_types',0); + $allowed_keys = array_keys($allowed_roles); + for ($k=0;$k t('Choose your role type'), + '#type' => 'select', + '#options' => $user_roles, + '#description' => t('Please choose a role type for your account'), + '#required' => TRUE, + ); + } //Display a confirm e-mail address box if option is enabled. if ($mail) { @@ -223,6 +244,7 @@ function logintoboggan_form_alter($form_ function logintoboggan_user_register_submit($form_id, $form_values) { global $base_url; + $role_choice = $form_values['tobaggon_role_choice']; $mail = $form_values['mail']; $name = $form_values['name']; $from = variable_get('site_mail', ini_get('sendmail_from')); @@ -252,7 +274,14 @@ function logintoboggan_user_register_sub // Set the roles for the new user--it's the pre-auth role if they can pick their own password, // and the pre-auth role isn't anon or auth user. $validating_id = logintoboggan_validating_id(); - $roles = ($reg_pass_set && ($validating_id > 2)) ? array($validating_id => 1) : array(); + if (!isset($role_choice)) { + $roles = ($reg_pass_set && ($validating_id > 2)) ? array($validating_id) : array(); + } else { + $allowed_values = array_values(variable_get('toboggan_choose_role_types', 0)); + $choice = $allowed_values[$role_choice]; + $roles = $reg_pass_set ? array($choice) : array(); + print_r($roles); + } $account = user_save('', array_merge($form_values, array('pass' => $pass, 'init' => $mail, 'roles' => $roles, 'status' => $status))); @@ -581,14 +610,31 @@ function logintoboggan_main_settings() { '#description' => t('This will allow users to choose their initial password when registering. If \'Set password & Immediate login\' is selected, users will be assigned to the role below and logged in immediately. They will not be assigned to the "authenticated user" role until they confirm their e-mail address by following the link in their registration e-mail. It is HIGHLY recommended that you set up a "pre-authorized" role with limited permissions for this purpose.
NOTE: If you enable this feature, you should edit the !settings--more help in writing the e-mail message can be found at !help.', array('!settings' => l('user e-mail welcome message', 'admin/user/settings'), '!help' => l('logintoboggan help', 'admin/help/logintoboggan'))), ); + // Allow users to choose their role upon login. + $roles_option = array('1' => t('Enabled'), '0' => t('Disabled')); + $form['registration']['toboggan_choose_role'] = array( + '#type' => 'select', + '#title' => t('Allow users to choose their own roles upon login:'), + '#options' => $roles_option, + '#default_value' => variable_get('toboggan_choose_role',0), + '#description' => t('This will allow users to choose a role upon login. If you enable this, you can select which roles are allowed below.'), + ); + // Grab the roles that can be used for pre-auth. Remove the anon role, as it's not a valid choice. $roles = user_roles(1); + $form['registration']['toboggan_choose_role_types'] = array( + '#type' => 'checkboxes', + '#title' => t('Choose which roles are allowed for user registration.'), + '#options' => $roles, + '#default_value' => variable_get('toboggan_choose_role_types',0), + '#description' => t('If you have chosen to allow users to choose their own role types on login, make sure to select which roles are allowed here. Otherwise, this option will be disabled. '), + ); $form ['registration']['toboggan_role'] = array('#type' => 'select', '#title' => t('Non-authenticated role'), '#options' => $roles, '#default_value' => variable_get('toboggan_role', 2), - '#description' => t('If "Set password & Immediate login" is selected, users will be able to login before their e-mail address has been authenticated. Therefore, you must choose a role for new non-authenticated users. Users will be removed from this role and assigned to the "authenticated user" role once they follow the link in their welcome e-mail. Add new roles.', array('!url' => url('admin/user/roles'))), + '#description' => t('If "Set password & Immediate login" is selected and you have not enabled "Role Selection" above, users will be able to login before their e-mail address has been authenticated. Therefore, you must choose a role for new non-authenticated users. Users will be removed from this role and assigned to the "authenticated user" role once they follow the link in their welcome e-mail. Add new roles.', array('%url' => url('admin/access/roles'))), ); $form['registration']['redirect'] = array(