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 * @author Sarven Capadisli <csarven@status.net>
26 * @copyright 2008-2009 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
40 * @author Evan Prodromou <evan@status.net>
41 * @author Sarven Capadisli <csarven@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
46 class LoginAction extends Action
49 * Has there been an error?
55 * Is this a read-only action?
57 * @return boolean false
60 function isReadOnly($args)
70 * @return string title
73 function prepare($args)
75 parent::prepare($args);
77 // @todo this check should really be in index.php for all sensitive actions
78 $ssl = common_config('site', 'ssl');
79 if (empty($_SERVER['HTTPS']) && ($ssl == 'always' || $ssl == 'sometimes')) {
80 common_redirect(common_local_url('login'));
88 * Handle input, produce output
90 * Switches on request method; either shows the form or handles its input.
92 * @param array $args $_REQUEST data
97 function handle($args)
99 parent::handle($args);
101 if (common_is_real_login()) {
102 $this->clientError(_('Already logged in.'));
103 } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
106 common_ensure_session();
112 * Check the login data
114 * Determines if the login data is valid. If so, logs the user
115 * in, and redirects to the 'with friends' page, or to the stored
121 function checkLogin($user_id=null)
123 // XXX: login throttle
125 $nickname = $this->trimmed('nickname');
126 $password = $this->arg('password');
128 $user = common_check_user($nickname, $password);
131 $this->showForm(_('Incorrect username or password.'));
136 if (!common_set_user($user)) {
137 $this->serverError(_('Error setting user. You are probably not authorized.'));
141 common_real_login(true);
143 if ($this->boolean('rememberme')) {
144 common_rememberme($user);
147 $url = common_get_returnto();
150 // We don't have to return to it again
151 common_set_returnto(null);
152 $url = common_inject_session($url);
154 $url = common_local_url('all',
159 common_redirect($url, 303);
163 * Store an error and show the page
165 * This used to show the whole page; now, it's just a wrapper
166 * that stores the error in an attribute.
168 * @param string $error error, if any.
173 function showForm($error=null)
175 $this->error = $error;
179 function showScripts()
181 parent::showScripts();
182 $this->autofocus('nickname');
188 * @return string title of the page
199 * Display a notice for how to use the page, or the
200 * error if it exists.
205 function showPageNotice()
208 $this->element('p', 'error', $this->error);
210 $instr = $this->getInstructions();
211 $output = common_markup_to_html($instr);
218 * Core of the display code
220 * Shows the login form.
225 function showContent()
227 $this->elementStart('form', array('method' => 'post',
228 'id' => 'form_login',
229 'class' => 'form_settings',
230 'action' => common_local_url('login')));
231 $this->elementStart('fieldset');
232 $this->element('legend', null, _('Login to site'));
233 $this->elementStart('ul', 'form_data');
234 $this->elementStart('li');
235 $this->input('nickname', _('Nickname'));
236 $this->elementEnd('li');
237 $this->elementStart('li');
238 $this->password('password', _('Password'));
239 $this->elementEnd('li');
240 $this->elementStart('li');
241 $this->checkbox('rememberme', _('Remember me'), false,
242 _('Automatically login in the future; ' .
243 'not for shared computers!'));
244 $this->elementEnd('li');
245 $this->elementEnd('ul');
246 $this->submit('submit', _('Login'));
247 $this->elementEnd('fieldset');
248 $this->elementEnd('form');
249 $this->elementStart('p');
250 $this->element('a', array('href' => common_local_url('recoverpassword')),
251 _('Lost or forgotten password?'));
252 $this->elementEnd('p');
256 * Instructions for using the form
258 * For "remembered" logins, we make the user re-login when they
259 * try to change settings. Different instructions for this case.
264 function getInstructions()
266 if (common_logged_in() && !common_is_real_login() &&
267 common_get_returnto()) {
268 // rememberme logins have to reauthenticate before
269 // changing any profile settings (cookie-stealing protection)
270 return _('For security reasons, please re-enter your ' .
271 'user name and password ' .
272 'before changing your settings.');
274 $prompt = _('Login with your username and password.');
275 if (!common_config('site', 'closed') && !common_config('site', 'inviteonly')) {
277 $prompt .= _('Don\'t have a username yet? ' .
278 '[Register](%%action.register%%) a new account.');
287 * Shows different login/register actions.
292 function showLocalNav()
294 $nav = new LoginGroupNav($this);