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 show_top($arr) {
32 $this->message($msg, $success);
34 common_element('div', 'instructions',
35 _t('Manage your associated OpenIDs from here.'));
38 $this->settings_menu();
41 function show_form($msg=NULL, $success=false) {
43 $user = common_current_user();
45 common_show_header(_t('OpenID settings'), NULL, array($msg, $success),
46 array($this, 'show_top'));
48 common_element_start('form', array('method' => 'POST',
51 common_local_url('openidsettings')));
52 common_element('h2', NULL, _t('Add OpenID'));
53 common_element('p', NULL,
54 _t('If you want to add an OpenID to your account, ' .
55 'enter it in the box below and click "Add".'));
56 common_element_start('p');
57 common_element('label', array('for' => 'openid_url'),
59 common_element('input', array('name' => 'openid_url',
61 'id' => 'openid_url'));
62 common_element('input', array('type' => 'submit',
66 'value' => _t('Add')));
67 common_element_end('p');
68 common_element_end('form');
70 $oid = new User_openid();
71 $oid->user_id = $user->id;
77 common_element('h2', NULL, _t('Remove OpenID'));
79 if ($cnt == 1 && !$user->password) {
81 common_element('p', NULL,
82 _t('Removing your only OpenID would make it impossible to log in! ' .
83 'If you need to remove it, add another OpenID first.'));
84 common_element_start('p');
85 common_element('a', array('href' => $oid->canonical),
87 common_element_end('p');
91 common_element('h2', NULL, _t('Remove OpenID'));
92 common_element('p', NULL,
93 _t('You can remove an OpenID from your account '.
94 'by clicking the button marked "Remove".'));
97 while ($oid->fetch()) {
98 common_element_start('form', array('method' => 'POST',
99 'id' => 'openiddelete' . $idx,
101 common_local_url('openidsettings')));
102 common_element_start('p');
103 common_element('a', array('href' => $oid->canonical),
105 common_element('input', array('type' => 'hidden',
106 'id' => 'openid_url'.$idx,
107 'name' => 'openid_url',
108 'value' => $oid->canonical));
109 common_element('input', array('type' => 'submit',
110 'id' => 'remove'.$idx,
113 'value' => _t('Remove')));
114 common_element_end('p');
115 common_element_end('form');
120 common_show_footer();
124 function handle_post() {
125 if ($this->arg('add')) {
126 $result = oid_authenticate($this->trimmed('openid_url'), 'finishaddopenid');
127 if (is_string($result)) { # error message
128 $this->show_form($result);
130 } else if ($this->arg('remove')) {
131 $this->remove_openid();
133 $this->show_form(_t('Something weird happened.'));
137 function remove_openid() {
139 $openid_url = $this->trimmed('openid_url');
140 $oid = User_openid::staticGet('canonical', $openid_url);
142 $this->show_form(_t('No such OpenID.'));
145 $cur = common_current_user();
146 if (!$cur || $oid->user_id != $cur->id) {
147 $this->show_form(_t('That OpenID does not belong to you.'));
151 $this->show_form(_t('OpenID removed.'), true);