3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/openid.php');
24 class FinishaddopenidAction extends Action {
26 function handle($args)
28 parent::handle($args);
29 if (!common_logged_in()) {
30 common_user_error(_('Not logged in.'));
39 $consumer =& oid_consumer();
41 $response = $consumer->complete(common_local_url('finishaddopenid'));
43 if ($response->status == Auth_OpenID_CANCEL) {
44 $this->message(_('OpenID authentication cancelled.'));
46 } else if ($response->status == Auth_OpenID_FAILURE) {
47 // Authentication failed; display the error message.
48 $this->message(sprintf(_('OpenID authentication failed: %s'), $response->message));
49 } else if ($response->status == Auth_OpenID_SUCCESS) {
51 $display = $response->getDisplayIdentifier();
52 $canonical = ($response->endpoint && $response->endpoint->canonicalID) ?
53 $response->endpoint->canonicalID : $display;
55 $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
58 $sreg = $sreg_resp->contents();
61 $cur =& common_current_user();
62 $other = oid_get_user($canonical);
65 if ($other->id == $cur->id) {
66 $this->message(_('You already have this OpenID!'));
68 $this->message(_('Someone else already has this OpenID.'));
77 $result = oid_link_user($cur->id, $canonical, $display);
80 $this->message(_('Error connecting user.'));
84 if (!oid_update_user($cur, $sreg)) {
85 $this->message(_('Error updating profile'));
92 $cur->query('COMMIT');
94 oid_set_last($display);
96 common_redirect(common_local_url('openidsettings'));
100 function message($msg)
102 common_show_header(_('OpenID Login'));
103 common_element('p', null, $msg);
104 common_show_footer();