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)
66 * Handle input, produce output
68 * Switches on request method; either shows the form or handles its input.
70 * @param array $args $_REQUEST data
75 function handle($args)
77 parent::handle($args);
78 if (common_is_real_login()) {
79 $this->clientError(_('Already logged in.'));
80 } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
83 common_ensure_session();
89 * Check the login data
91 * Determines if the login data is valid. If so, logs the user
92 * in, and redirects to the 'with friends' page, or to the stored
100 // XXX: login throttle
102 // CSRF protection - token set in NoticeForm
103 $token = $this->trimmed('token');
104 if (!$token || $token != common_session_token()) {
105 $this->clientError(_('There was a problem with your session token. '.
106 'Try again, please.'));
110 $nickname = common_canonical_nickname($this->trimmed('nickname'));
111 $password = $this->arg('password');
113 $user = common_check_user($nickname, $password);
116 $this->showForm(_('Incorrect username or password.'));
121 if (!common_set_user($user)) {
122 $this->serverError(_('Error setting user.'));
126 common_real_login(true);
128 if ($this->boolean('rememberme')) {
129 common_rememberme($user);
132 $url = common_get_returnto();
135 // We don't have to return to it again
136 common_set_returnto(null);
138 $url = common_local_url('all',
143 common_redirect($url, 303);
147 * Store an error and show the page
149 * This used to show the whole page; now, it's just a wrapper
150 * that stores the error in an attribute.
152 * @param string $error error, if any.
157 function showForm($error=null)
159 $this->error = $error;
163 function showScripts()
165 parent::showScripts();
166 $this->autofocus('nickname');
172 * @return string title of the page
183 * Display a notice for how to use the page, or the
184 * error if it exists.
189 function showPageNotice()
192 $this->element('p', 'error', $this->error);
194 $instr = $this->getInstructions();
195 $output = common_markup_to_html($instr);
202 * Core of the display code
204 * Shows the login form.
209 function showContent()
211 $this->elementStart('form', array('method' => 'post',
212 'id' => 'form_login',
213 'class' => 'form_settings',
214 'action' => common_local_url('login')));
215 $this->elementStart('fieldset');
216 $this->element('legend', null, _('Login to site'));
217 $this->elementStart('ul', 'form_data');
218 $this->elementStart('li');
219 $this->input('nickname', _('Nickname'));
220 $this->elementEnd('li');
221 $this->elementStart('li');
222 $this->password('password', _('Password'));
223 $this->elementEnd('li');
224 $this->elementStart('li');
225 $this->checkbox('rememberme', _('Remember me'), false,
226 _('Automatically login in the future; ' .
227 'not for shared computers!'));
228 $this->elementEnd('li');
229 $this->elementEnd('ul');
230 $this->submit('submit', _('Login'));
231 $this->hidden('token', common_session_token());
232 $this->elementEnd('fieldset');
233 $this->elementEnd('form');
234 $this->elementStart('p');
235 $this->element('a', array('href' => common_local_url('recoverpassword')),
236 _('Lost or forgotten password?'));
237 $this->elementEnd('p');
241 * Instructions for using the form
243 * For "remembered" logins, we make the user re-login when they
244 * try to change settings. Different instructions for this case.
249 function getInstructions()
251 if (common_logged_in() && !common_is_real_login() &&
252 common_get_returnto()) {
253 // rememberme logins have to reauthenticate before
254 // changing any profile settings (cookie-stealing protection)
255 return _('For security reasons, please re-enter your ' .
256 'user name and password ' .
257 'before changing your settings.');
259 return _('Login with your username and password. ' .
260 'Don\'t have a username yet? ' .
261 '[Register](%%action.register%%) a new account.');
268 * Shows different login/register actions.
273 function showLocalNav()
275 $nav = new LoginGroupNav($this);