xref: /webtrees/app/Http/RequestHandlers/Logout.php (revision d403609d9adfb78373074e21cba0e7fd0ec71fde)
1*d403609dSGreg Roach<?php
2*d403609dSGreg Roach
3*d403609dSGreg Roach/**
4*d403609dSGreg Roach * webtrees: online genealogy
5*d403609dSGreg Roach * Copyright (C) 2019 webtrees development team
6*d403609dSGreg Roach * This program is free software: you can redistribute it and/or modify
7*d403609dSGreg Roach * it under the terms of the GNU General Public License as published by
8*d403609dSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9*d403609dSGreg Roach * (at your option) any later version.
10*d403609dSGreg Roach * This program is distributed in the hope that it will be useful,
11*d403609dSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*d403609dSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*d403609dSGreg Roach * GNU General Public License for more details.
14*d403609dSGreg Roach * You should have received a copy of the GNU General Public License
15*d403609dSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16*d403609dSGreg Roach */
17*d403609dSGreg Roachdeclare(strict_types=1);
18*d403609dSGreg Roach
19*d403609dSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
20*d403609dSGreg Roach
21*d403609dSGreg Roachuse Fisharebest\Webtrees\Auth;
22*d403609dSGreg Roachuse Fisharebest\Webtrees\FlashMessages;
23*d403609dSGreg Roachuse Fisharebest\Webtrees\I18N;
24*d403609dSGreg Roachuse Fisharebest\Webtrees\Log;
25*d403609dSGreg Roachuse Fisharebest\Webtrees\Tree;
26*d403609dSGreg Roachuse Fisharebest\Webtrees\User;
27*d403609dSGreg Roachuse Psr\Http\Message\ResponseInterface;
28*d403609dSGreg Roachuse Psr\Http\Message\ServerRequestInterface;
29*d403609dSGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
30*d403609dSGreg Roachuse function redirect;
31*d403609dSGreg Roachuse function route;
32*d403609dSGreg Roach
33*d403609dSGreg Roach/**
34*d403609dSGreg Roach * Perform a logout.
35*d403609dSGreg Roach */
36*d403609dSGreg Roachclass Logout implements RequestHandlerInterface
37*d403609dSGreg Roach{
38*d403609dSGreg Roach    /**
39*d403609dSGreg Roach     * @param ServerRequestInterface $request
40*d403609dSGreg Roach     *
41*d403609dSGreg Roach     * @return ResponseInterface
42*d403609dSGreg Roach     */
43*d403609dSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
44*d403609dSGreg Roach    {
45*d403609dSGreg Roach        $tree = $request->getAttribute('tree');
46*d403609dSGreg Roach        $user = $request->getAttribute('user');
47*d403609dSGreg Roach
48*d403609dSGreg Roach        if ($user instanceof User) {
49*d403609dSGreg Roach            Log::addAuthenticationLog('Logout: ' . Auth::user()->userName() . '/' . Auth::user()->realName());
50*d403609dSGreg Roach            Auth::logout();
51*d403609dSGreg Roach            FlashMessages::addMessage(I18N::translate('You have signed out.'));
52*d403609dSGreg Roach        }
53*d403609dSGreg Roach
54*d403609dSGreg Roach        if ($tree instanceof Tree) {
55*d403609dSGreg Roach            return redirect(route('tree-page', ['ged' => $tree->name()]));
56*d403609dSGreg Roach        }
57*d403609dSGreg Roach
58*d403609dSGreg Roach        return redirect(route('tree-page'));
59*d403609dSGreg Roach    }
60*d403609dSGreg Roach}
61