logout.php 2.64 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1
<?php
Robin Millette's avatar
Robin Millette committed
2 3 4 5 6 7
/**
 * Logout action.
 *
 * PHP version 5
 *
 * @category Action
8
 * @package  StatusNet
9 10
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
Robin Millette's avatar
Robin Millette committed
11
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
13
 *
14
 * StatusNet - the distributed open-source microblogging tool
15
 * Copyright (C) 2008, 2009, StatusNet, Inc.
Evan Prodromou's avatar
Evan Prodromou committed
16
 *
Evan Prodromou's avatar
Evan Prodromou committed
17 18 19 20
 * This program is free software: you can redistribute it and/or modify
 * 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
21
 *
Evan Prodromou's avatar
Evan Prodromou committed
22 23 24 25
 * 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
26
 *
Evan Prodromou's avatar
Evan Prodromou committed
27 28 29 30
 * 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/>.
 */

31
if (!defined('STATUSNET') && !defined('LACONICA')) {
Robin Millette's avatar
Robin Millette committed
32 33
    exit(1);
}
Evan Prodromou's avatar
Evan Prodromou committed
34

Robin Millette's avatar
Robin Millette committed
35 36 37 38
/**
 * Logout action class.
 *
 * @category Action
39
 * @package  StatusNet
40 41
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
Robin Millette's avatar
Robin Millette committed
42
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
44
 */
45 46
class LogoutAction extends Action
{
Robin Millette's avatar
Robin Millette committed
47 48
    /**
     * This is read only.
49
     *
Robin Millette's avatar
Robin Millette committed
50 51
     * @return boolean true
     */
52
    function isReadOnly($args)
53
    {
54
        return false;
55
    }
Robin Millette's avatar
Robin Millette committed
56 57 58

    /**
     * Class handler.
59
     *
Robin Millette's avatar
Robin Millette committed
60 61 62 63
     * @param array $args array of arguments
     *
     * @return nothing
     */
64 65
    function handle($args)
    {
66 67
        parent::handle($args);
        if (!common_logged_in()) {
68
            // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
69
            $this->clientError(_('Not logged in.'));
70
        } else {
71 72 73 74 75
            if (Event::handle('StartLogout', array($this))) {
                $this->logout();
            }
            Event::handle('EndLogout', array($this));

76 77 78 79 80 81 82
            if (common_config('singleuser', 'enabled')) {
                $user = User::singleUser();
                common_redirect(common_local_url('showstream',
                                                 array('nickname' => $user->nickname)));
            } else {
                common_redirect(common_local_url('public'), 303);
            }
83 84
        }
    }
85 86 87 88 89

    function logout()
    {
        common_set_user(null);
        common_real_login(false); // not logged in
90
        common_forgetme(); // don't log back in!
91
    }
Evan Prodromou's avatar
Evan Prodromou committed
92
}