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
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);
47 $rememberme = $this->boolean('rememberme');
49 common_ensure_session();
51 $_SESSION['openid_rememberme'] = $rememberme;
53 $result = oid_authenticate($openid_url,
56 if (is_string($result)) { # error message
57 unset($_SESSION['openid_rememberme']);
58 $this->showForm($result, $openid_url);
61 $openid_url = oid_get_last();
62 $this->showForm(null, $openid_url);
66 function getInstructions()
68 if (common_logged_in() && !common_is_real_login() &&
69 common_get_returnto()) {
70 // rememberme logins have to reauthenticate before
71 // changing any profile settings (cookie-stealing protection)
72 // TRANS: OpenID plugin message. Rememberme logins have to reauthenticate before changing any profile settings.
73 // TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
74 return _m('For security reasons, please re-login with your ' .
75 '[OpenID](%%doc.openid%%) ' .
76 'before changing your settings.');
78 // TRANS: OpenID plugin message.
79 // TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
80 return _m('Login with an [OpenID](%%doc.openid%%) account.');
84 function showPageNotice()
87 $this->element('div', array('class' => 'error'), $this->error);
89 $instr = $this->getInstructions();
90 $output = common_markup_to_html($instr);
91 $this->elementStart('div', 'instructions');
93 $this->elementEnd('div');
97 function showScripts()
99 parent::showScripts();
100 if (common_config('openid', 'trusted_provider')) {
101 if (common_config('openid', 'append_username')) {
102 $this->autofocus('openid_username');
104 $this->autofocus('rememberme');
107 $this->autofocus('openid_url');
113 // TRANS: OpenID plugin message. Title.
114 return _m('TITLE','OpenID Login');
117 function showForm($error=null, $openid_url)
119 $this->error = $error;
120 $this->openid_url = $openid_url;
124 function showContent() {
125 $formaction = common_local_url('openidlogin');
126 $this->elementStart('form', array('method' => 'post',
127 'id' => 'form_openid_login',
128 'class' => 'form_settings',
129 'action' => $formaction));
130 $this->elementStart('fieldset');
131 // TRANS: OpenID plugin logon form legend.
132 $this->element('legend', null, _m('LEGEND','OpenID login'));
134 $this->elementStart('ul', 'form_data');
135 $this->elementStart('li');
136 $provider = common_config('openid', 'trusted_provider');
137 $appendUsername = common_config('openid', 'append_username');
139 // TRANS: Field label.
140 $this->element('label', [], _m('LABEL','OpenID provider'));
141 $this->element('span', [], $provider);
142 if ($appendUsername) {
143 $this->element('input', array('id' => 'openid_username',
144 'name' => 'openid_username',
145 'style' => 'float: none'));
147 $this->element('p', 'form_guide',
148 // TRANS: Form guide.
149 ($appendUsername ? _m('Enter your username.') . ' ' : '') .
150 // TRANS: Form guide.
151 _m('You will be sent to the provider\'s site for authentication.'));
152 $this->hidden('openid_url', $provider);
154 // TRANS: OpenID plugin logon form field label.
155 $this->input('openid_url', _m('OpenID URL'),
157 // TRANS: OpenID plugin logon form field title.
158 _m('Your OpenID URL.'));
160 $this->elementEnd('li');
161 $this->elementStart('li', array('id' => 'settings_rememberme'));
162 // TRANS: OpenID plugin logon form checkbox label for setting to put the OpenID information in a cookie.
163 $this->checkbox('rememberme', _m('Remember me'), false,
164 // TRANS: OpenID plugin logon form field title.
165 _m('Automatically login in the future; ' .
166 'not for shared computers!'));
167 $this->elementEnd('li');
168 $this->elementEnd('ul');
169 // TRANS: OpenID plugin logon form button label to start logon with the data provided in the logon form.
170 $this->submit('submit', _m('BUTTON', 'Login'));
171 $this->elementEnd('fieldset');
172 $this->elementEnd('form');
175 function showLocalNav()
177 $nav = new LoginGroupNav($this);
181 function showNoticeForm()
185 function showProfileBlock()