]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/login.php
Merge branch 'master' into 'nightly'
[quix0rs-gnu-social.git] / actions / login.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Login form
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Login
23  * @package   GNUsocial
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/
31  */
32
33 if (!defined('GNUSOCIAL')) { exit(1); }
34
35 class LoginAction extends FormAction
36 {
37     protected $needLogin = false;
38
39     /**
40      * Handle input, produce output
41      *
42      * Switches on request method; either shows the form or handles its input.
43      *
44      * @return void
45      */
46     protected function handle()
47     {
48         if (common_is_real_login()) {
49             common_redirect(common_local_url('all', array('nickname' => $this->scoped->nickname)), 307);
50         }
51
52         return parent::handle();
53     }
54
55     /**
56      * Check the login data
57      *
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
60      * return-to URL.
61      *
62      * @return void
63      */
64     protected function doPost()
65     {
66         // XXX: login throttle
67
68         $nickname = $this->trimmed('nickname');
69         $password = $this->arg('password');
70
71         $user = common_check_user($nickname, $password);
72
73         if (!$user instanceof User) {
74             // TRANS: Form validation error displayed when trying to log in with incorrect credentials.
75             throw new ServerException(_('Incorrect username or password.'));
76         }
77
78         // success!
79         if (!common_set_user($user)) {
80             // TRANS: Server error displayed when during login a server error occurs.
81             throw new ServerException(_('Error setting user. You are probably not authorized.'));
82         }
83
84         common_real_login(true);
85         $this->updateScopedProfile(); 
86
87         if ($this->boolean('rememberme')) {
88             common_rememberme($user);
89         }
90
91         $url = common_get_returnto();
92
93         if ($url) {
94             // We don't have to return to it again
95             common_set_returnto(null);
96             $url = common_inject_session($url);
97         } else {
98             $url = common_local_url('all',
99                                     array('nickname' => $this->scoped->nickname));
100         }
101
102         common_redirect($url, 303);
103     }
104
105     function showScripts()
106     {
107         parent::showScripts();
108         $this->autofocus('nickname');
109     }
110
111     /**
112      * Title of the page
113      *
114      * @return string title of the page
115      */
116     function title()
117     {
118         // TRANS: Page title for login page.
119         return _('Login');
120     }
121
122     /**
123      * Core of the display code
124      *
125      * Shows the login form.
126      *
127      * @return void
128      */
129     function showContent()
130     {
131         $this->elementStart('form', array('method' => 'post',
132                                           'id' => 'form_login',
133                                           'class' => 'form_settings',
134                                           'action' => common_local_url('login')));
135         $this->elementStart('fieldset');
136         // TRANS: Form legend on login page.
137         $this->element('legend', null, _('Login to site'));
138         $this->elementStart('ul', 'form_data');
139         $this->elementStart('li');
140         // TRANS: Field label on login page.
141         $this->input('nickname', _('Username or email address'));
142         $this->elementEnd('li');
143         $this->elementStart('li');
144         // TRANS: Field label on login page.
145         $this->password('password', _('Password'));
146         $this->elementEnd('li');
147         $this->elementStart('li');
148         // TRANS: Checkbox label label on login page.
149         $this->checkbox('rememberme', _('Remember me'), false,
150                         // TRANS: Checkbox title on login page.
151                         _('Automatically login in the future; ' .
152                           'not for shared computers!'));
153         $this->elementEnd('li');
154         $this->elementEnd('ul');
155         // TRANS: Button text for log in on login page.
156         $this->submit('submit', _m('BUTTON','Login'));
157         $this->hidden('token', common_session_token());
158         $this->elementEnd('fieldset');
159         $this->elementEnd('form');
160         $this->elementStart('p');
161         $this->element('a', array('href' => common_local_url('recoverpassword')),
162                        // TRANS: Link text for link to "reset password" on login page.
163                        _('Lost or forgotten password?'));
164         $this->elementEnd('p');
165     }
166
167     /**
168      * Instructions for using the form
169      *
170      * For "remembered" logins, we make the user re-login when they
171      * try to change settings. Different instructions for this case.
172      *
173      * @return void
174      */
175     protected function getInstructions()
176     {
177         if (common_logged_in() && !common_is_real_login() &&
178             common_get_returnto()) {
179             // rememberme logins have to reauthenticate before
180             // changing any profile settings (cookie-stealing protection)
181             // TRANS: Form instructions on login page before being able to change user settings.
182             return _('For security reasons, please re-enter your ' .
183                      'user name and password ' .
184                      'before changing your settings.');
185         } else {
186             // TRANS: Form instructions on login page.
187             $prompt = _('Login with your username and password.');
188             if (!common_config('site', 'closed') && !common_config('site', 'inviteonly')) {
189                 $prompt .= ' ';
190                 // TRANS: Form instructions on login page. This message contains Markdown links in the form [Link text](Link).
191                 // TRANS: %%action.register%% is a link to the registration page.
192                 $prompt .= _('Don\'t have a username yet? ' .
193                              '[Register](%%action.register%%) a new account.');
194             }
195             return $prompt;
196         }
197     }
198
199     /**
200      * A local menu
201      *
202      * Shows different login/register actions.
203      *
204      * @return void
205      */
206     function showLocalNav()
207     {
208         $nav = new LoginGroupNav($this);
209         $nav->show();
210     }
211
212     function showNoticeForm()
213     {
214     }
215
216     function showProfileBlock()
217     {
218     }
219 }