function tryLogin() { $consumer = oid_consumer(); $response = $consumer->complete(common_local_url('finishopenidlogin')); if ($response->status == Auth_OpenID_CANCEL) { // TRANS: Status message in case the response from the OpenID provider is that the logon attempt was cancelled. $this->message(_m('OpenID authentication cancelled.')); return; } else { if ($response->status == Auth_OpenID_FAILURE) { // TRANS: OpenID authentication failed; display the error message. %s is the error message. $this->message(sprintf(_m('OpenID authentication failed: %s'), $response->message)); } else { if ($response->status == Auth_OpenID_SUCCESS) { // This means the authentication succeeded; extract the // identity URL and Simple Registration data (if it was // returned). $display = $response->getDisplayIdentifier(); $canonical = $response->endpoint->canonicalID ? $response->endpoint->canonicalID : $response->getDisplayIdentifier(); oid_assert_allowed($display); oid_assert_allowed($canonical); $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response); if ($sreg_resp) { $sreg = $sreg_resp->contents(); } // Launchpad teams extension if (!oid_check_teams($response)) { $this->message(_m('OpenID authentication aborted: you are not allowed to login to this site.')); return; } $user = oid_get_user($canonical); if ($user) { oid_set_last($display); # XXX: commented out at @edd's request until better # control over how data flows from OpenID provider. # oid_update_user($user, $sreg); common_set_user($user); common_real_login(true); if (isset($_SESSION['openid_rememberme']) && $_SESSION['openid_rememberme']) { common_rememberme($user); } unset($_SESSION['openid_rememberme']); $this->goHome($user->nickname); } else { $this->saveValues($display, $canonical, $sreg); $this->showForm(null, $this->bestNewNickname($display, $sreg)); } } } } }
/** * Try to log in using OpenID * * Check the OpenID for validity; potentially store it. * * @return void */ function tryLogin() { $consumer = oid_consumer(); $response = $consumer->complete(common_local_url('finishaddopenid')); if ($response->status == Auth_OpenID_CANCEL) { // TRANS: Status message in case the response from the OpenID provider is that the logon attempt was cancelled. $this->message(_m('OpenID authentication cancelled.')); return; } else { if ($response->status == Auth_OpenID_FAILURE) { // TRANS: OpenID authentication failed; display the error message. // TRANS: %s is the error message. $this->message(sprintf(_m('OpenID authentication failed: %s.'), $response->message)); } else { if ($response->status == Auth_OpenID_SUCCESS) { $display = $response->getDisplayIdentifier(); $canonical = $response->endpoint && $response->endpoint->canonicalID ? $response->endpoint->canonicalID : $display; $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response); if ($sreg_resp) { $sreg = $sreg_resp->contents(); } // Launchpad teams extension if (!oid_check_teams($response)) { // TRANS: OpenID authentication error. $this->message(_m('OpenID authentication aborted: You are not allowed to login to this site.')); return; } $cur = common_current_user(); $other = oid_get_user($canonical); if ($other) { if ($other->id == $cur->id) { // TRANS: Message in case a user tries to add an OpenID that is already connected to them. $this->message(_m('You already have this OpenID!')); } else { // TRANS: Message in case a user tries to add an OpenID that is already used by another user. $this->message(_m('Someone else already has this OpenID.')); } return; } // start a transaction $cur->query('BEGIN'); $result = oid_link_user($cur->id, $canonical, $display); if (!$result) { // TRANS: Message in case the OpenID object cannot be connected to the user. $this->message(_m('Error connecting user.')); return; } if (Event::handle('StartOpenIDUpdateUser', array($cur, $canonical, &$sreg))) { if ($sreg) { if (!oid_update_user($cur, $sreg)) { // TRANS: Message in case the user or the user profile cannot be saved in StatusNet. $this->message(_m('Error updating profile.')); return; } } } Event::handle('EndOpenIDUpdateUser', array($cur, $canonical, $sreg)); // success! $cur->query('COMMIT'); oid_set_last($display); common_redirect(common_local_url('openidsettings'), 303); } } } }