logintoboggan.admin.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /**
  3. * @file
  4. * Administration functions for LoginToboggan module.
  5. */
  6. function logintoboggan_main_settings() {
  7. $_disabled = t('Disabled');
  8. $_enabled = t('Enabled');
  9. $form['login'] = array(
  10. '#type' => 'fieldset',
  11. '#title' => t('Log in'),
  12. );
  13. $form['login']['logintoboggan_login_with_email'] = array(
  14. '#type' => 'radios',
  15. '#title' => t('Allow users to login using their e-mail address'),
  16. '#default_value' => variable_get('logintoboggan_login_with_email', 0),
  17. '#options' => array($_disabled, $_enabled),
  18. '#description' => t('Users will be able to enter EITHER their username OR their e-mail address to log in.'),
  19. );
  20. $form['login']['logintoboggan_unified_login'] = array(
  21. '#type' => 'checkbox',
  22. '#title' => t('Present a unified login/registration page'),
  23. '#default_value' => variable_get('logintoboggan_unified_login', 0),
  24. '#description' => t("Use one page for both login and registration instead of Drupal's tabbed login/registration/password pages."),
  25. );
  26. $form['registration'] = array(
  27. '#type' => 'fieldset',
  28. '#title' => t('Registration'),
  29. );
  30. $form['registration']['logintoboggan_confirm_email_at_registration'] = array(
  31. '#type' => 'radios',
  32. '#title' => t('Use two e-mail fields on registration form'),
  33. '#default_value' => variable_get('logintoboggan_confirm_email_at_registration', 0),
  34. '#options' => array($_disabled, $_enabled),
  35. '#description' => t('User will have to type the same e-mail address into both fields. This helps to confirm that they\'ve typed the correct address.'),
  36. );
  37. if (module_exists('help')) {
  38. $help_text = t(" More help in writing the e-mail message can be found at <a href=\"!help\">LoginToboggan help</a>.", array('!help' => url('admin/help/logintoboggan')));
  39. }
  40. else {
  41. $help_text = '';
  42. }
  43. $form['registration']['logintoboggan_user_email_verification'] = array(
  44. '#type' => 'checkbox',
  45. '#title' => t('Set password'),
  46. '#default_value' => !variable_get('user_email_verification', TRUE) ? 1 : 0,
  47. '#description' => t("This will allow users to choose their initial password when registering (note that this setting is a mirror of the <a href=\"!settings\">Require e-mail verification when a visitor creates an account</a> setting, and is merely here for convenience). If selected, users will be assigned to the role below. 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. <br />NOTE: If you enable this feature, you should edit the <a href=\"!settings\">Welcome (no approval required)</a> text.", array('!settings' => url('admin/config/people/accounts'))) . $help_text,
  48. );
  49. // Grab the roles that can be used for pre-auth. Remove the anon role, as it's not a valid choice.
  50. $roles = user_roles(TRUE);
  51. $form ['registration']['logintoboggan_pre_auth_role'] = array(
  52. '#type' => 'select',
  53. '#title' => t('Non-authenticated role'),
  54. '#options' => $roles,
  55. '#default_value' => variable_get('logintoboggan_pre_auth_role', DRUPAL_AUTHENTICATED_RID),
  56. '#description' => t('If "Set password" 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 -- you may wish to <a href="!url">add a new role</a> for this purpose. Users will be removed from this role and assigned to the "authenticated user" role once they follow the link in their welcome e-mail. <strong>WARNING: changing this setting after initial site setup can cause undesirable results, including unintended deletion of users -- change with extreme caution!</strong>', array('!url' => url('admin/people/permissions/roles'))),
  57. );
  58. $purge_options = array(
  59. 0 => t('Never delete'),
  60. 86400 => t('1 Day'),
  61. 172800 => t('2 Days'),
  62. 259200 => t('3 Days'),
  63. 345600 => t('4 Days'),
  64. 432000 => t('5 Days'),
  65. 518400 => t('6 Days'),
  66. 604800 => t('1 Week'),
  67. 1209600 => t('2 Weeks'),
  68. 2592000 => t('1 Month'),
  69. 7776000 => t('3 Months'),
  70. 15379200 => t('6 Months'),
  71. 30758400 => t('1 Year'),
  72. );
  73. $form['registration']['logintoboggan_purge_unvalidated_user_interval'] = array(
  74. '#type' => 'select',
  75. '#title' => t('Delete unvalidated users after'),
  76. '#options' => $purge_options,
  77. '#default_value' => variable_get('logintoboggan_purge_unvalidated_user_interval', 0),
  78. '#description' => t("If enabled, users that are still in the 'Non-authenticated role' set above will be deleted automatically from the system, if the set time interval since their initial account creation has passed. This can be used to automatically purge spambot registrations. Note: this requires cron, and also requires that the 'Set password' option above is enabled. <strong>WARNING: changing this setting after initial site setup can cause undesirable results, including unintended deletion of users -- change with extreme caution! (please read the CAVEATS section of INSTALL.txt for important information on configuring this feature)</strong>")
  79. );
  80. $form['registration']['logintoboggan_immediate_login_on_register'] = array(
  81. '#type' => 'checkbox',
  82. '#title' => t('Immediate login'),
  83. '#default_value' => variable_get('logintoboggan_immediate_login_on_register', TRUE),
  84. '#description' => t("If set, the user will be logged in immediately after registering. Note this only applies if the 'Set password' option above is enabled."),
  85. );
  86. $form['registration']['redirect'] = array(
  87. '#type' => 'fieldset',
  88. '#title' => t('Redirections'),
  89. '#collapsible' => true,
  90. '#collapsed' => false,
  91. );
  92. $form['registration']['redirect']['logintoboggan_redirect_on_register'] = array(
  93. '#type' => 'textfield',
  94. '#title' => t('Redirect path on registration'),
  95. '#default_value' => variable_get('logintoboggan_redirect_on_register', ''),
  96. '#description' => t('Normally, after a user registers a new account, they will be taken to the front page, or to their user page if you specify <cite>Immediate login</cite> above. Leave this setting blank if you wish to keep the default behavior. If you wish the user to go to a page of your choosing, then enter the path for it here. For instance, you may redirect them to a static page such as <cite>node/35</cite>, or to the <cite>&lt;front&gt;</cite> page. You may also use <em>%uid</em> as a variable, and the user\'s user ID will be substituted in the path.'),
  97. );
  98. $form['registration']['redirect']['logintoboggan_redirect_on_confirm'] = array(
  99. '#type' => 'textfield',
  100. '#title' => t('Redirect path on confirmation'),
  101. '#default_value' => variable_get('logintoboggan_redirect_on_confirm', ''),
  102. '#description' => t('Normally, after a user confirms their new account, they will be taken to their user page. Leave this setting blank if you wish to keep the default behavior. If you wish the user to go to a page of your choosing, then enter the path for it here. For instance, you may redirect them to a static page such as <cite>node/35</cite>, or to the <cite>&lt;front&gt;</cite> page. You may also use <em>%uid</em> as a variable, and the user\'s user ID will be substituted in the path. In the case where users are not creating their own passwords, it is suggested to use <cite>user/%uid/edit</cite> here, so the user may set their password immediately after validating their account.'),
  103. );
  104. $form['registration']['redirect']['logintoboggan_override_destination_parameter'] = array(
  105. '#type' => 'checkbox',
  106. '#title' => t('Override destination parameter'),
  107. '#default_value' => variable_get('logintoboggan_override_destination_parameter', 1),
  108. '#description' => t("Normally, when a Drupal redirect is performed, priority is given to the 'destination' parameter from the originating URL. With this setting enabled, LoginToboggan will attempt to override this behavior with any values set above."),
  109. );
  110. $form['other'] = array('#type' => 'fieldset',
  111. '#title' => t('Other'),
  112. '#tree' => FALSE,
  113. );
  114. $site403 = variable_get('site_403', '');
  115. if ($site403 == '') {
  116. $disabled = $default = '0';
  117. }
  118. elseif ($site403 == 'toboggan/denied') {
  119. $disabled = '0';
  120. $default = 'toboggan/denied';
  121. }
  122. else {
  123. $disabled = $default = $site403;
  124. }
  125. $options = array($disabled => $_disabled, 'toboggan/denied' => $_enabled);
  126. $form['other']['logintoboggan_site_403'] = array(
  127. '#type' => 'radios',
  128. '#title' => t('Present login form on access denied (403)'),
  129. '#options' => $options,
  130. '#default_value' => $default,
  131. '#description' => t('Anonymous users will be presented with a login form along with an access denied message.')
  132. );
  133. $form['other']['logintoboggan_login_successful_message'] = array(
  134. '#type' => 'radios',
  135. '#title' => t('Display login successful message'),
  136. '#options' => array($_disabled, $_enabled),
  137. '#default_value' => variable_get('logintoboggan_login_successful_message', 0),
  138. '#description' => t('If enabled, users will receive a \'Log in successful\' message upon login.')
  139. );
  140. $min_pass_options = array(t('None'));
  141. for ($i = 2; $i < 30; $i++) {
  142. $min_pass_options[$i] = $i;
  143. }
  144. $form['other']['logintoboggan_minimum_password_length'] = array(
  145. '#type' => 'select',
  146. '#title' => t('Minimum password length'),
  147. '#options' => $min_pass_options,
  148. '#default_value' => variable_get('logintoboggan_minimum_password_length', 0),
  149. '#description' => t('LoginToboggan automatically performs basic password validation for illegal characters. If you would additionally like to have a minimum password length requirement, select the length here, or set to \'None\' for no password length validation.')
  150. );
  151. return system_settings_form($form);
  152. }
  153. /**
  154. * Implement hook_form_logintoboggan_main_settings_alter().
  155. *
  156. * @ingroup logintoboggan_core
  157. */
  158. function logintoboggan_form_logintoboggan_main_settings_alter(&$form, &$form_state) {
  159. // Ensure a valid submit array.
  160. $form['#submit'] = is_array($form['#submit']) ? $form['#submit'] : array();
  161. // Make this submit handler run first.
  162. array_unshift($form['#submit'], 'logintoboggan_main_settings_submit');
  163. }
  164. /**
  165. * Takes custom settings on the main settings page, transforms them into the
  166. * appropriate core setting, and cleans up the custom values.
  167. */
  168. function logintoboggan_main_settings_submit($form, &$form_state) {
  169. // User email verification setting.
  170. $user_email_verification = $form_state['values']['logintoboggan_user_email_verification'] ? FALSE : TRUE;
  171. variable_set('user_email_verification', $user_email_verification);
  172. unset($form_state['values']['logintoboggan_user_email_verification']);
  173. // Site 403 setting.
  174. $site_403 = $form_state['values']['logintoboggan_site_403'] == '0' ? '' : $form_state['values']['logintoboggan_site_403'];
  175. variable_set('site_403', $site_403);
  176. unset($form_state['values']['logintoboggan_site_403']);
  177. // If the unified login setting has been changed, we need to rebuild the
  178. // menu cache.
  179. if ($form['login']['logintoboggan_unified_login']['#default_value'] != $form['login']['logintoboggan_unified_login']['#value']) {
  180. drupal_set_message(t('Unified login setting was changed, menus have been rebuilt.'));
  181. // For some reason, a regular menu_rebuild() still leaves the old callbacks
  182. // cached -- doing it in a shutdown function seems to correct that issue.
  183. drupal_register_shutdown_function('menu_rebuild');
  184. }
  185. }