Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
QuickLogin
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 1
 readResponse
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3/**
4 * @package Zmsstatistic
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsstatistic;
9
10use BO\Mellon\Validator;
11use BO\Zmsentities\Workstation;
12use BO\Zmsentities\Scope;
13use BO\Zmsentities\Useraccount;
14use BO\Zmsentities\Exception\QuickLoginFailed;
15use BO\Zmsclient\Exception;
16use Psr\Http\Message\RequestInterface;
17use Psr\Http\Message\ResponseInterface;
18
19class QuickLogin extends BaseController
20{
21    /**
22     * @SuppressWarnings(Param)
23     */
24    #[\Override]
25    public function readResponse(
26        RequestInterface $request,
27        ResponseInterface $response,
28        array $args
29    ): ResponseInterface {
30        $loginData = Helper\LoginForm::fromQuickLogin();
31        if ($loginData->hasFailed()) {
32            throw new QuickLoginFailed();
33        }
34        $loginData = $loginData->getStatus();
35        $userAccount = new Useraccount(array(
36            'id' => $loginData['loginName']['value'],
37            'password' => $loginData['password']['value']
38        ));
39
40        $workstation = null;
41        try {
42            /** @var mixed $workstation */
43            $workstation = \App::http()
44                ->readPostResult('/workstation/login/', $userAccount)->getEntity();
45        } catch (Exception $exception) {
46            //ignore double login exception on quick login
47            if ($exception->template == 'BO\Zmsbackend\Useraccount\Exception\UserAlreadyLoggedIn') {
48                $workstation = new Workstation($exception->data);
49            } else {
50                throw $exception;
51            }
52        }
53
54        /** @var mixed $workstation */
55        $workstation = $workstation;
56        /** @var mixed $authkey */
57        $authkey = $workstation->authkey;
58        \BO\Zmsclient\Auth::setKey($authkey, time() + \App::SESSION_DURATION);
59        $workstation->scope = new Scope(array('id' => $loginData['scope']['value']));
60        $workstation->hint = $loginData['hint']['value'];
61        $workstation->name = $loginData['workstation']['value'];
62        \App::http()->readPostResult('/workstation/', $workstation)->getEntity();
63        /** @var mixed $request */
64        $basePath = $request->getBasePath();
65
66        /** @var \BO\Slim\Response $response */
67        return $response->withRedirect($basePath . '/' . trim($loginData['redirectUrl']['value'], "/"));
68    }
69}