3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, 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('STATUSNET') && !defined('LACONICA')) { exit(1); }
22 require_once INSTALLDIR.'/plugins/OpenID/openid.php';
24 class OpenidloginAction extends Action
26 function handle($args)
28 parent::handle($args);
29 if (common_is_real_login()) {
30 // TRANS: Client error message trying to log on with OpenID while already logged on.
31 $this->clientError(_m('Already logged in.'));
32 } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
33 $provider = common_config('openid', 'trusted_provider');
35 $openid_url = $provider;
36 if (common_config('openid', 'append_username')) {
37 $openid_url .= $this->trimmed('openid_username');
40 $openid_url = $this->trimmed('openid_url');
43 oid_assert_allowed($openid_url);
46 $token = $this->trimmed('token');
47 if (!$token || $token != common_session_token()) {
48 // TRANS: Message given when there is a problem with the user's session token.
49 $this->showForm(_m('There was a problem with your session token. Try again, please.'), $openid_url);
53 $rememberme = $this->boolean('rememberme');
55 common_ensure_session();
57 $_SESSION['openid_rememberme'] = $rememberme;
59 $result = oid_authenticate($openid_url,
62 if (is_string($result)) { # error message
63 unset($_SESSION['openid_rememberme']);
64 $this->showForm($result, $openid_url);
67 $openid_url = oid_get_last();
68 $this->showForm(null, $openid_url);
72 function getInstructions()
74 if (common_logged_in() && !common_is_real_login() &&
75 common_get_returnto()) {
76 // rememberme logins have to reauthenticate before
77 // changing any profile settings (cookie-stealing protection)
78 // TRANS: OpenID plugin message. Rememberme logins have to reauthenticate before changing any profile settings.
79 // TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
80 return _m('For security reasons, please re-login with your ' .
81 '[OpenID](%%doc.openid%%) ' .
82 'before changing your settings.');
84 // TRANS: OpenID plugin message.
85 // TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
86 return _m('Login with an [OpenID](%%doc.openid%%) account.');
90 function showPageNotice()
93 $this->element('div', array('class' => 'error'), $this->error);
95 $instr = $this->getInstructions();
96 $output = common_markup_to_html($instr);
97 $this->elementStart('div', 'instructions');
99 $this->elementEnd('div');
103 function showScripts()
105 parent::showScripts();
106 if (common_config('openid', 'trusted_provider')) {
107 if (common_config('openid', 'append_username')) {
108 $this->autofocus('openid_username');
110 $this->autofocus('rememberme');
113 $this->autofocus('openid_url');
119 // TRANS: OpenID plugin message. Title.
120 return _m('OpenID Login');
123 function showForm($error=null, $openid_url)
125 $this->error = $error;
126 $this->openid_url = $openid_url;
130 function showContent() {
131 $formaction = common_local_url('openidlogin');
132 $this->elementStart('form', array('method' => 'post',
133 'id' => 'form_openid_login',
134 'class' => 'form_settings',
135 'action' => $formaction));
136 $this->elementStart('fieldset');
137 // TRANS: OpenID plugin logon form legend.
138 $this->element('legend', null, _m('OpenID login'));
139 $this->hidden('token', common_session_token());
141 $this->elementStart('ul', 'form_data');
142 $this->elementStart('li');
143 $provider = common_config('openid', 'trusted_provider');
144 $appendUsername = common_config('openid', 'append_username');
146 $this->element('label', array(), _m('OpenID provider'));
147 $this->element('span', array(), $provider);
148 if ($appendUsername) {
149 $this->element('input', array('id' => 'openid_username',
150 'name' => 'openid_username',
151 'style' => 'float: none'));
153 $this->element('p', 'form_guide',
154 ($appendUsername ? _m('Enter your username.') . ' ' : '') .
155 _m('You will be sent to the provider\'s site for authentication.'));
156 $this->hidden('openid_url', $provider);
158 // TRANS: OpenID plugin logon form field label.
159 $this->input('openid_url', _m('OpenID URL'),
161 // TRANS: OpenID plugin logon form field instructions.
162 _m('Your OpenID URL'));
164 $this->elementEnd('li');
165 $this->elementStart('li', array('id' => 'settings_rememberme'));
166 // TRANS: OpenID plugin logon form checkbox label for setting to put the OpenID information in a cookie.
167 $this->checkbox('rememberme', _m('Remember me'), false,
168 // TRANS: OpenID plugin logon form field instructions.
169 _m('Automatically login in the future; ' .
170 'not for shared computers!'));
171 $this->elementEnd('li');
172 $this->elementEnd('ul');
173 // TRANS: OpenID plugin logon form button label to start logon with the data provided in the logon form.
174 $this->submit('submit', _m('BUTTON', 'Login'));
175 $this->elementEnd('fieldset');
176 $this->elementEnd('form');
179 function showLocalNav()
181 $nav = new LoginGroupNav($this);