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_element('h2', NULL, _('Add OpenID'));
44 common_element('p', NULL,
45 _('If you want to add an OpenID to your account, ' .
46 'enter it in the box below and click "Add".'));
47 common_element_start('p');
48 common_element('label', array('for' => 'openid_url'),
50 common_element('input', array('name' => 'openid_url',
52 'id' => 'openid_url'));
53 common_element('input', array('type' => 'submit',
57 'value' => _('Add')));
58 common_element_end('p');
59 common_element_end('form');
61 $oid = new User_openid();
62 $oid->user_id = $user->id;
68 common_element('h2', NULL, _('Remove OpenID'));
70 if ($cnt == 1 && !$user->password) {
72 common_element('p', NULL,
73 _('Removing your only OpenID would make it impossible to log in! ' .
74 'If you need to remove it, add another OpenID first.'));
77 common_element_start('p');
78 common_element('a', array('href' => $oid->canonical),
80 common_element_end('p');
85 common_element('p', NULL,
86 _('You can remove an OpenID from your account '.
87 'by clicking the button marked "Remove".'));
90 while ($oid->fetch()) {
91 common_element_start('form', array('method' => 'POST',
92 'id' => 'openiddelete' . $idx,
94 common_local_url('openidsettings')));
95 common_element_start('p');
96 common_element('a', array('href' => $oid->canonical),
98 common_element('input', array('type' => 'hidden',
99 'id' => 'openid_url'.$idx,
100 'name' => 'openid_url',
101 'value' => $oid->canonical));
102 common_element('input', array('type' => 'submit',
103 'id' => 'remove'.$idx,
106 'value' => _('Remove')));
107 common_element_end('p');
108 common_element_end('form');
114 common_show_footer();
117 function handle_post() {
118 if ($this->arg('add')) {
119 $result = oid_authenticate($this->trimmed('openid_url'), 'finishaddopenid');
120 if (is_string($result)) { # error message
121 $this->show_form($result);
123 } else if ($this->arg('remove')) {
124 $this->remove_openid();
126 $this->show_form(_('Something weird happened.'));
130 function remove_openid() {
132 $openid_url = $this->trimmed('openid_url');
133 $oid = User_openid::staticGet('canonical', $openid_url);
135 $this->show_form(_('No such OpenID.'));
138 $cur = common_current_user();
139 if (!$cur || $oid->user_id != $cur->id) {
140 $this->show_form(_('That OpenID does not belong to you.'));
144 $this->show_form(_('OpenID removed.'), true);