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/settingsaction.php');
23 require_once(INSTALLDIR.'/lib/openid.php');
25 class OpenidsettingsAction extends SettingsAction
28 function get_instructions()
30 return _('[OpenID](%%doc.openid%%) lets you log into many sites ' .
31 ' with the same user account. '.
32 ' Manage your associated OpenIDs from here.');
35 function show_form($msg=null, $success=false)
38 $user = common_current_user();
40 $this->form_header(_('OpenID settings'), $msg, $success);
42 common_element_start('form', array('method' => 'post',
45 common_local_url('openidsettings')));
46 common_hidden('token', common_session_token());
47 common_element('h2', null, _('Add OpenID'));
48 common_element('p', null,
49 _('If you want to add an OpenID to your account, ' .
50 'enter it in the box below and click "Add".'));
51 common_element_start('p');
52 common_element('label', array('for' => 'openid_url'),
54 common_element('input', array('name' => 'openid_url',
56 'id' => 'openid_url'));
57 common_element('input', array('type' => 'submit',
61 'value' => _('Add')));
62 common_element_end('p');
63 common_element_end('form');
65 $oid = new User_openid();
66 $oid->user_id = $user->id;
72 common_element('h2', null, _('Remove OpenID'));
74 if ($cnt == 1 && !$user->password) {
76 common_element('p', null,
77 _('Removing your only OpenID would make it impossible to log in! ' .
78 'If you need to remove it, add another OpenID first.'));
81 common_element_start('p');
82 common_element('a', array('href' => $oid->canonical),
84 common_element_end('p');
89 common_element('p', null,
90 _('You can remove an OpenID from your account '.
91 'by clicking the button marked "Remove".'));
94 while ($oid->fetch()) {
95 common_element_start('form', array('method' => 'POST',
96 'id' => 'openiddelete' . $idx,
98 common_local_url('openidsettings')));
99 common_element_start('p');
100 common_hidden('token', common_session_token());
101 common_element('a', array('href' => $oid->canonical),
103 common_element('input', array('type' => 'hidden',
104 'id' => 'openid_url'.$idx,
105 'name' => 'openid_url',
106 'value' => $oid->canonical));
107 common_element('input', array('type' => 'submit',
108 'id' => 'remove'.$idx,
111 'value' => _('Remove')));
112 common_element_end('p');
113 common_element_end('form');
119 common_show_footer();
122 function handle_post()
125 $token = $this->trimmed('token');
126 if (!$token || $token != common_session_token()) {
127 $this->show_form(_('There was a problem with your session token. Try again, please.'));
131 if ($this->arg('add')) {
132 $result = oid_authenticate($this->trimmed('openid_url'), 'finishaddopenid');
133 if (is_string($result)) { # error message
134 $this->show_form($result);
136 } else if ($this->arg('remove')) {
137 $this->remove_openid();
139 $this->show_form(_('Something weird happened.'));
143 function remove_openid()
146 $openid_url = $this->trimmed('openid_url');
147 $oid = User_openid::staticGet('canonical', $openid_url);
149 $this->show_form(_('No such OpenID.'));
152 $cur = common_current_user();
153 if (!$cur || $oid->user_id != $cur->id) {
154 $this->show_form(_('That OpenID does not belong to you.'));
158 $this->show_form(_('OpenID removed.'), true);