. */ 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 { $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.')); } return redirect(route(HomePage::class)); } }