cvs diff: Diffing modules
cvs diff: Diffing modules/signup_confirm_email
Index: modules/signup_confirm_email/signup_confirm_email.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/modules/signup_confirm_email/signup_confirm_email.inc,v
retrieving revision 1.1
diff -u -p -r1.1 signup_confirm_email.inc
--- modules/signup_confirm_email/signup_confirm_email.inc	24 Jul 2009 17:47:49 -0000	1.1
+++ modules/signup_confirm_email/signup_confirm_email.inc	3 Aug 2009 20:00:56 -0000
@@ -14,40 +14,41 @@
  */
 function signup_confirm_email_alter_signup_form(&$form, &$form_state, $form_id) {
   global $user;
-  unset($_SESSION['signup_email_confirm_sid']);
-  unset($_SESSION['signup_email_confirm_values']);
+
+  // We only need to do this for authenticated users signing up
+  // themselves. We already collect the (presumably current) e-mail for
+  // "anonymous" signups. If an administrator is signing up another user,
+  // there's no reason to include the e-mail confirmation field, either.
   if (!empty($user->uid) && empty($form['collapse']['signup_user_form']['signup_username'])) {
-    // We only need to do this for authenticated users signing up
-    // themselves. We already collect the (presumably current) e-mail for
-    // "anonymous" signups. If an administrator is signing up another user,
-    // there's no reason to include the e-mail confirmation field, either.
-    $email_confirm = array(
+    drupal_add_js(drupal_get_path('module', 'signup_confirm_email') . '/signup_confirm_email.js');
+    $email = array(
+      '#weight' => -1,
+    );
+    $email['email_address'] = array(
       '#title' => t('E-mail address'),
       '#type' => 'textfield',
       '#default_value' => $user->mail,
       '#size' => 40,
-      '#weight' => -1,
+    );
+    $email['email_confirm'] = array(
+      '#title' => t('Update e-mail address in user profile'),
+      '#type' => 'checkbox',
+      '#default_value' => 0,
+      '#description' => t('You must confirm any changes to the e-mail address stored in your user profile by selecting this checkbox.'),
+      // This div is used to hide the checkbox on page load when JS is
+      // enabled, and to reveal it once the 'email_address' field is edited.
+      '#prefix' => '<div class="js-hide" id="signup-confirm-email-checkbox">',
+      '#suffix' => '</div>',
     );
     if ($form_id == 'signup_form') {
-      $form['collapse']['email_confirm'] = $email_confirm;
-      $form['signup_type'] = array('#type' => 'value', '#value' => 'new');
+      $form['collapse']['email'] = $email;
+      $form['#submit'][] = 'signup_email_confirm_submit';
     }
     elseif ($form_id == 'signup_edit_form') {
-      $form['elements']['email_confirm'] = $email_confirm;
-      $form['signup_type'] = array('#type' => 'value', '#value' => 'edit');
+      $form['elements']['email'] = $email;
+      $form['elements']['save']['#submit'][] = 'signup_email_confirm_submit';
     }
     $form['#validate'][] = 'signup_email_confirm_validate';
-    if (!empty($form['#submit'])) {
-      foreach ($form['#submit'] as $key => $callback) {
-        if ($callback == 'signup_form_submit') {
-          unset($form['#submit'][$key]);
-        }
-      }
-    }
-    elseif (!empty($form['elements']['save']['#submit'])) {
-      unset($form['elements']['save']['#submit']);
-    }
-    $form['#submit'][] = 'signup_email_confirm_submit';
   }
 }
 
@@ -55,10 +56,20 @@ function signup_confirm_email_alter_sign
  * Validation callback for the signup form.
  */
 function signup_email_confirm_validate($form, $form_state) {
-  if (!empty($form_state['values']['email_confirm']) && 
-      !valid_email_address($form_state['values']['email_confirm'])) {
-    form_set_error('email_confirm', t('Invalid e-mail address'));
+  global $user;
+  $error = FALSE;
+  if (!empty($form_state['values']['email_address'])) {
+    if (!valid_email_address($form_state['values']['email_address'])) {
+      form_set_error('email_address', t('Invalid e-mail address'));
+    }
+    if ($form_state['values']['email_address'] != $user->mail && empty($form_state['values']['email_confirm'])) {
+      form_set_error('email_confirm', t('Please confirm that you wish to save this new e-mail address into your user profile.'));
+      $error = TRUE;
+    }
   }
+  // Add a JS setting for if the checkbox has a validation error, in which
+  // case we display it, even if the 'E-mail address' field isn't re-edited.
+  drupal_add_js(array('signupConfirmEmailCheckboxError' => $error), 'setting');
 }
 
 /**
@@ -72,73 +83,14 @@ function signup_email_confirm_validate($
  */
 function signup_email_confirm_submit($form, &$form_state) {
   global $user;
-  if (!empty($form_state['values']['email_confirm'])) {
-    if ($form_state['values']['email_confirm'] != $user->mail) {
-      if (!empty($form['#signup'])) {
-        $_SESSION['signup_email_confirm_sid'] = $form['#signup']->sid;
-      }
-      $_SESSION['signup_email_confirm_values'] = $form_state['values'];
-      if (empty($_SESSION['signup_email_confirm_values']['nid'])) {
-        $_SESSION['signup_email_confirm_values']['nid'] = arg(1);
-      }
-      $nid = $_SESSION['signup_email_confirm_values']['nid'];
-      $form_state['redirect'] = "node/$nid/signup/confirm-email";
-      return;
+  if (!empty($form_state['values']['email_confirm']) && 
+      !empty($form_state['values']['email_address'])) {
+    if ($form_state['values']['email_address'] != $user->mail) {
+      // Update the user's e-mail address in their profile.
+      $user->mail = $form_state['values']['email_address'];
+      user_save($user, array('mail' => $user->mail));
+      drupal_set_message(t('Updated the e-mail address in your profile to %new_address.', array('%new_address' => $user->mail)));
     }
   }
-  if ($form_state['values']['signup_type'] == 'new') {
-    signup_form_submit($form, $form_state);
-  }
-  else {
-    module_load_include('inc', 'signup', 'includes/signup_edit_form');
-    signup_edit_form_save_submit($form, $form_state);
-  }
-}
-
-/**
- * Builds the confirmation form when the user is changing their e-mail address.
- */
-function signup_confirm_email_confirm_form() {
-  global $user;
-  $form['#submit'][] = 'signup_confirm_email_confirm_form_submit';
-  $abort_url = isset($_REQUEST['destination']) ? $_REQUEST['destination'] : 'node/' . $_SESSION['signup_email_confirm_values']['nid'];
-  $button_text = $_SESSION['signup_email_confirm_values']['signup_type'] == 'new' ? t('Change e-mail address and sign up') : t('Save changes');
-  return confirm_form(
-    $form,
-    t('Are you sure you want to change your e-mail address?'),
-    $abort_url,
-    t('You have entered a new e-mail address (%new_address) which is different from the one currently saved in your profile (%current_address). If you continue, the new address will be used for future e-mail messages from this site.', array('%new_address' => $_SESSION['signup_email_confirm_values']['email_confirm'], '%current_address' => $user->mail)),
-    $button_text, t('Cancel')
-  );
-}
-
-/**
- * Submit callback for the confirmation form when a user changes their e-mail.
- */
-function signup_confirm_email_confirm_form_submit($form, &$form_state) {
-  global $user;
-
-  // Update the user's e-mail address in their profile.
-  $user->mail = $_SESSION['signup_email_confirm_values']['email_confirm'];
-  user_save($user, array('mail' => $user->mail));
-  drupal_set_message(t('Updated the e-mail address in your profile to %new_address.', array('%new_address' => $user->mail)));
-
-  // Complete the signup and clear out the SESSION variable.
-  $nid = $_SESSION['signup_email_confirm_values']['nid'];
-  if ($_SESSION['signup_email_confirm_values']['signup_type'] == 'new') {
-    signup_sign_up_user($_SESSION['signup_email_confirm_values']);
-  }
-  else {
-    $signup->sid = $_SESSION['signup_email_confirm_sid'];
-    $edit_form['#signup'] = $signup;
-    $edit_form_state['values'] = $_SESSION['signup_email_confirm_values'];
-    module_load_include('inc', 'signup', 'includes/signup_edit_form');
-    signup_edit_form_save_submit($edit_form, $edit_form_state);
-  }
-  unset($_SESSION['signup_email_confirm_sid']);
-  unset($_SESSION['signup_email_confirm_values']);
-
-  // Return to the node they signed up to.
-  $form_state['redirect'] = "node/$nid";
 }
 
Index: modules/signup_confirm_email/signup_confirm_email.install
===================================================================
RCS file: modules/signup_confirm_email/signup_confirm_email.install
diff -N modules/signup_confirm_email/signup_confirm_email.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/signup_confirm_email/signup_confirm_email.install	3 Aug 2009 20:00:56 -0000
@@ -0,0 +1,11 @@
+<?php
+// $Id$
+
+/**
+ * Rebuild the site's menu to remove the stale menu item.
+ */
+function signup_confirm_email_update_6000() {
+  menu_rebuild();
+  return array();
+}
+
Index: modules/signup_confirm_email/signup_confirm_email.js
===================================================================
RCS file: modules/signup_confirm_email/signup_confirm_email.js
diff -N modules/signup_confirm_email/signup_confirm_email.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/signup_confirm_email/signup_confirm_email.js	3 Aug 2009 20:00:56 -0000
@@ -0,0 +1,45 @@
+/* $Id$ */
+
+/**
+ * Conditionally show the "Update e-mail..." checkbox on signup forms.
+ *
+ * We only want to display this checkbox if the user changes the
+ * "E-mail address" field while signing up or editing a signup.
+ * Unfortunately, just using change() doesn't work. We need to see
+ * when a key is pressed that can modify the value, and use that to
+ * trigger revealing the checkbox and its description.
+ *
+ * However, if there's a validation error regarding the checkbox, we
+ * need to ensure it's always visible, even if the e-mail address
+ * field is unchanged.
+ */
+Drupal.behaviors.showSignupConfirmEmailCheckbox = function() {
+  if (Drupal.settings.signupConfirmEmailCheckboxError) {
+    $('div#signup-confirm-email-checkbox').show();
+  }
+  else {
+    $('#edit-email-address-wrapper input[type=text]').keyup(function (e) {
+      switch (e.keyCode) {
+        case 16: // shift
+        case 17: // ctrl
+        case 18: // alt
+        case 20: // caps lock
+        case 33: // page up
+        case 34: // page down
+        case 35: // end
+        case 36: // home
+        case 37: // left arrow
+        case 38: // up arrow
+        case 39: // right arrow
+        case 40: // down arrow
+        case 9:  // tab
+        case 13: // enter
+        case 27: // esc
+          return false;
+        default:
+          $('div#signup-confirm-email-checkbox').show();
+      }
+    });
+  }
+}
+
Index: modules/signup_confirm_email/signup_confirm_email.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/signup/modules/signup_confirm_email/signup_confirm_email.module,v
retrieving revision 1.1
diff -u -p -r1.1 signup_confirm_email.module
--- modules/signup_confirm_email/signup_confirm_email.module	24 Jul 2009 17:47:49 -0000	1.1
+++ modules/signup_confirm_email/signup_confirm_email.module	3 Aug 2009 20:00:56 -0000
@@ -6,28 +6,13 @@
  * The Signup confirm e-mail module is an add-on for the Signup module to
  * confirm a user's e-mail address when they sign up for content on the site.
  * It adds an extra field on the signup form, prepopulated with the user's
- * current e-mail address. If the user changes this field, they are presented
- * with a confirmation form, and if they accept, their e-mail address in their
- * user profile is updated accordingly.
+ * current e-mail address. If the user changes this field, and they confirm
+ * they want to modify their profile, their e-mail address in their user
+ * profile is updated accordingly.
  */
 
 
 /**
- * Implement hook_menu().
- */
-function signup_confirm_email_menu() {
-  $items['node/%node/signup/confirm-email'] = array(
-    'type' => MENU_CALLBACK,
-    'description' => 'Confirmation page when changing e-mail during a signup.',
-    'access arguments' => array('sign up for content'),
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('signup_confirm_email_confirm_form'),
-    'file' => 'signup_confirm_email.inc',
-  );
-  return $items;
-}
-
-/**
  * Implement hook_form_alter().
  */
 function signup_confirm_email_form_alter(&$form, &$form_state, $form_id) {
cvs diff: Diffing modules/signup_confirm_email/translations
