]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
supporting associating an OpenID with an existing account
authorCash Costello <cash.costello@gmail.com>
Sat, 28 Jan 2012 17:40:18 +0000 (12:40 -0500)
committerCash Costello <cash.costello@gmail.com>
Sat, 28 Jan 2012 17:40:18 +0000 (12:40 -0500)
return.php

index 87ce5b19f58f4ce2134df21f2cd2e5ca56b539db..ab0fc622afb4a0df0e5e705f6d158f9941e2936a 100644 (file)
@@ -24,16 +24,29 @@ if (!$data || !$data['openid_identifier']) {
        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