Lines
0.00%
0 / 17
Functions and Methods
0.00%
0 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ModuleAccess | 0.00% | 0 / 17 | 0.00% | 0 / 2 | 132 | 0.00% | 0 / 1 | |||
| rejectWrongModuleAccess | 0.00% | 0 / 12 | 0.00% | 0 / 1 | 56 | |||||
| endSession | 0.00% | 0 / 5 | 0.00% | 0 / 1 | 20 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsclient; | |
| 4 | ||
| 5 | use BO\Zmsentities\Workstation; | |
| 6 | use Psr\Http\Message\ResponseInterface; | |
| 7 | ||
| 8 | class ModuleAccess | |
| 9 | { | |
| 10 | public const string MODULE_ADMIN = 'zmsadmin'; | |
| 11 | ||
| 12 | public const string MODULE_STATISTIC = 'zmsstatistic'; | |
| 13 | ||
| 14 | public static function rejectWrongModuleAccess( | |
| 15 | string $application, | |
| 16 | Workstation $workstation, | |
| 17 | ResponseInterface $response | |
| 18 | ): ?ResponseInterface { | |
| 19 | $useraccount = $workstation->getUseraccount(); | |
| 20 | ||
| 21 | if ($useraccount->isSuperUser()) { | |
| 22 | return null; | |
| 23 | } | |
| 24 | ||
| 25 | $rejected = ($application === self::MODULE_STATISTIC && !$useraccount->hasPermissions(['statistic'])) | |
| 26 | || ($application === self::MODULE_ADMIN && $useraccount->hasExclusivePermission('statistic')); | |
| 27 | ||
| 28 | if ($rejected) { | |
| 29 | self::endSession($workstation); | |
| 30 | $template = $application === self::MODULE_ADMIN | |
| 31 | ? 'exception/bo/slim/exception/wrongmodulestatistic.twig' | |
| 32 | : 'exception/bo/slim/exception/wrongmoduleadmin.twig'; | |
| 33 | return \BO\Slim\Render::withHtml($response, $template, [], 403); | |
| 34 | } else { | |
| 35 | return null; | |
| 36 | } | |
| 37 | } | |
| 38 | ||
| 39 | private static function endSession(Workstation $workstation): void | |
| 40 | { | |
| 41 | try { | |
| 42 | $authKey = Auth::getKey(); | |
| 43 | if ($authKey !== null && $authKey !== '') { | |
| 44 | \App::$http->readDeleteResult('/workstation/login/' . $workstation->getUseraccount()['id'] . '/'); | |
| 45 | } | |
| 46 | } catch (\Exception $exception) { | |
| 47 | } | |
| 48 | ||
| 49 | Auth::removeKey(); | |
| 50 | } | |
| 51 | } |