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()
29 return _('[OpenID](%%doc.openid%%) lets you log into many sites ' .
30 ' with the same user account. '.
31 ' Manage your associated OpenIDs from here.');
34 function show_form($msg=null, $success=false)
37 $user = common_current_user();
39 $this->form_header(_('OpenID settings'), $msg, $success);
41 common_element_start('form', array('method' => 'post',
44 common_local_url('openidsettings')));
45 common_hidden('token', common_session_token());
46 common_element('h2', null, _('Add OpenID'));
47 common_element('p', null,
48 _('If you want to add an OpenID to your account, ' .
49 'enter it in the box below and click "Add".'));
50 common_element_start('p');
51 common_element('label', array('for' => 'openid_url'),
53 common_element('input', array('name' => 'openid_url',
55 'id' => 'openid_url'));
56 common_element('input', array('type' => 'submit',
60 'value' => _('Add')));
61 common_element_end('p');
62 common_element_end('form');
64 $oid = new User_openid();
65 $oid->user_id = $user->id;
71 common_element('h2', null, _('Remove OpenID'));
73 if ($cnt == 1 && !$user->password) {
75 common_element('p', null,
76 _('Removing your only OpenID would make it impossible to log in! ' .
77 'If you need to remove it, add another OpenID first.'));
80 common_element_start('p');
81 common_element('a', array('href' => $oid->canonical),
83 common_element_end('p');
88 common_element('p', null,
89 _('You can remove an OpenID from your account '.
90 'by clicking the button marked "Remove".'));
93 while ($oid->fetch()) {
94 common_element_start('form', array('method' => 'POST',
95 'id' => 'openiddelete' . $idx,
97 common_local_url('openidsettings')));
98 common_element_start('p');
99 common_hidden('token', common_session_token());
100 common_element('a', array('href' => $oid->canonical),
102 common_element('input', array('type' => 'hidden',
103 'id' => 'openid_url'.$idx,
104 'name' => 'openid_url',
105 'value' => $oid->canonical));
106 common_element('input', array('type' => 'submit',
107 'id' => 'remove'.$idx,
110 'value' => _('Remove')));
111 common_element_end('p');
112 common_element_end('form');
118 common_show_footer();
121 function handle_post()
124 $token = $this->trimmed('token');
125 if (!$token || $token != common_session_token()) {
126 $this->show_form(_('There was a problem with your session token. Try again, please.'));
130 if ($this->arg('add')) {
131 $result = oid_authenticate($this->trimmed('openid_url'), 'finishaddopenid');
132 if (is_string($result)) { # error message
133 $this->show_form($result);
135 } else if ($this->arg('remove')) {
136 $this->remove_openid();
138 $this->show_form(_('Something weird happened.'));
142 function remove_openid()
145 $openid_url = $this->trimmed('openid_url');
146 $oid = User_openid::staticGet('canonical', $openid_url);
148 $this->show_form(_('No such OpenID.'));
151 $cur = common_current_user();
152 if (!$cur || $oid->user_id != $cur->id) {
153 $this->show_form(_('That OpenID does not belong to you.'));
157 $this->show_form(_('OpenID removed.'), true);