$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;
}
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;
- }
}
$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();
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;
}
$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;
+}