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 $openid_url = $this->trimmed('openid_url');
35 oid_assert_allowed($openid_url);
38 $token = $this->trimmed('token');
39 if (!$token || $token != common_session_token()) {
40 // TRANS: Message given when there is a problem with the user's session token.
41 $this->showForm(_m('There was a problem with your session token. Try again, please.'), $openid_url);
45 $rememberme = $this->boolean('rememberme');
47 common_ensure_session();
49 $_SESSION['openid_rememberme'] = $rememberme;
51 $result = oid_authenticate($openid_url,
54 if (is_string($result)) { # error message
55 unset($_SESSION['openid_rememberme']);
56 $this->showForm($result, $openid_url);
59 $openid_url = oid_get_last();
60 $this->showForm(null, $openid_url);
64 function getInstructions()
66 if (common_logged_in() && !common_is_real_login() &&
67 common_get_returnto()) {
68 // rememberme logins have to reauthenticate before
69 // changing any profile settings (cookie-stealing protection)
70 // TRANS: OpenID plugin message. Rememberme logins have to reauthenticate before changing any profile settings.
71 // TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
72 return _m('For security reasons, please re-login with your ' .
73 '[OpenID](%%doc.openid%%) ' .
74 'before changing your settings.');
76 // TRANS: OpenID plugin message.
77 // TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
78 return _m('Login with an [OpenID](%%doc.openid%%) account.');
82 function showPageNotice()
85 $this->element('div', array('class' => 'error'), $this->error);
87 $instr = $this->getInstructions();
88 $output = common_markup_to_html($instr);
89 $this->elementStart('div', 'instructions');
91 $this->elementEnd('div');
95 function showScripts()
97 parent::showScripts();
98 $this->autofocus('openid_url');
103 // TRANS: OpenID plugin message. Title.
104 return _m('OpenID Login');
107 function showForm($error=null, $openid_url)
109 $this->error = $error;
110 $this->openid_url = $openid_url;
114 function showContent() {
115 $formaction = common_local_url('openidlogin');
116 $this->elementStart('form', array('method' => 'post',
117 'id' => 'form_openid_login',
118 'class' => 'form_settings',
119 'action' => $formaction));
120 $this->elementStart('fieldset');
121 // TRANS: OpenID plugin logon form legend.
122 $this->element('legend', null, _m('OpenID login'));
123 $this->hidden('token', common_session_token());
125 $this->elementStart('ul', 'form_data');
126 $this->elementStart('li');
127 // TRANS: OpenID plugin logon form field label.
128 $this->input('openid_url', _m('OpenID URL'),
130 // TRANS: OpenID plugin logon form field instructions.
131 _m('Your OpenID URL'));
132 $this->elementEnd('li');
133 $this->elementStart('li', array('id' => 'settings_rememberme'));
134 // TRANS: OpenID plugin logon form checkbox label for setting to put the OpenID information in a cookie.
135 $this->checkbox('rememberme', _m('Remember me'), false,
136 // TRANS: OpenID plugin logon form field instructions.
137 _m('Automatically login in the future; ' .
138 'not for shared computers!'));
139 $this->elementEnd('li');
140 $this->elementEnd('ul');
141 // TRANS: OpenID plugin logon form button label to start logon with the data provided in the logon form.
142 $this->submit('submit', _m('BUTTON', 'Login'));
143 $this->elementEnd('fieldset');
144 $this->elementEnd('form');
147 function showLocalNav()
149 $nav = new LoginGroupNav($this);