xref: /dokuwiki/inc/Action/Logout.php (revision d868eb89f182718a31113373a6272670bd7f8012)
164ab5140SAndreas Gohr<?php
264ab5140SAndreas Gohr
364ab5140SAndreas Gohrnamespace dokuwiki\Action;
464ab5140SAndreas Gohr
5480336a3SAndreas Gohruse dokuwiki\Action\Exception\ActionDisabledException;
664ab5140SAndreas Gohruse dokuwiki\Action\Exception\ActionException;
779a2d784SGerrit Uitslaguse dokuwiki\Extension\AuthPlugin;
864ab5140SAndreas Gohr
9ab583a1bSAndreas Gohr/**
10ab583a1bSAndreas Gohr * Class Logout
11ab583a1bSAndreas Gohr *
12ab583a1bSAndreas Gohr * Log out a user
13ab583a1bSAndreas Gohr *
14ab583a1bSAndreas Gohr * @package dokuwiki\Action
15ab583a1bSAndreas Gohr */
168c7c53b0SAndreas Gohrclass Logout extends AbstractUserAction
178c7c53b0SAndreas Gohr{
1864ab5140SAndreas Gohr
1964ab5140SAndreas Gohr    /** @inheritdoc */
20*d868eb89SAndreas Gohr    public function minimumPermission()
21*d868eb89SAndreas Gohr    {
2264ab5140SAndreas Gohr        return AUTH_NONE;
2364ab5140SAndreas Gohr    }
2464ab5140SAndreas Gohr
2564ab5140SAndreas Gohr    /** @inheritdoc */
26*d868eb89SAndreas Gohr    public function checkPreconditions()
27*d868eb89SAndreas Gohr    {
28b2c9cd19SAndreas Gohr        parent::checkPreconditions();
29480336a3SAndreas Gohr
3079a2d784SGerrit Uitslag        /** @var AuthPlugin $auth */
31480336a3SAndreas Gohr        global $auth;
32480336a3SAndreas Gohr        if(!$auth->canDo('logout')) throw new ActionDisabledException();
33480336a3SAndreas Gohr    }
34480336a3SAndreas Gohr
35480336a3SAndreas Gohr    /** @inheritdoc */
36*d868eb89SAndreas Gohr    public function preProcess()
37*d868eb89SAndreas Gohr    {
3864ab5140SAndreas Gohr        global $ID;
3964ab5140SAndreas Gohr        global $INPUT;
4064ab5140SAndreas Gohr
416a25531dSAndreas Gohr        if (!checkSecurityToken()) throw new ActionException();
426a25531dSAndreas Gohr
4364ab5140SAndreas Gohr        // when logging out during an edit session, unlock the page
4464ab5140SAndreas Gohr        $lockedby = checklock($ID);
4564ab5140SAndreas Gohr        if($lockedby == $INPUT->server->str('REMOTE_USER')) {
4664ab5140SAndreas Gohr            unlock($ID);
4764ab5140SAndreas Gohr        }
4864ab5140SAndreas Gohr
4964ab5140SAndreas Gohr        // do the logout stuff and redirect to login
5064ab5140SAndreas Gohr        auth_logoff();
516723156fSAndreas Gohr        send_redirect(wl($ID, ['do' => 'login'], true, '&'));
5264ab5140SAndreas Gohr
5364ab5140SAndreas Gohr        // should never be reached
5464ab5140SAndreas Gohr        throw new ActionException('login');
5564ab5140SAndreas Gohr    }
5664ab5140SAndreas Gohr}
57