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