logout.php 2.24 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('GNUSOCIAL')) { exit(1); }
Evan Prodromou's avatar
Evan Prodromou committed
32

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

55
    protected function doPreparation()
56
    {
57
        if (!common_logged_in()) {
58 59
            // TRANS: Error message displayed when trying to logout even though you are not logged in.
            throw new AlreadyFulfilledException(_('Cannot log you out if you are not logged in.'));
60
        }
61 62 63 64 65
        if (Event::handle('StartLogout', array($this))) {
            $this->logout();
        }
        Event::handle('EndLogout', array($this));

66
        common_redirect(common_local_url('top'));
67
    }
68

69 70
    // Accessed through the action on events
    public function logout()
71 72 73
    {
        common_set_user(null);
        common_real_login(false); // not logged in
74
        common_forgetme(); // don't log back in!
75
    }
Evan Prodromou's avatar
Evan Prodromou committed
76
}