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_form($msg=NULL, $success=false) {
29 $user = common_current_user();
31 common_show_header(_t('OpenID settings'), NULL, NULL, array($this, 'settings_menu'));
34 $this->message($msg, $success);
36 common_element('div', 'instructions',
37 _t('Manage your associated OpenIDs from here.'));
39 common_element_start('form', array('method' => 'POST',
42 common_local_url('openidsettings')));
43 common_element('h2', NULL, _t('Add OpenID'));
44 common_element('p', NULL,
45 _t('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',
56 'value' => _t('Add')));
57 common_element_end('p');
58 common_element_end('form');
60 $oid = new User_openid();
61 $oid->user_id = $user->id;
65 common_element('h2', NULL, _t('OpenID'));
66 common_element('p', NULL,
67 _t('You can remove an OpenID from your account ',
68 'by clicking the button marked "Delete" next to it.'));
71 while ($oid->fetch()) {
72 common_element_start('form', array('method' => 'POST',
73 'id' => 'openiddelete' . $idx,
75 common_local_url('openidsettings')));
76 common_element_start('p');
77 common_element('a', array('href' => $oid->canonical),
79 common_element('input', array('type' => 'hidden',
80 'id' => 'openid_url'.$idx,
81 'name' => 'openid_url',
82 'value' => $oid->canonical));
83 common_element('input', array('type' => 'submit',
84 'id' => 'remove'.$idx,
86 'value' => _t('Add')));
87 common_element_end('p');
88 common_element_end('form');
96 function handle_post() {
97 if ($this->arg('add')) {
98 $result = oid_authenticate($this->trimmed('openid_url'), 'finishaddopenid');
99 if (is_string($result)) { # error message
100 $this->show_form($result);
102 } else if ($this->arg('remove')) {
103 $this->remove_openid();
105 $this->show_form(_t('Something weird happened.'));
109 function remove_openid() {
111 $openid_url = $this->trimmed('openid_url');
112 $oid = User_openid::staticGet('canonical', $openid_url);
114 $this->show_form(_t('No such OpenID.'));
117 $cur = common_current_user();
118 if (!$cur || $oid->user_id != $cur->id) {
119 $this->show_form(_t('That OpenID does not belong to you.'));
123 $this->show_form(_t('OpenID removed.', true));