Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Logout
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3/**
4 * @package Zmsstatistic
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsstatistic;
9
10use App;
11use BO\Slim\Render;
12use BO\Zmsclient\Auth;
13use BO\Zmsclient\Exception;
14use Psr\Http\Message\RequestInterface;
15use Psr\Http\Message\ResponseInterface;
16
17class Logout extends BaseController
18{
19    protected int $resolveLevel = 0;
20    protected bool $withAccess = false;
21
22    /**
23     * @SuppressWarnings(Param)
24     * @return \Psr\Http\Message\ResponseInterface
25     */
26    #[\Override]
27    public function readResponse(
28        RequestInterface $request,
29        ResponseInterface $response,
30        array $args
31    ): ResponseInterface {
32        $workstation = null;
33        try {
34            /** @var mixed $workstation */
35            $workstation = \App::http()->readGetResult('/workstation/', ['resolveReferences' => 0])->getEntity();
36            \App::http()->readDeleteResult('/workstation/login/' . $workstation->useraccount['id'] . '/')->getEntity();
37        } catch (Exception $exception) {
38            if ("BO\Zmsentities\Exception\UseraccountMissingLogin" !== $exception->template) {
39                throw $exception;
40            }
41        }
42        /** @var mixed $workstation */
43        /** @var mixed $authKey */
44        $authKey = Auth::getKey();
45        $sessionHash = hash('sha256', $authKey);
46        $username = null;
47        if ($workstation !== null) {
48            $username = $workstation->useraccount['id'];
49        }
50        App::$log->info('User logged out', [
51            'event' => 'auth_logout',
52            'timestamp' => date('c'),
53            'username' => $username,
54            'hashed_session_token' => $sessionHash,
55            'logout_type' => 'manual',
56            'application' => 'zmsstatistic'
57        ]);
58        Auth::removeKey();
59        return Render::withHtml(
60            $response,
61            'page/logout.twig',
62            array(
63                'title' => 'Erfolgreich abgemeldet'
64            )
65        );
66    }
67}