diff --git a/openid_connect.module b/openid_connect.module index 5bf87c9..630980e 100644 --- a/openid_connect.module +++ b/openid_connect.module @@ -819,19 +819,19 @@ function openid_connect_complete_authorization($client, $tokens, &$destination) return FALSE; } - // Check whether there is an e-mail address conflict. - if (user_load_by_mail($userinfo['email'])) { - drupal_set_message(t('The e-mail address %email is already taken.', array('%email' => $userinfo['email'])), 'error'); - - return FALSE; + // Check whether the user already has account on the system. + if (!$account = user_load_by_mail($userinfo['email'])) { + // Create a new account. + $account = openid_connect_create_user($sub, $userinfo, $client->getName()); + $account_is_new = TRUE; + } + else { + $account_is_new = FALSE; } - // Create a new account. - $account = openid_connect_create_user($sub, $userinfo, $client->getName()); // Reload $account in case it has been altered in a user hook elsewhere. $account = user_load($account->uid); openid_connect_save_userinfo($account, $userinfo); - $account_is_new = TRUE; } openid_connect_login_user($account, $destination);