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')) {
24 require_once INSTALLDIR.'/plugins/OpenID/openid.php';
26 class OpenidloginAction extends Action
28 function handle($args)
30 parent::handle($args);
31 if (common_is_real_login()) {
32 // TRANS: Client error message trying to log on with OpenID while already logged on.
33 $this->clientError(_m('Already logged in.'));
34 } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
35 $provider = common_config('openid', 'trusted_provider');
37 $openid_url = $provider;
38 if (common_config('openid', 'append_username')) {
39 $openid_url .= $this->trimmed('openid_username');
42 $openid_url = $this->trimmed('openid_url');
45 oid_assert_allowed($openid_url);
48 $token = $this->trimmed('token');
49 if (!$token || $token != common_session_token()) {
50 // TRANS: Message given when there is a problem with the user's session token.
51 $this->showForm(_m('There was a problem with your session token. Try again, please.'), $openid_url);
55 $rememberme = $this->boolean('rememberme');
57 common_ensure_session();
59 $_SESSION['openid_rememberme'] = $rememberme;
61 $result = oid_authenticate($openid_url,
64 if (is_string($result)) { # error message
65 unset($_SESSION['openid_rememberme']);
66 $this->showForm($result, $openid_url);
69 $openid_url = oid_get_last();
70 $this->showForm(null, $openid_url);
74 function getInstructions()
76 if (common_logged_in() && !common_is_real_login() &&
77 common_get_returnto()) {
78 // rememberme logins have to reauthenticate before
79 // changing any profile settings (cookie-stealing protection)
80 // TRANS: OpenID plugin message. Rememberme logins have to reauthenticate before changing any profile settings.
81 // TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
82 return _m('For security reasons, please re-login with your ' .
83 '[OpenID](%%doc.openid%%) ' .
84 'before changing your settings.');
86 // TRANS: OpenID plugin message.
87 // TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
88 return _m('Login with an [OpenID](%%doc.openid%%) account.');
92 function showPageNotice()
95 $this->element('div', array('class' => 'error'), $this->error);
97 $instr = $this->getInstructions();
98 $output = common_markup_to_html($instr);
99 $this->elementStart('div', 'instructions');
101 $this->elementEnd('div');
105 function showScripts()
107 parent::showScripts();
108 if (common_config('openid', 'trusted_provider')) {
109 if (common_config('openid', 'append_username')) {
110 $this->autofocus('openid_username');
112 $this->autofocus('rememberme');
115 $this->autofocus('openid_url');
121 // TRANS: OpenID plugin message. Title.
122 return _m('OpenID Login');
125 function showForm($error=null, $openid_url)
127 $this->error = $error;
128 $this->openid_url = $openid_url;
132 function showContent() {
133 $formaction = common_local_url('openidlogin');
134 $this->elementStart('form', array('method' => 'post',
135 'id' => 'form_openid_login',
136 'class' => 'form_settings',
137 'action' => $formaction));
138 $this->elementStart('fieldset');
139 // TRANS: OpenID plugin logon form legend.
140 $this->element('legend', null, _m('OpenID login'));
141 $this->hidden('token', common_session_token());
143 $this->elementStart('ul', 'form_data');
144 $this->elementStart('li');
145 $provider = common_config('openid', 'trusted_provider');
146 $appendUsername = common_config('openid', 'append_username');
148 $this->element('label', array(), _m('OpenID provider'));
149 $this->element('span', array(), $provider);
150 if ($appendUsername) {
151 $this->element('input', array('id' => 'openid_username',
152 'name' => 'openid_username',
153 'style' => 'float: none'));
155 $this->element('p', 'form_guide',
156 ($appendUsername ? _m('Enter your username.') . ' ' : '') .
157 _m('You will be sent to the provider\'s site for authentication.'));
158 $this->hidden('openid_url', $provider);
160 // TRANS: OpenID plugin logon form field label.
161 $this->input('openid_url', _m('OpenID URL'),
163 // TRANS: OpenID plugin logon form field instructions.
164 _m('Your OpenID URL'));
166 $this->elementEnd('li');
167 $this->elementStart('li', array('id' => 'settings_rememberme'));
168 // TRANS: OpenID plugin logon form checkbox label for setting to put the OpenID information in a cookie.
169 $this->checkbox('rememberme', _m('Remember me'), false,
170 // TRANS: OpenID plugin logon form field instructions.
171 _m('Automatically login in the future; ' .
172 'not for shared computers!'));
173 $this->elementEnd('li');
174 $this->elementEnd('ul');
175 // TRANS: OpenID plugin logon form button label to start logon with the data provided in the logon form.
176 $this->submit('submit', _m('BUTTON', 'Login'));
177 $this->elementEnd('fieldset');
178 $this->elementEnd('form');
181 function showLocalNav()
183 $nav = new LoginGroupNav($this);