]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
consolidate linking a user to an OpenID
authorEvan Prodromou <evan@prodromou.name>
Wed, 18 Jun 2008 11:43:10 +0000 (07:43 -0400)
committerEvan Prodromou <evan@prodromou.name>
Wed, 18 Jun 2008 11:43:10 +0000 (07:43 -0400)
darcs-hash:20080618114310-84dde-15b224bb16d434150af457bc3b08de58e3833abd.gz

actions/finishaddopenid.php
actions/finishopenidlogin.php
lib/openid.php

index 2b34b38ea2eb0f22ae69025e83fba094d630a487..6a7bb3d2484cc703dea65e4948d725ec824581e5 100644 (file)
@@ -64,7 +64,8 @@ class FinishaddopenidAction extends Action {
                                $this->message(_t('This OpenID is already associated with user "') . $user->nickname . _t('"'));
                        } else {
                                $cur = common_current_user();
-                               if (!$this->connect_user($cur, $display, $canonical)) {
+                               $result = oid_link_user($cur->id, $display, $canonical);
+                               if (!$result) {
                                        $this->message(_t('Error connecting user'));
                                        return;
                                }
@@ -136,24 +137,4 @@ class FinishaddopenidAction extends Action {
                
                return true;
        }
-
-       function connect_user($user, $display, $canonical) {
-
-               $id = $user->id;
-               
-               $oid = new User_openid();
-               $oid->display = $display;
-               $oid->canonical = $canonical;
-               $oid->user_id = $id;
-               $oid->created = DB_DataObject_Cast::dateTime();
-               
-               $result = $oid->insert();
-               
-               if (!$result) {
-                       $err = PEAR::getStaticProperty('DB_DataObject','lastError');
-                       common_debug('DB error ' . $err->code . ': ' . $err->message, __FILE__);
-                       return false;
-               }
-               return true;
-       }
 }
index 202520d54ea8fc0281274a420be4188eaad0a2c6..3d0c8f2779cfcee78cd5fac42ff7c1e3cb6f3237 100644 (file)
@@ -264,15 +264,8 @@ class FinishopenidloginAction extends Action {
                        $profile->delete();
                }
 
-               $oid = new User_openid();
-               $oid->display = $display;
-               $oid->canonical = $canonical;
-               $oid->user_id = $id;
-               $oid->created = DB_DataObject_Cast::dateTime();
                
-               $result = $oid->insert();
-
-               if (!$result) {
+               if (!oid_link_user($user->id, $canonical, $display) {
                        # Try to clean up...
                        $user->delete();
                        $profile->delete();
@@ -303,14 +296,10 @@ class FinishopenidloginAction extends Action {
                        return;
                }
                
-               $oid = new User_openid();
-               $oid->display = $display;
-               $oid->canonical = $canonical;
-               $oid->user_id = $user->id;
-               $oid->created = DB_DataObject_Cast::dateTime();
+               $result = oid_link_user($user->id, $canonical, $display);
                
-               if (!$oid->insert()) {
-                       common_server_error(_t('Error connecting OpenID.'));
+               if (!$result) {
+                       common_server_error(_t('Error connecting user to OpenID.'));
                        return;
                }
                
index 9128ecddcc25a02004703faee901c06b5a05d857..c41b3424cd2973b1157a126f71ffab98745ac2ed 100644 (file)
@@ -41,4 +41,21 @@ function oid_consumer() {
        $store = oid_store();
        $consumer = new Auth_OpenID_Consumer($store);
        return $consumer;
-}
\ No newline at end of file
+}
+
+function oid_link_user($id, $canonical, $display) {
+       
+       $oid = new User_openid();
+       $oid->user_id = $id;
+       $oid->canonical = $canonical;
+       $oid->display = $display;
+       $oid->created = DB_DataObject_Cast::dateTime();
+               
+       if (!$oid->insert()) {
+               $err = PEAR::getStaticProperty('DB_DataObject','lastError');
+               common_debug('DB error ' . $err->code . ': ' . $err->message, __FILE__);
+               return false;
+       }
+       
+       return true;
+}