Index: invite.module
===================================================================
--- invite.module	(.../orig/current/sites/all/modules/invite)	(revision 3356)
+++ invite.module	(.../trunk/sites/all/modules/invite)	(revision 3356)
@@ -384,15 +384,6 @@
     case 'insert':
       $invite = invite_load_from_session();
 
-      if (!$invite) {
-        // Try to look up an invitation in case a user has been invited to join
-        // the site, but did go straight to the site and signed up without
-        // using the invite link.
-        $code = db_result(db_query("SELECT reg_code FROM {invite} WHERE email = '%s'", $account->mail));
-        if ($code) {
-          $invite = invite_load($code);
-        }
-      }
       if ($invite) {
         invite_accept($invite, $account);
 
@@ -404,6 +402,11 @@
 
         unset($_SESSION[INVITE_SESSION]);
       }
+      
+      // Now update anyone else that sent an invitation to this user
+      db_query("UPDATE {invite} SET email = '%s', invitee = %d, joined = %d WHERE (email = lower('%s') OR email = lower('%s'))  AND canceled = 0 AND joined = 0", $account->mail, $account->uid, time(), $account->mail,$invite?$invite->email:$account->mail);
+      db_query("INSERT INTO {invite_notifications} (uid, invitee) SELECT uid, %d from {invite} WHERE (email = '%s') AND canceled = 0", $account->uid, $account->mail);
+      
       break;
 
     case 'delete':
@@ -421,13 +424,11 @@
  *   The user object of the invitee.
  */
 function invite_accept($invite, $account) {
-  // Update the invitation record.
-  db_query("UPDATE {invite} SET email = '%s', invitee = %d, joined = %d WHERE reg_code = '%s'", $account->mail, $account->uid, time(), $invite->reg_code);
-  // Delete all invites to these e-mail addresses, except this one.
-  db_query("DELETE FROM {invite} WHERE (email = '%s' OR email = '%s') AND reg_code <> '%s'", $invite->email, $account->mail, $invite->reg_code);
-  // Add all users who invited this particular e-mail address to the
-  // notification queue.
-  db_query("INSERT INTO {invite_notifications} (uid, invitee) SELECT uid, %d from {invite} WHERE (email = '%s' OR email = '%s') AND canceled = 0", $account->uid, $invite->email, $account->mail);
+  // Update just the registration for this reg_code
+  // The user_hook will handle any other invitations to this user,
+  // and also notifications.
+  db_query("UPDATE {invite} SET email = '%s', invitee = %d, joined = %d WHERE reg_code = '%s' AND canceled = 0", $account->mail, $account->uid, time(), $invite->reg_code);
+
   // Escalate the invitee's role.
   _invite_escalate_role($account);
   // Unblock user account.
