git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

login.php 7.06 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1
<?php
2
/**
3
 * StatusNet, the distributed open-source microblogging tool
Evan Prodromou's avatar
Evan Prodromou committed
4
 *
5
 * Login form
6 7 8 9
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
10 11 12
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
Evan Prodromou's avatar
Evan Prodromou committed
13
 *
14 15 16 17
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
Evan Prodromou's avatar
Evan Prodromou committed
18
 *
19 20
 * You should have received a copy of the GNU Affero General Public License
 * 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 41 42 43 44 45
    /**
     * Handle input, produce output
     *
     * Switches on request method; either shows the form or handles its input.
     *
     * @return void
     */
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 57 58 59 60 61 62 63
    /**
     * Check the login data
     *
     * Determines if the login data is valid. If so, logs the user
     * in, and redirects to the 'with friends' page, or to the stored
     * return-to URL.
     *
     * @return void
     */
64
    protected function doPost()
65
    {
66 67 68 69 70 71 72
        // XXX: login throttle

        $nickname = $this->trimmed('nickname');
        $password = $this->arg('password');

        $user = common_check_user($nickname, $password);

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 88 89
        if ($this->boolean('rememberme')) {
            common_rememberme($user);
        }
90

91
        $url = common_get_returnto();
92

93
        if ($url) {
94
            // We don't have to return to it again
Evan Prodromou's avatar
Evan Prodromou committed
95
            common_set_returnto(null);
96
            $url = common_inject_session($url);
97 98
        } else {
            $url = common_local_url('all',
99
                                    array('nickname' => $this->scoped->nickname));
100
        }
101

102
        common_redirect($url, 303);
103
    }
Evan Prodromou's avatar
Evan Prodromou committed
104

105 106 107 108 109 110
    function showScripts()
    {
        parent::showScripts();
        $this->autofocus('nickname');
    }

111 112 113 114 115
    /**
     * Title of the page
     *
     * @return string title of the page
     */
116 117
    function title()
    {
118
        // TRANS: Page title for login page.
sarven's avatar
sarven committed
119
        return _('Login');
120 121
    }

122 123 124 125 126 127 128
    /**
     * Core of the display code
     *
     * Shows the login form.
     *
     * @return void
     */
129
    function showContent()
130
    {
131
        $this->elementStart('form', array('method' => 'post',
132 133 134
                                          'id' => 'form_login',
                                          'class' => 'form_settings',
                                          'action' => common_local_url('login')));
sarven's avatar
sarven committed
135
        $this->elementStart('fieldset');
136
        // TRANS: Form legend on login page.
sarven's avatar
sarven committed
137
        $this->element('legend', null, _('Login to site'));
sarven's avatar
sarven committed
138
        $this->elementStart('ul', 'form_data');
sarven's avatar
sarven committed
139
        $this->elementStart('li');
140
        // TRANS: Field label on login page.
141
        $this->input('nickname', _('Username or email address'));
sarven's avatar
sarven committed
142 143
        $this->elementEnd('li');
        $this->elementStart('li');
144
        // TRANS: Field label on login page.
145
        $this->password('password', _('Password'));
sarven's avatar
sarven committed
146 147
        $this->elementEnd('li');
        $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!'));
sarven's avatar
sarven committed
153 154
        $this->elementEnd('li');
        $this->elementEnd('ul');
155 156
        // TRANS: Button text for log in on login page.
        $this->submit('submit', _m('BUTTON','Login'));
157
        $this->hidden('token', common_session_token());
sarven's avatar
sarven committed
158
        $this->elementEnd('fieldset');
159 160 161
        $this->elementEnd('form');
        $this->elementStart('p');
        $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 169 170 171 172 173 174
    /**
     * Instructions for using the form
     *
     * For "remembered" logins, we make the user re-login when they
     * try to change settings. Different instructions for this case.
     *
     * @return void
     */
175
    protected function getInstructions()
176
    {
177 178 179 180
        if (common_logged_in() && !common_is_real_login() &&
            common_get_returnto()) {
            // rememberme logins have to reauthenticate before
            // changing any profile settings (cookie-stealing protection)
181
            // TRANS: Form instructions on login page before being able to change user settings.
182 183 184
            return _('For security reasons, please re-enter your ' .
                     'user name and password ' .
                     'before changing your settings.');
185
        } else {
186
            // TRANS: Form instructions on login page.
187 188 189
            $prompt = _('Login with your username and password.');
            if (!common_config('site', 'closed') && !common_config('site', 'inviteonly')) {
                $prompt .= ' ';
190 191
                // TRANS: Form instructions on login page. This message contains Markdown links in the form [Link text](Link).
                // TRANS: %%action.register%% is a link to the registration page.
192 193 194 195
                $prompt .= _('Don\'t have a username yet? ' .
                             '[Register](%%action.register%%) a new account.');
            }
            return $prompt;
196 197
        }
    }
198 199 200 201 202 203 204 205 206 207 208 209 210

    /**
     * A local menu
     *
     * Shows different login/register actions.
     *
     * @return void
     */
    function showLocalNav()
    {
        $nav = new LoginGroupNav($this);
        $nav->show();
    }
211 212 213 214

    function showNoticeForm()
    {
    }
215 216 217 218

    function showProfileBlock()
    {
    }
Evan Prodromou's avatar
Evan Prodromou committed
219
}