xref: /dokuwiki/inc/Action/Logout.php (revision 8c7c53b0321a3cd3116b8d3b2ad27863a38dece7)
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        return AUTH_NONE;
22    }
23
24    /** @inheritdoc */
25    public function checkPreconditions() {
26        parent::checkPreconditions();
27
28        /** @var AuthPlugin $auth */
29        global $auth;
30        if(!$auth->canDo('logout')) throw new ActionDisabledException();
31    }
32
33    /** @inheritdoc */
34    public function preProcess() {
35        global $ID;
36        global $INPUT;
37
38        if (!checkSecurityToken()) throw new ActionException();
39
40        // when logging out during an edit session, unlock the page
41        $lockedby = checklock($ID);
42        if($lockedby == $INPUT->server->str('REMOTE_USER')) {
43            unlock($ID);
44        }
45
46        // do the logout stuff and redirect to login
47        auth_logoff();
48        send_redirect(wl($ID, ['do' => 'login'], true, '&'));
49
50        // should never be reached
51        throw new ActionException('login');
52    }
53}
54