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 /** @inheritdoc */ 19*d868eb89SAndreas Gohr public function minimumPermission() 20*d868eb89SAndreas Gohr { 2164ab5140SAndreas Gohr return AUTH_NONE; 2264ab5140SAndreas Gohr } 2364ab5140SAndreas Gohr 2464ab5140SAndreas Gohr /** @inheritdoc */ 25*d868eb89SAndreas Gohr public function checkPreconditions() 26*d868eb89SAndreas Gohr { 27b2c9cd19SAndreas Gohr parent::checkPreconditions(); 28480336a3SAndreas Gohr 2979a2d784SGerrit Uitslag /** @var AuthPlugin $auth */ 30480336a3SAndreas Gohr global $auth; 31480336a3SAndreas Gohr if (!$auth->canDo('logout')) throw new ActionDisabledException(); 32480336a3SAndreas Gohr } 33480336a3SAndreas Gohr 34480336a3SAndreas Gohr /** @inheritdoc */ 35*d868eb89SAndreas Gohr public function preProcess() 36*d868eb89SAndreas Gohr { 3764ab5140SAndreas Gohr global $ID; 3864ab5140SAndreas Gohr global $INPUT; 3964ab5140SAndreas Gohr 406a25531dSAndreas Gohr if (!checkSecurityToken()) throw new ActionException(); 416a25531dSAndreas Gohr 4264ab5140SAndreas Gohr // when logging out during an edit session, unlock the page 4364ab5140SAndreas Gohr $lockedby = checklock($ID); 4464ab5140SAndreas Gohr if ($lockedby == $INPUT->server->str('REMOTE_USER')) { 4564ab5140SAndreas Gohr unlock($ID); 4664ab5140SAndreas Gohr } 4764ab5140SAndreas Gohr 4864ab5140SAndreas Gohr // do the logout stuff and redirect to login 4964ab5140SAndreas Gohr auth_logoff(); 506723156fSAndreas Gohr send_redirect(wl($ID, ['do' => 'login'], true, '&')); 5164ab5140SAndreas Gohr 5264ab5140SAndreas Gohr // should never be reached 5364ab5140SAndreas Gohr throw new ActionException('login'); 5464ab5140SAndreas Gohr } 5564ab5140SAndreas Gohr} 56