You are here

function sharedemail_is_shared_email in Shared Email 7

Check whether the e-mail address should be disguised during validation.

If the e-mail address is valid, check whether there are any other users with the same address. If there are, the address must be modified so that the User module's validation function will think it's unique.

Parameters

$form: The user form that was submitted.

$form_state: The state of the form.

Return value

Returns the e-mail address if it's a duplicate and is allowed. Otherwise nothing is returned.

1 call to sharedemail_is_shared_email()
sharedemail_account_form_validate in ./sharedemail.module
Form validation handler for user_account_form().

File

./sharedemail.module, line 156
Allow an e-mail address to be used by more than one user account.

Code

function sharedemail_is_shared_email($form, &$form_state) {
  $mail = trim($form_state['values']['mail']);

  // If e-mail address is invalid, don't have to disguise it.
  if (!user_validate_mail($mail)) {

    // Get the UIDs of all other users who have this e-mail address.
    $account = $form['#user'];
    $existing = db_select('users')
      ->fields('users', array(
      'uid',
    ))
      ->condition('uid', $account->uid, '<>')
      ->condition('mail', db_like($mail), 'LIKE')
      ->execute()
      ->fetchCol();
    if (count($existing) > 0) {
      if (user_access('show warning text')) {
        drupal_set_message(variable_get('sharedemail_msg', ''));
      }
      return $mail;
    }
  }

  // return nothing.
}