. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\FlashMessages; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Log; use Fisharebest\Webtrees\Tree; use Fisharebest\Webtrees\User; use InvalidArgumentException; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use function assert; use function redirect; use function route; /** * Perform a logout. */ class Logout implements RequestHandlerInterface { /** * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $tree = $request->getAttribute('tree'); assert($tree instanceof Tree, new InvalidArgumentException()); $user = $request->getAttribute('user'); if ($user instanceof User) { Log::addAuthenticationLog('Logout: ' . Auth::user()->userName() . '/' . Auth::user()->realName()); Auth::logout(); FlashMessages::addMessage(I18N::translate('You have signed out.')); } if ($tree instanceof Tree) { return redirect(route('tree-page', ['tree' => $tree->name()])); } return redirect(route('tree-page')); } }