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