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/
45 class LoginAction extends Action
48 * Has there been an error?
53 * Is this a read-only action?
55 * @return boolean false
57 function isReadOnly($args)
67 * @return string title
69 function prepare($args)
71 parent::prepare($args);
73 // @todo this check should really be in index.php for all sensitive actions
74 $ssl = common_config('site', 'ssl');
75 if (empty($_SERVER['HTTPS']) && ($ssl == 'always' || $ssl == 'sometimes')) {
76 common_redirect(common_local_url('login'));
84 * Handle input, produce output
86 * Switches on request method; either shows the form or handles its input.
88 * @param array $args $_REQUEST data
92 function handle($args)
94 parent::handle($args);
96 if (common_is_real_login()) {
97 common_redirect(common_local_url('index'));
98 } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
101 common_ensure_session();
107 * Check the login data
109 * Determines if the login data is valid. If so, logs the user
110 * in, and redirects to the 'with friends' page, or to the stored
115 function checkLogin($user_id=null, $token=null)
117 // XXX: login throttle
119 $nickname = $this->trimmed('nickname');
120 $password = $this->arg('password');
122 $user = common_check_user($nickname, $password);
125 // TRANS: Form validation error displayed when trying to log in with incorrect credentials.
126 $this->showForm(_('Incorrect username or password.'));
131 if (!common_set_user($user)) {
132 // TRANS: Server error displayed when during login a server error occurs.
133 $this->serverError(_('Error setting user. You are probably not authorized.'));
137 common_real_login(true);
139 if ($this->boolean('rememberme')) {
140 common_rememberme($user);
143 $url = common_get_returnto();
146 // We don't have to return to it again
147 common_set_returnto(null);
148 $url = common_inject_session($url);
150 $url = common_local_url('all',
155 common_redirect($url, 303);
159 * Store an error and show the page
161 * This used to show the whole page; now, it's just a wrapper
162 * that stores the error in an attribute.
164 * @param string $error error, if any.
168 function showForm($error=null)
170 $this->error = $error;
174 function showScripts()
176 parent::showScripts();
177 $this->autofocus('nickname');
183 * @return string title of the page
187 // TRANS: Page title for login page.
194 * Display a notice for how to use the page, or the
195 * error if it exists.
199 function showPageNotice()
202 $this->element('p', 'error', $this->error);
204 $instr = $this->getInstructions();
205 $output = common_markup_to_html($instr);
212 * Core of the display code
214 * Shows the login form.
218 function showContent()
220 $this->elementStart('form', array('method' => 'post',
221 'id' => 'form_login',
222 'class' => 'form_settings',
223 'action' => common_local_url('login')));
224 $this->elementStart('fieldset');
225 // TRANS: Form legend on login page.
226 $this->element('legend', null, _('Login to site'));
227 $this->elementStart('ul', 'form_data');
228 $this->elementStart('li');
229 // TRANS: Field label on login page.
230 $this->input('nickname', _('Username or email address'));
231 $this->elementEnd('li');
232 $this->elementStart('li');
233 // TRANS: Field label on login page.
234 $this->password('password', _('Password'));
235 $this->elementEnd('li');
236 $this->elementStart('li');
237 // TRANS: Checkbox label label on login page.
238 $this->checkbox('rememberme', _('Remember me'), false,
239 // TRANS: Checkbox title on login page.
240 _('Automatically login in the future; ' .
241 'not for shared computers!'));
242 $this->elementEnd('li');
243 $this->elementEnd('ul');
244 // TRANS: Button text for log in on login page.
245 $this->submit('submit', _m('BUTTON','Login'));
246 $this->elementEnd('fieldset');
247 $this->elementEnd('form');
248 $this->elementStart('p');
249 $this->element('a', array('href' => common_local_url('recoverpassword')),
250 // TRANS: Link text for link to "reset password" on login page.
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.
263 function getInstructions()
265 if (common_logged_in() && !common_is_real_login() &&
266 common_get_returnto()) {
267 // rememberme logins have to reauthenticate before
268 // changing any profile settings (cookie-stealing protection)
269 // TRANS: Form instructions on login page before being able to change user settings.
270 return _('For security reasons, please re-enter your ' .
271 'user name and password ' .
272 'before changing your settings.');
274 // TRANS: Form instructions on login page.
275 $prompt = _('Login with your username and password.');
276 if (!common_config('site', 'closed') && !common_config('site', 'inviteonly')) {
278 // TRANS: Form instructions on login page. This message contains Markdown links in the form [Link text](Link).
279 // TRANS: %%action.register%% is a link to the registration page.
280 $prompt .= _('Don\'t have a username yet? ' .
281 '[Register](%%action.register%%) a new account.');
290 * Shows different login/register actions.
294 function showLocalNav()
296 $nav = new LoginGroupNav($this);
300 function showNoticeForm()
304 function showProfileBlock()