xref: /dokuwiki/inc/Action/Logout.php (revision 177d6836e2f75d0e404be9c566e61725852a1e07)
1<?php
2
3namespace dokuwiki\Action;
4
5use dokuwiki\Action\Exception\ActionDisabledException;
6use dokuwiki\Action\Exception\ActionException;
7use dokuwiki\Extension\AuthPlugin;
8
9/**
10 * Class Logout
11 *
12 * Log out a user
13 *
14 * @package dokuwiki\Action
15 */
16class Logout extends AbstractUserAction
17{
18
19    /** @inheritdoc */
20    public function minimumPermission()
21    {
22        return AUTH_NONE;
23    }
24
25    /** @inheritdoc */
26    public function checkPreconditions()
27    {
28        parent::checkPreconditions();
29
30        /** @var AuthPlugin $auth */
31        global $auth;
32        if (!$auth->canDo('logout')) throw new ActionDisabledException();
33    }
34
35    /** @inheritdoc */
36    public function preProcess()
37    {
38        global $ID;
39        global $INPUT;
40
41        if (!checkSecurityToken()) throw new ActionException();
42
43        // when logging out during an edit session, unlock the page
44        $lockedby = checklock($ID);
45        if ($lockedby == $INPUT->server->str('REMOTE_USER')) {
46            unlock($ID);
47        }
48
49        // do the logout stuff and redirect to login
50        auth_logoff();
51        send_redirect(wl($ID, ['do' => 'login'], true, '&'));
52
53        // should never be reached
54        throw new ActionException('login');
55    }
56}
57