forward();\r
}\r
\r
-// does this user exist\r
+// is there an account already associated with this openid\r
+$user = null;\r
$users = elgg_get_entities_from_annotations(array(\r
'type' => 'user',\r
'annotation_name' => 'openid_identifier',\r
'annotation_value' => $data['openid_identifier'],\r
));\r
if ($users) {\r
- // log in user and maybe update account (admin setting, user prompt?)\r
+ // there should only be one account\r
$user = $users[0];\r
+} else {\r
+ $email = elgg_extract('email', $data);\r
+ if ($email) {\r
+ $users = get_user_by_email($email);\r
+ if (count($users) === 1) {\r
+ $user = $users[0];\r
+ $user->annotate('openid_identifier', $data['openid_identifier'], ACCESS_PUBLIC);\r
+ }\r
+ }\r
+}\r
\r
+if ($user) {\r
+ // log in user and maybe update account (admin setting, user prompt?)\r
try {\r
login($user);\r
} catch (LoginException $e) {\r