aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/logout.php
blob: 22a93f09bb11cadd53168a7e6e2b6bc76f9bb317 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
 * logout.php - logout
 *
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * @author      André Noack <noack@data-quest.de>
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 */
class LogoutController extends AuthenticatedController
{
    protected $allow_nobody = true;

    public function index_action()
    {
        if ($GLOBALS['user']->id !== 'nobody') {
            $my_messaging_settings = $GLOBALS['user']->cfg->MESSAGING_SETTINGS;

            //Wenn Option dafuer gewaehlt, alle ungelsesenen Nachrichten als gelesen speichern
            if ($my_messaging_settings["logout_markreaded"]) {
                Message::markAllAs();
            }

            $logout_user = $GLOBALS['user']->id;
            $_language = $_SESSION['_language'];
            $contrast = UserConfig::get($GLOBALS['user']->id)->USER_HIGH_CONTRAST;

            // Get auth plugin of user before logging out since the $auth object will
            // be modified by the logout
            $auth_plugin = StudipAuthAbstract::getInstance($GLOBALS['user']->auth_plugin);

            sess()->destroy();
            //Session changed zuruecksetzen
            $timeout=(time()-(15 * 60));
            $GLOBALS['user']->set_last_action($timeout);

            // Perform logout from auth plugin (if possible)
            if ($auth_plugin instanceof StudipAuthSSO) {
                $auth_plugin->logout();
            }

            sess()->start();
            $_SESSION['_language'] = $_language;
            if ($contrast) {
                $_SESSION['contrast'] = $contrast;
            }
            NotificationCenter::addObserver(function() {
                throw new NotificationVetoException();
            }, '__invoke', 'PageCloseWillExecute');
            PageLayout::postSuccess(
                _('Sie sind nun aus dem System abgemeldet.'),
                array_filter([$GLOBALS['UNI_LOGOUT_ADD']])
            );
        }

        $this->redirect(URLHelper::getURL('dispatch.php/start'));
    }
}