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 * @author Mikael Nordfeldth <mmn@hethane.se>
27 * @copyright 2008-2009 StatusNet, Inc.
28 * @copyright 2013 Free Software Foundation, Inc.
29 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
30 * @link http://www.gnu.org/software/social/
33 if (!defined('GNUSOCIAL')) { exit(1); }
35 class LoginAction extends FormAction
37 protected $needLogin = false;
40 * Handle input, produce output
42 * Switches on request method; either shows the form or handles its input.
46 protected function handle()
48 if (common_is_real_login()) {
49 common_redirect(common_local_url('all', array('nickname' => $this->scoped->nickname)), 307);
52 return parent::handle();
56 * Check the login data
58 * Determines if the login data is valid. If so, logs the user
59 * in, and redirects to the 'with friends' page, or to the stored
64 protected function handlePost()
68 // XXX: login throttle
70 $nickname = $this->trimmed('nickname');
71 $password = $this->arg('password');
73 $user = common_check_user($nickname, $password);
75 if (!$user instanceof User) {
76 // TRANS: Form validation error displayed when trying to log in with incorrect credentials.
77 throw new ServerException(_('Incorrect username or password.'));
81 if (!common_set_user($user)) {
82 // TRANS: Server error displayed when during login a server error occurs.
83 throw new ServerException(_('Error setting user. You are probably not authorized.'));
86 common_real_login(true);
87 $this->updateScopedProfile();
89 if ($this->boolean('rememberme')) {
90 common_rememberme($user);
93 $url = common_get_returnto();
96 // We don't have to return to it again
97 common_set_returnto(null);
98 $url = common_inject_session($url);
100 $url = common_local_url('all',
101 array('nickname' => $this->scoped->nickname));
104 common_redirect($url, 303);
108 * Store an error and show the page
110 * This used to show the whole page; now, it's just a wrapper
111 * that stores the error in an attribute.
113 * @param string $error error, if any.
117 public function showForm($msg=null, $success=false)
119 common_ensure_session();
120 return parent::showForm($msg, $success);
123 function showScripts()
125 parent::showScripts();
126 $this->autofocus('nickname');
132 * @return string title of the page
136 // TRANS: Page title for login page.
141 * Core of the display code
143 * Shows the login form.
147 function showContent()
149 $this->elementStart('form', array('method' => 'post',
150 'id' => 'form_login',
151 'class' => 'form_settings',
152 'action' => common_local_url('login')));
153 $this->elementStart('fieldset');
154 // TRANS: Form legend on login page.
155 $this->element('legend', null, _('Login to site'));
156 $this->elementStart('ul', 'form_data');
157 $this->elementStart('li');
158 // TRANS: Field label on login page.
159 $this->input('nickname', _('Username or email address'));
160 $this->elementEnd('li');
161 $this->elementStart('li');
162 // TRANS: Field label on login page.
163 $this->password('password', _('Password'));
164 $this->elementEnd('li');
165 $this->elementStart('li');
166 // TRANS: Checkbox label label on login page.
167 $this->checkbox('rememberme', _('Remember me'), false,
168 // TRANS: Checkbox title on login page.
169 _('Automatically login in the future; ' .
170 'not for shared computers!'));
171 $this->elementEnd('li');
172 $this->elementEnd('ul');
173 // TRANS: Button text for log in on login page.
174 $this->submit('submit', _m('BUTTON','Login'));
175 $this->hidden('token', common_session_token());
176 $this->elementEnd('fieldset');
177 $this->elementEnd('form');
178 $this->elementStart('p');
179 $this->element('a', array('href' => common_local_url('recoverpassword')),
180 // TRANS: Link text for link to "reset password" on login page.
181 _('Lost or forgotten password?'));
182 $this->elementEnd('p');
186 * Instructions for using the form
188 * For "remembered" logins, we make the user re-login when they
189 * try to change settings. Different instructions for this case.
193 function getInstructions()
195 if (common_logged_in() && !common_is_real_login() &&
196 common_get_returnto()) {
197 // rememberme logins have to reauthenticate before
198 // changing any profile settings (cookie-stealing protection)
199 // TRANS: Form instructions on login page before being able to change user settings.
200 return _('For security reasons, please re-enter your ' .
201 'user name and password ' .
202 'before changing your settings.');
204 // TRANS: Form instructions on login page.
205 $prompt = _('Login with your username and password.');
206 if (!common_config('site', 'closed') && !common_config('site', 'inviteonly')) {
208 // TRANS: Form instructions on login page. This message contains Markdown links in the form [Link text](Link).
209 // TRANS: %%action.register%% is a link to the registration page.
210 $prompt .= _('Don\'t have a username yet? ' .
211 '[Register](%%action.register%%) a new account.');
220 * Shows different login/register actions.
224 function showLocalNav()
226 $nav = new LoginGroupNav($this);
230 function showNoticeForm()
234 function showProfileBlock()