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 */ 16*8c7c53b0SAndreas Gohrclass Logout extends AbstractUserAction 17*8c7c53b0SAndreas Gohr{ 1864ab5140SAndreas Gohr 1964ab5140SAndreas Gohr /** @inheritdoc */ 20ec701221SAndreas Gohr public function minimumPermission() { 2164ab5140SAndreas Gohr return AUTH_NONE; 2264ab5140SAndreas Gohr } 2364ab5140SAndreas Gohr 2464ab5140SAndreas Gohr /** @inheritdoc */ 25b2c9cd19SAndreas Gohr public function checkPreconditions() { 26b2c9cd19SAndreas Gohr parent::checkPreconditions(); 27480336a3SAndreas Gohr 2879a2d784SGerrit Uitslag /** @var AuthPlugin $auth */ 29480336a3SAndreas Gohr global $auth; 30480336a3SAndreas Gohr if(!$auth->canDo('logout')) throw new ActionDisabledException(); 31480336a3SAndreas Gohr } 32480336a3SAndreas Gohr 33480336a3SAndreas Gohr /** @inheritdoc */ 3464ab5140SAndreas Gohr public function preProcess() { 3564ab5140SAndreas Gohr global $ID; 3664ab5140SAndreas Gohr global $INPUT; 3764ab5140SAndreas Gohr 386a25531dSAndreas Gohr if (!checkSecurityToken()) throw new ActionException(); 396a25531dSAndreas Gohr 4064ab5140SAndreas Gohr // when logging out during an edit session, unlock the page 4164ab5140SAndreas Gohr $lockedby = checklock($ID); 4264ab5140SAndreas Gohr if($lockedby == $INPUT->server->str('REMOTE_USER')) { 4364ab5140SAndreas Gohr unlock($ID); 4464ab5140SAndreas Gohr } 4564ab5140SAndreas Gohr 4664ab5140SAndreas Gohr // do the logout stuff and redirect to login 4764ab5140SAndreas Gohr auth_logoff(); 486723156fSAndreas Gohr send_redirect(wl($ID, ['do' => 'login'], true, '&')); 4964ab5140SAndreas Gohr 5064ab5140SAndreas Gohr // should never be reached 5164ab5140SAndreas Gohr throw new ActionException('login'); 5264ab5140SAndreas Gohr } 5364ab5140SAndreas Gohr} 54