diff --git a/commerce_checkout_login.info b/commerce_checkout_login.info index 89359e4..a69230f 100644 --- a/commerce_checkout_login.info +++ b/commerce_checkout_login.info @@ -7,3 +7,10 @@ core = 7.x ; Simple tests ; files[] = tests/commerce_checkout_login.test + +; Information added by drupal.org packaging script on 2013-09-30 +version = "7.x-1.x-dev" +core = "7.x" +project = "commerce_checkout_login" +datestamp = "1380560029" + diff --git a/commerce_checkout_login.module b/commerce_checkout_login.module index f2e242d..41594b0 100644 --- a/commerce_checkout_login.module +++ b/commerce_checkout_login.module @@ -22,25 +22,6 @@ function commerce_checkout_login_form_commerce_checkout_pane_settings_form_alter ); $settings_form = &$form['settings']['commerce_checkout_login']; - $settings_form['commerce_checkout_login_new_user_create'] = array( - '#type' => 'checkbox', - '#title' => t('Automatically create a user account for new customers'), - '#description' => t('If checked, a new user will be created based on the order\'s email address. The user is created on submit of the checkout page.'), - '#default_value' => variable_get('commerce_checkout_login_new_user_create', FALSE), - ); - $settings_form['commerce_checkout_login_new_user_login'] = array( - '#type' => 'checkbox', - '#title' => t('Automatically login the new user.'), - '#description' => t('If checked, the new user will be logged in and the order converted to an authenticated user order.'), - '#default_value' => variable_get('commerce_checkout_login_new_user_login', FALSE), - '#prefix' => '
', - '#suffix' => '
', - '#states' => array( - 'invisible' => array( - ':input[name="commerce_checkout_login_new_user_create"]' => array('checked' => FALSE), - ), - ), - ); $settings_form['commerce_checkout_login_allow_registration'] = array( '#type' => 'checkbox', '#title' => t('Allow new customers to create a new account'), @@ -123,6 +104,7 @@ function commerce_checkout_login_form_commerce_checkout_form_alter(&$form, &$for '#type' => 'password', '#title' => t('Password'), '#required' => TRUE, + '#description' => t('Please enter the password for your account. !forgot', array('!forgot' => l(t('Did you forget your password?'), 'user/password'))) ); // No e-mail confirmation is required to login. So we hide the e-mail @@ -195,11 +177,9 @@ function commerce_checkout_login_form_commerce_checkout_form_alter(&$form, &$for } } - if (variable_get('commerce_checkout_login_new_user_create', FALSE)) { - // New user creation - if (isset($form['buttons']['continue'])) { - $form['buttons']['continue']['#submit'][] = 'commerce_checkout_login_checkout_form_user_register_submit'; - } + // Register the submit callback to enable user creation. + if (isset($form['buttons']['continue'])) { + $form['buttons']['continue']['#submit'][] = 'commerce_checkout_login_checkout_form_user_register_submit'; } } } @@ -211,11 +191,16 @@ function commerce_checkout_login_form_commerce_checkout_form_alter(&$form, &$for function commerce_checkout_login_checkout_form_refresh($form, $form_state) { $show_conf_mail = variable_get('commerce_order_account_pane_mail_double_entry', FALSE); + $mail = !empty($form_state['values']['account']['login']['mail']) ? trim($form_state['values']['account']['login']['mail']) : ''; + _validate_email($mail); + if (!$show_conf_mail) { return $form['account']['login']; } - // Return AJAX commands to set focus to the mail confirmation field for better UX. + + // Return AJAX commands to set focus to the mail confirmation field for + // improved user experience. $commands = array(); $commands[] = ajax_command_replace('#' . $form['account']['login']['mail']['#ajax']['wrapper'], drupal_render($form['account']['login'])); $commands[] = ajax_command_invoke('[name="account[login][mail_confirm]"]', 'focus'); @@ -238,13 +223,7 @@ function commerce_checkout_login_commerce_checkout_pane_info_alter(&$checkout_pa */ function commerce_checkout_login_commerce_checkout_pane_validate(&$form, &$form_state, $checkout_pane, $order) { $mail = !empty($form_state['values']['account']['login']['mail']) ? trim($form_state['values']['account']['login']['mail']) : $form_state['order']->mail; - $validated = TRUE; - - // Bail if an invalid e-mail address was supplied. - if ($error = user_validate_mail($mail)) { - form_set_error('account][login][mail', $error); - $validated = FALSE; - } + $validated = _validate_email($mail); if ($account = user_load_by_mail($mail)) { $validated = _validate_existing_account($form, $form_state, $account); @@ -280,9 +259,26 @@ function commerce_checkout_login_commerce_checkout_pane_validate(&$form, &$form_ } /** + * Email validation helper + */ +function _validate_email($mail) { + if ($error = user_validate_mail($mail)) { + form_set_error('account][login][mail', $error); + return FALSE; + } + return TRUE; +} + +/** * Known user validation helper. */ function _validate_existing_account(&$form, &$form_state, &$account) { + if ($user = user_uid_optional_load()) { + if ($user->uid === $account->uid) { + // Nothing to validate, the user is already logged in. + return TRUE; + } + } // If there is no password field present, the customer has not yet been // informed about the the pre-existing account. We therefore have to inform // the customer about this. @@ -308,8 +304,8 @@ function _validate_existing_account(&$form, &$form_state, &$account) { return TRUE; } else { - // But indicate that we could not login the user if validation failed. - form_set_error('account][login][password', t('Sorry, unrecognized username or password. Have you forgotten your password?', array('@password' => url('user/password')))); + // Indicate that the user could not be logged in if validation failed. + form_set_error('account][login][password', t('Sorry, unrecognized username or password. !password', array('!password' => l('Have you forgotten your password?', 'user/password')))); return FALSE; } } @@ -444,18 +440,16 @@ function commerce_checkout_login_checkout_form_user_register_submit($form, &$for } if (!empty($account)) { - // If either "automatic creation && automatic login" or "custom creation && automatic login": - if ((variable_get('commerce_checkout_login_new_user_create', FALSE) && variable_get('commerce_checkout_login_new_user_login', FALSE)) || (variable_get('commerce_checkout_login_allow_registration', FALSE) && variable_get('commerce_checkout_login_allow_registration_login', FALSE))) { - // Load the specified user into the global $user variable. - $user = $account; + // Login the user. + // Load the specified user into the global $user variable. + $user = $account; - // "Finalize" the login by triggering the appropriate system messages, IP - // address and login timestamp logging, and user login hook. - user_login_finalize(); + // "Finalize" the login by triggering the appropriate system messages, IP + // address and login timestamp logging, and user login hook. + user_login_finalize(); - // Convert the current cart order to an authenticated cart for the current user. - commerce_cart_order_convert($order, $user); - } + // Convert the current cart order to an authenticated cart for the current user. + commerce_cart_order_convert($order, $user); if (variable_get('commerce_checkout_login_send_welcome_message', FALSE)) { _user_mail_notify('register_no_approval_required', $account);