X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Ffinishopenidlogin.php;h=da2a05c26bf914a882e23ec3b4e283fd97969a67;hb=26c7d5f04ea7808c8a3addf1d4ed56d36a36b6c9;hp=af5ffdf14d6b27c9166ad666fa1d10f87b9e16c3;hpb=21463458c55fb138461225cc0402001ce91cb81c;p=quix0rs-gnu-social.git diff --git a/actions/finishopenidlogin.php b/actions/finishopenidlogin.php index af5ffdf14d..da2a05c26b 100644 --- a/actions/finishopenidlogin.php +++ b/actions/finishopenidlogin.php @@ -104,10 +104,11 @@ class FinishopenidloginAction extends Action { $sreg = $sreg_resp->contents(); } - $user = $this->get_user($canonical); + $user = oid_get_user($canonical); if ($user) { - $this->update_user($user, $sreg); + oid_set_last($display); + oid_update_user($user, $sreg); common_set_user($user->nickname); $this->go_home($user->nickname); } else { @@ -123,55 +124,6 @@ class FinishopenidloginAction extends Action { common_show_footer(); } - function get_user($canonical) { - $user = NULL; - $oid = User_openid::staticGet('canonical', $canonical); - if ($oid) { - $user = User::staticGet('id', $oid->user_id); - } - return $user; - } - - function update_user($user, $sreg) { - - $profile = $user->getProfile(); - - $orig_profile = clone($profile); - - if ($sreg['fullname'] && strlen($sreg['fullname']) <= 255) { - $profile->fullname = $sreg['fullname']; - } - - if ($sreg['country']) { - if ($sreg['postcode']) { - # XXX: use postcode to get city and region - # XXX: also, store postcode somewhere -- it's valuable! - $profile->location = $sreg['postcode'] . ', ' . $sreg['country']; - } else { - $profile->location = $sreg['country']; - } - } - - # XXX save language if it's passed - # XXX save timezone if it's passed - - if (!$profile->update($orig_profile)) { - common_server_error(_t('Error saving the profile.')); - return; - } - - $orig_user = clone($user); - - if ($sreg['email'] && Validate::email($sreg['email'], true)) { - $user->email = $sreg['email']; - } - - if (!$user->update($orig_user)) { - common_server_error(_t('Error saving the user.')); - return; - } - } - function save_values($display, $canonical, $sreg) { common_ensure_session(); $_SESSION['openid_display'] = $display; @@ -210,7 +162,7 @@ class FinishopenidloginAction extends Action { # Possible race condition... let's be paranoid - $other = $this->get_user($canonical); + $other = oid_get_user($canonical); if ($other) { common_server_error(_t('Creating new account for OpenID that already has a user.')); @@ -238,6 +190,8 @@ class FinishopenidloginAction extends Action { # XXX save language if it's passed # XXX save timezone if it's passed + $profile->profileurl = common_profile_url($nickname); + $profile->created = DB_DataObject_Cast::dateTime(); # current time $id = $profile->insert(); @@ -264,21 +218,17 @@ 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_link_user($user->id, $canonical, $display); - $result = $oid->insert(); - if (!$result) { # Try to clean up... $user->delete(); $profile->delete(); } - common_redirect(common_local_url('profilesettings')); + oid_set_last($display); + common_set_user($user->nickname); + common_redirect(common_local_url('showstream', array('nickname' => $user->nickname))); } function connect_user() { @@ -302,18 +252,15 @@ 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; } - $this->update_user($user, $sreg); + oid_update_user($user, $sreg); + oid_set_last($display); common_set_user($user->nickname); $this->go_home($user->nickname); } @@ -334,9 +281,13 @@ class FinishopenidloginAction extends Action { function best_new_nickname($display, $sreg) { # Try the passed-in nickname - - if ($sreg['nickname'] && $this->is_new_nickname($sreg['nickname'])) { - return $sreg['nickname']; + + + if ($sreg['nickname']) { + $nickname = $this->nicknamize($sreg['nickname']); + if ($this->is_new_nickname($nickname)) { + return $nickname; + } } # Try the full name