consolidate linking a user to an OpenID

darcs-hash:20080618114310-84dde-15b224bb16d434150af457bc3b08de58e3833abd.gz
This commit is contained in:
Evan Prodromou 2008-06-18 07:43:10 -04:00
parent dc2e7f4225
commit 4a0b1a9ea9
3 changed files with 24 additions and 37 deletions

View File

@ -64,7 +64,8 @@ class FinishaddopenidAction extends Action {
$this->message(_t('This OpenID is already associated with user "') . $user->nickname . _t('"')); $this->message(_t('This OpenID is already associated with user "') . $user->nickname . _t('"'));
} else { } else {
$cur = common_current_user(); $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')); $this->message(_t('Error connecting user'));
return; return;
} }
@ -136,24 +137,4 @@ class FinishaddopenidAction extends Action {
return true; 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;
}
} }

View File

@ -264,15 +264,8 @@ class FinishopenidloginAction extends Action {
$profile->delete(); $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 (!oid_link_user($user->id, $canonical, $display) {
if (!$result) {
# Try to clean up... # Try to clean up...
$user->delete(); $user->delete();
$profile->delete(); $profile->delete();
@ -303,14 +296,10 @@ class FinishopenidloginAction extends Action {
return; return;
} }
$oid = new User_openid(); $result = oid_link_user($user->id, $canonical, $display);
$oid->display = $display;
$oid->canonical = $canonical;
$oid->user_id = $user->id;
$oid->created = DB_DataObject_Cast::dateTime();
if (!$oid->insert()) { if (!$result) {
common_server_error(_t('Error connecting OpenID.')); common_server_error(_t('Error connecting user to OpenID.'));
return; return;
} }

View File

@ -42,3 +42,20 @@ function oid_consumer() {
$consumer = new Auth_OpenID_Consumer($store); $consumer = new Auth_OpenID_Consumer($store);
return $consumer; return $consumer;
} }
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;
}