aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/logout.php
blob: cf0409d716201295280c3a76fcf4ec1f238b26ae (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
64
65
66
67
68
69
70
71
72
73
74
75
76
<?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 (
            !Request::isPost()
            && !(
                isset($_SESSION['logout_ticket'])
                && check_ticket($_SESSION['logout_ticket'])
            )
        ) {
            $this->redirect(URLHelper::getURL('dispatch.php/start'));
            return;
        }

        $user = User::findCurrent();
        if ($user) {
            $my_messaging_settings = $user->getConfiguration()->getValue('MESSAGING_SETTINGS');

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

            $_language = $_SESSION['_language'];
            $contrast = $user->getConfiguration()->getValue('USER_HIGH_CONTRAST');

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

            sess()->destroy();

            //Session changed zuruecksetzen
            $timeout = strtotime('-15 minutes');
            $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'));
    }
}