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 {
27 function get_instructions() {
28 return _('[OpenID](%%doc.openid%%) lets you log into many sites ' .
29 ' with the same user account. '.
30 ' Manage your associated OpenIDs from here.');
33 function show_form($msg=NULL, $success=false) {
35 $user = common_current_user();
37 $this->form_header(_('OpenID settings'), $msg, $success);
39 common_element_start('form', array('method' => 'post',
42 common_local_url('openidsettings')));
43 common_hidden('token', common_session_token());
44 common_element('h2', NULL, _('Add OpenID'));
45 common_element('p', NULL,
46 _('If you want to add an OpenID to your account, ' .
47 'enter it in the box below and click "Add".'));
48 common_element_start('p');
49 common_element('label', array('for' => 'openid_url'),
51 common_element('input', array('name' => 'openid_url',
53 'id' => 'openid_url'));
54 common_element('input', array('type' => 'submit',
58 'value' => _('Add')));
59 common_element_end('p');
60 common_element_end('form');
62 $oid = new User_openid();
63 $oid->user_id = $user->id;
69 common_element('h2', NULL, _('Remove OpenID'));
71 if ($cnt == 1 && !$user->password) {
73 common_element('p', NULL,
74 _('Removing your only OpenID would make it impossible to log in! ' .
75 'If you need to remove it, add another OpenID first.'));
78 common_element_start('p');
79 common_element('a', array('href' => $oid->canonical),
81 common_element_end('p');
86 common_element('p', NULL,
87 _('You can remove an OpenID from your account '.
88 'by clicking the button marked "Remove".'));
91 while ($oid->fetch()) {
92 common_element_start('form', array('method' => 'POST',
93 'id' => 'openiddelete' . $idx,
95 common_local_url('openidsettings')));
96 common_element_start('p');
97 common_hidden('token', common_session_token());
98 common_element('a', array('href' => $oid->canonical),
100 common_element('input', array('type' => 'hidden',
101 'id' => 'openid_url'.$idx,
102 'name' => 'openid_url',
103 'value' => $oid->canonical));
104 common_element('input', array('type' => 'submit',
105 'id' => 'remove'.$idx,
108 'value' => _('Remove')));
109 common_element_end('p');
110 common_element_end('form');
116 common_show_footer();
119 function handle_post() {
121 $token = $this->trimmed('token');
122 if (!$token || $token != common_session_token()) {
123 $this->show_form(_('There was a problem with your session token. Try again, please.'));
127 if ($this->arg('add')) {
128 $result = oid_authenticate($this->trimmed('openid_url'), 'finishaddopenid');
129 if (is_string($result)) { # error message
130 $this->show_form($result);
132 } else if ($this->arg('remove')) {
133 $this->remove_openid();
135 $this->show_form(_('Something weird happened.'));
139 function remove_openid() {
141 $openid_url = $this->trimmed('openid_url');
142 $oid = User_openid::staticGet('canonical', $openid_url);
144 $this->show_form(_('No such OpenID.'));
147 $cur = common_current_user();
148 if (!$cur || $oid->user_id != $cur->id) {
149 $this->show_form(_('That OpenID does not belong to you.'));
153 $this->show_form(_('OpenID removed.'), true);