Exemplo n.º 1
0
 /**
  * @param userModel|modelBase $user
  *
  * @return array
  * @throws \mpcmf\modules\moduleBase\exceptions\mapperException
  * @throws \mpcmf\system\acl\exception\aclException
  * @throws \mpcmf\system\application\exception\webApplicationException
  */
 public function _token_generate($user = null)
 {
     $slim = $this->getSlim();
     if ($user === null) {
         $user = aclManager::getInstance()->getCurrentUser();
     }
     $tokenMapper = tokenMapper::getInstance();
     if ($slim->request()->isPost() && $slim->request->post('updateToken') === 'true') {
         try {
             /** @var tokenModel $tokenModel */
             $tokenModel = $tokenMapper->getBy([tokenMapper::FIELD__USER => $user->getUserId()]);
         } catch (mapperException $mapperException) {
             $tokenModel = tokenModel::fromArray([tokenMapper::FIELD__USER => $user->getUserId(), tokenMapper::FIELD__LIMIT => tokenMapper::DEFAULT_LIMIT]);
         }
         $tokenString = tokenManager::getInstance()->generateToken($tokenModel);
         $result = ['token' => $tokenString];
         $this->getSlim()->response()->header('Content-type', 'application/json');
         $this->getSlim()->response()->write(json_encode($result, JSON_UNESCAPED_UNICODE));
         $this->getSlim()->stop();
     }
     return self::nothing([]);
 }
Exemplo n.º 2
0
 private function registerActionsGroup()
 {
     $entityName = ltrim($this->getEntityUniqueName(), '/');
     $entityActions = array_keys($this->actions);
     $groupsListHash = md5($entityName . implode(',', $entityActions));
     $cacheKey = "action/groups/{$entityName}/{$groupsListHash}";
     MPCMF_LL_DEBUG && self::log()->addDebug("[{$entityName}] Checking action's groups registration... (key: {$cacheKey})");
     if (!cache::getCached($cacheKey)) {
         MPCMF_LL_DEBUG && self::log()->addDebug("[{$entityName}] Cached not found, building groups...");
         $entityAclGroups = [];
         /** @var action $actionData */
         foreach ($entityActions as $actionName) {
             $entityAclGroups[] = "{$entityName}/{$actionName}";
         }
         MPCMF_DEBUG && self::log()->addDebug("[{$entityName}] Registering action's groups: " . count($entityAclGroups));
         MPCMF_LL_DEBUG && self::log()->addDebug("[{$entityName}] Groups: " . implode(',', $entityAclGroups));
         aclManager::getInstance()->createGroupsByList($entityAclGroups);
         cache::setCached($cacheKey, true);
     } else {
         MPCMF_LL_DEBUG && self::log()->addDebug("[{$entityName}] Found registered groups, skipping");
     }
 }
Exemplo n.º 3
0
 public function _logout()
 {
     aclManager::getInstance()->removeUserCookie();
     $redirectUrl = $this->getSlim()->request()->get('redirectUrl');
     if (!$redirectUrl) {
         $redirectUrl = base64_encode('/');
     }
     return self::success(['redirectUrl' => $redirectUrl]);
 }
Exemplo n.º 4
0
 /**
  * @param                          $fieldName
  * @param modelBase|null           $model
  *
  * @return array
  * @throws \mpcmf\modules\moduleBase\exceptions\modelException
  * @throws \mpcmf\system\acl\exception\aclException
  * @throws mapperException
  */
 protected function relatedMapperCriteria($fieldName, modelBase $model = null)
 {
     /** @noinspection DegradedSwitchInspection */
     switch ($fieldName) {
         case self::FIELD__GROUPS:
             $currentUser = aclManager::getInstance()->getCurrentUser();
             if ($currentUser->isRoot()) {
                 $criteria = [];
                 break;
             }
             $groups = sdsAclManager::getInstance()->expandGroupsByCursor($currentUser->getGroups());
             $relationData = $this->getRelationData($fieldName);
             $criteria = [$relationData['field'] => ['$in' => $groups]];
             break;
         default:
             $criteria = [];
             break;
     }
     return $criteria;
 }
Exemplo n.º 5
0
 public function getMenuStructure($full = false, $reallyFull = false)
 {
     $aclManager = aclManager::getInstance();
     $groups = $aclManager->getCurrentUser()->getGroupIds();
     $cacheKey = 'webApp/sidebar/menu/' . md5(json_encode($groups));
     if (!($menu = cache::getCached($cacheKey))) {
         $homeMenuItem = ['path' => '/', 'name' => i18n::lang()->get('Главная')];
         $menu = [$homeMenuItem];
         foreach ($this->getAllModules() as $moduleName => $module) {
             $modulePath = "/{$moduleName}";
             $menuItem = ['path' => $modulePath, 'name' => $module->getName(), 'subitems' => []];
             $hasSubItemsAccess = false;
             /**
              * @var string $entityUniqueName
              * @var array  $entity
              */
             foreach ($module->getModuleRoutes()->getStructure() as $entityUniqueName => $entityData) {
                 /** @var modelBase $entityModel */
                 $entityModel = $entityData['entity'];
                 $subMenuItem = ['path' => $entityUniqueName, 'name' => $entityModel->getPublicName(), 'subitems' => []];
                 $hasSubSubItemsAccess = false;
                 /**
                  * @var string $actionName
                  * @var action $actionModel
                  */
                 foreach ($entityData['actions'] as $actionName => $actionModel) {
                     if (!$reallyFull && $actionModel->getType() !== action::TYPE__GLOBAL) {
                         continue;
                     }
                     $actionPath = preg_replace('/\\(.*\\)/', '', $actionModel->getPath());
                     if ($actionModel->isRelative()) {
                         $path = $actionModel->getActionUniqueName() . $actionPath;
                     } else {
                         $path = '/' . ltrim($actionPath, '/');
                     }
                     $hasAccess = $aclManager->checkActionAccess($actionModel)['status'];
                     if (!$hasSubSubItemsAccess && $hasAccess) {
                         $hasSubSubItemsAccess = true;
                     }
                     if ($full || $reallyFull || $hasAccess) {
                         $subSubMenuItem = ['path' => $path, 'name' => $actionModel->getName(), 'access' => $hasAccess];
                         $subMenuItem['subitems'][] = $subSubMenuItem;
                     }
                 }
                 $subMenuItem['hasSubItemsAccess'] = $hasSubSubItemsAccess;
                 if (!$hasSubItemsAccess && $hasSubSubItemsAccess) {
                     $hasSubItemsAccess = true;
                 }
                 if ($full || $reallyFull || $hasSubSubItemsAccess) {
                     $menuItem['subitems'][] = $subMenuItem;
                 }
             }
             $menuItem['hasSubItemsAccess'] = $hasSubItemsAccess;
             if ($full || $reallyFull || $hasSubItemsAccess) {
                 $menu[] = $menuItem;
             }
         }
         cache::setCached($cacheKey, $menu, 300);
     }
     $slim = $this->slim();
     $currentRoutePath = $slim->urlFor($slim->router()->getCurrentRoute()->getName());
     $this->processMenuItems($menu, $currentRoutePath);
     return $menu;
 }