3 * StatusNet, the distributed open-source microblogging tool
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @copyright 2008-2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 require_once INSTALLDIR.'/lib/accountsettingsaction.php';
35 require_once INSTALLDIR.'/plugins/OpenID/openid.php';
40 * Lets users add, edit and delete OpenIDs from their account
44 * @author Evan Prodromou <evan@status.net>
45 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46 * @link http://status.net/
49 class OpenidsettingsAction extends AccountSettingsAction
54 * @return string Page title
59 return _('OpenID settings');
63 * Instructions for use
65 * @return string Instructions for use
68 function getInstructions()
70 return _('[OpenID](%%doc.openid%%) lets you log into many sites' .
71 ' with the same user account.'.
72 ' Manage your associated OpenIDs from here.');
75 function showScripts()
77 parent::showScripts();
78 $this->autofocus('openid_url');
82 * Show the form for OpenID management
84 * We have one form with a few different submit buttons to do different things.
89 function showContent()
91 $user = common_current_user();
93 $this->elementStart('form', array('method' => 'post',
94 'id' => 'form_settings_openid_add',
95 'class' => 'form_settings',
97 common_local_url('openidsettings')));
98 $this->elementStart('fieldset', array('id' => 'settings_openid_add'));
99 $this->element('legend', null, _('Add OpenID'));
100 $this->hidden('token', common_session_token());
101 $this->element('p', 'form_guide',
102 _('If you want to add an OpenID to your account, ' .
103 'enter it in the box below and click "Add".'));
104 $this->elementStart('ul', 'form_data');
105 $this->elementStart('li');
106 $this->element('label', array('for' => 'openid_url'),
108 $this->element('input', array('name' => 'openid_url',
110 'id' => 'openid_url'));
111 $this->elementEnd('li');
112 $this->elementEnd('ul');
113 $this->element('input', array('type' => 'submit',
114 'id' => 'settings_openid_add_action-submit',
117 'value' => _('Add')));
118 $this->elementEnd('fieldset');
119 $this->elementEnd('form');
121 $oid = new User_openid();
123 $oid->user_id = $user->id;
129 $this->element('h2', null, _('Remove OpenID'));
131 if ($cnt == 1 && !$user->password) {
133 $this->element('p', 'form_guide',
134 _('Removing your only OpenID '.
135 'would make it impossible to log in! ' .
136 'If you need to remove it, '.
137 'add another OpenID first.'));
140 $this->elementStart('p');
141 $this->element('a', array('href' => $oid->canonical),
143 $this->elementEnd('p');
148 $this->element('p', 'form_guide',
149 _('You can remove an OpenID from your account '.
150 'by clicking the button marked "Remove".'));
153 while ($oid->fetch()) {
154 $this->elementStart('form',
155 array('method' => 'POST',
156 'id' => 'form_settings_openid_delete' . $idx,
157 'class' => 'form_settings',
159 common_local_url('openidsettings')));
160 $this->elementStart('fieldset');
161 $this->hidden('token', common_session_token());
162 $this->element('a', array('href' => $oid->canonical),
164 $this->element('input', array('type' => 'hidden',
165 'id' => 'openid_url'.$idx,
166 'name' => 'openid_url',
167 'value' => $oid->canonical));
168 $this->element('input', array('type' => 'submit',
169 'id' => 'remove'.$idx,
171 'class' => 'submit remove',
172 'value' => _('Remove')));
173 $this->elementEnd('fieldset');
174 $this->elementEnd('form');
182 * Handle a POST request
184 * Muxes to different sub-functions based on which button was pushed
189 function handlePost()
192 $token = $this->trimmed('token');
193 if (!$token || $token != common_session_token()) {
194 $this->showForm(_('There was a problem with your session token. '.
195 'Try again, please.'));
199 if ($this->arg('add')) {
200 $result = oid_authenticate($this->trimmed('openid_url'),
202 if (is_string($result)) { // error message
203 $this->showForm($result);
205 } else if ($this->arg('remove')) {
206 $this->removeOpenid();
208 $this->showForm(_('Something weird happened.'));
213 * Handles a request to remove an OpenID from the user's account
215 * Validates input and, if everything is OK, deletes the OpenID.
216 * Reloads the form with a success or error notification.
221 function removeOpenid()
223 $openid_url = $this->trimmed('openid_url');
225 $oid = User_openid::staticGet('canonical', $openid_url);
228 $this->showForm(_('No such OpenID.'));
231 $cur = common_current_user();
232 if (!$cur || $oid->user_id != $cur->id) {
233 $this->showForm(_('That OpenID does not belong to you.'));
237 $this->showForm(_('OpenID removed.'), true);