When using modules like Fboauth, Twitter, or Linkedin, new accounts often do not have an associated email address-- the email key is left as an empty string in user_save().

This causes the invite module to throw this fatal error when a new user is created:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-1410' for key 'uid_invitee': INSERT INTO {invite_notifications} (uid, invitee) SELECT uid, :uid FROM {invite} WHERE (email = :invite_email OR email = :account_mail) AND canceled = 0; Array ( [:uid] => 1410 [:invite_email] => [:account_mail] => ) in invite_process_invite() (line 747 of /localhost/sites/all/modules/invite/invite.module).

If two accounts have been registered with email address '', the follow chain of events will occur:

  1. invite_user_insert() calls invite_find_invite(), which returns a row.
  2. invite_user_insert() then calls invite_process_invite(), which attempts to insert a new row with email address ''.
  3. Error is thrown.

It's probably simplest to prevent this by checking the value of $account->mail with valid_email_address() in invite_user_insert(). We can modify invite_user_insert() like so:

/**
 * Implements hook_user_insert().
 */
function invite_user_insert(&$edit, $account, $category) {
  if (valid_email_address($account->mail)) {
    $invite = invite_find_invite($account->mail);

    if ($invite) {
      invite_process_invite($invite, $account);

      module_invoke_all('invite_accept', $invite, $account);

      // Flag the inviting user, this triggers status notifications and
      // saves us some queries otherwise.
      if ($invite->inviter->uid) {
        user_save($invite->inviter, array('data' => array('invite_accepted' => TRUE)));
      }

      if (isset($_SESSION)) {
        unset($_SESSION[INVITE_SESSION]);
      }
    }
  }
}

Comments

grasmash’s picture

Status: Active » Needs review
StatusFileSize
new1.67 KB

Attaching patch.

grasmash’s picture

Issue summary: View changes

added links to referenced modules

grasmash’s picture

Issue summary: View changes

adding detail

grasmash’s picture

Issue summary: View changes

updating to reflex latest 2.x integration