Exemple #1
0
 public function doLogin($req, $res)
 {
     $allPostPutVars = $req->getParsedBody();
     $auth_type = $this->containerSlim->get('systemOptions')->getValue('email_or_login') or 'email';
     $errors = false;
     if (!$allPostPutVars['password']) {
         $errors = true;
         $this->flash->addMessage('errors', 'The password attribute is required. ');
     }
     if (!$allPostPutVars[$auth_type]) {
         $this->flash->addMessage('errors', 'The login attribute is required. ');
         $errors = true;
     }
     $user = Users::where($auth_type, $allPostPutVars[$auth_type])->get();
     if (!isset($user[0])) {
         $this->flash->addMessage('errors', 'User no find in db.');
         $errors = true;
     } elseif (!$user[0]->active) {
         $this->flash->addMessage('errors', 'User is no active. Please contact administrator system.');
         $errors = true;
     } elseif (!$user[0]->verifyPassword($allPostPutVars['password'])) {
         $this->flash->addMessage('errors', 'User no find in system.');
         $errors = true;
     }
     if ($errors) {
         return $res->withStatus(302)->withHeader('Location', $this->router->pathFor('login'));
     }
     Session::put('auth', true);
     Session::put('user', $user[0]->toArray());
     return $res->withStatus(301)->withHeader('Location', '/admin/dashboard');
 }
Exemple #2
0
 protected function adminPanelRouteRegister()
 {
     if (Session::has('auth') && Session::get('auth')) {
         AdminRouteCollection::add(new AdminResource('sections'));
         $this->adminPanelMenuRegister();
     }
 }
Exemple #3
0
 protected function adminPanelRouteRegister()
 {
     if (SessionManager::has('auth') && SessionManager::get('auth') && $this->container->systemOptions->isDevMode()) {
         $this->app->get('/admin/generate_module', 'App\\Controllers\\Admin\\ModuleGenerator:index')->setName('developers.module.generator');
         $this->app->post('/admin/generate_module', 'App\\Controllers\\Admin\\ModuleGenerator:doAdd')->setName('developers.module.generator.add');
     }
 }
Exemple #4
0
 public function __invoke($request, $response, $next)
 {
     if (Session::has('auth') && Session::get('auth') && $request->getMethod() == 'PUT') {
         return $next($request, $response);
     }
     $guard = new \Slim\Csrf\Guard('csrf', $t, null, 10);
     return $guard($request, $response, $next);
 }
Exemple #5
0
 /**
  * Example middleware invokable class
  *
  * @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request
  * @param \Psr\Http\Message\ResponseInterface $response PSR7 response
  * @param callable $next Next middleware
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function __invoke($request, $response, $next)
 {
     global $container;
     if (!Session::has('auth') || !Session::get('auth')) {
         $container->flash->addMessage('errors', 'Please authorize');
         return $response->withStatus(302)->withHeader('Location', '/auth/login');
     }
     $response = $next($request, $response);
     return $response;
 }
 public static function add(Interfaces\IRouteResource $resource)
 {
     if (!Session::has('auth') || !Session::get('auth')) {
         return;
     }
     $info = $resource->getInfo();
     $collectionName = str_replace('/', "_", substr($info['path'], 1));
     if (isset(self::$collection[$collectionName])) {
         throw new \InvalidArgumentException("Resourse: " . $collectionName . " is registered. Please register other resource");
     }
     self::$collection[$collectionName] = $resource;
 }
 protected function storeParams($value)
 {
     $u_id = Session::get('user')['id'];
     $model = ModelsFactory::getModel('UserViewsSettings');
     $result = $model->where('user_id', $u_id)->where('group', $this->groupName)->where('code', $this->variableName)->first();
     if (!$result) {
         $result = ModelsFactory::getModel('UserViewsSettings', ['user_id' => $u_id, 'group' => $this->groupName, 'code' => $this->variableName]);
         $result->user_id = $u_id;
     }
     $result->value = $value;
     $result->save();
     return $result;
 }
 public function setOption($value, RequestParams $allParams)
 {
     $this->groupName = $this->groupName . basename($allParams->getRequest()->getUri()->getPath());
     $arParams = ['value' => $value, 'codeName' => $this->variableName, 'groupName' => $this->groupName];
     $event = new BaseContainerEvent($this->c, $arParams);
     $event = $this->c->dispatcher->dispatch('middleware.itemparpage.before', $event);
     $value = $event->getParams()['value'] ? $event->getParams()['value'] : $allParams->all($this->variableName);
     $result = $this->storeParams($value);
     Session::push('admin_panel.count_page', $allParams->all($this->variableName));
     $arParams = ['result' => $result, 'allParams' => $allParams];
     $event = new BaseContainerEvent($this->c, $arParams);
     $this->c->dispatcher->dispatch('middleware.itemparpage.after', $event);
 }
 public function update($request, $response, $args)
 {
     $params = $request->getParsedBody();
     $model = ModelsFactory::getModel('UserViewsSettings');
     $u_id = Session::get('user')['id'];
     $result = $model->where('user_id', $u_id)->where('group', $_REQUEST['group'])->where('code', $_REQUEST['code'])->first();
     if (!$result) {
         $result = ModelsFactory::getModel('UserViewsSettings', $_REQUEST);
         $result->user_id = $u_id;
     }
     $result->value = json_encode($_REQUEST['show']);
     $result->save();
     $this->data['data']['success'] = true;
     $this->view->render($response, 'json.twig', $this->data);
     return $response->withStatus(200)->withHeader('Content-type', 'application/json');
 }
 public function index(request $req, $res)
 {
     $this->initRoute($req, $res);
     $model = ModelsFactory::getModelWithRequest($req);
     $this->data['items'] = $model->orderBy($this->pageOrderBy, $this->pageOrderType)->paginate($this->pagecount);
     $this->data['items']->setPath($this->router->pathFor($this->data['all_e_link']));
     $this->data['items']->pagenItems = UrlWindow::make($this->data['items']);
     $this->data['fields'] = $this->getFields($model->getColumnsNames(), array('id'));
     $userField = ModelsFactory::getModel('UserViewsSettings');
     $userField = $userField->where('user_id', Session::get('user')['id'])->where('group', $this->data['all_e_link'])->where('code', 'show_fields_in_table')->first();
     $this->data['showFields'] = array();
     if ($userField) {
         $this->data['showFields'] = (array) json_decode($userField->toArray()['value']);
         $this->data['fields'] = $this->data['showFields'];
     }
     $this->data['allFields'] = array_diff($model->getColumnsNames(), $this->data['showFields']);
     $this->render('admin\\dataTables.twig');
 }
 protected function adminPanelMenuRegister()
 {
     $item = new Menu('Dashboard', ['url' => '/admin/dashboard', 'link_attr' => ['icon' => 'fa fa-dashboard fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false, 'sort' => 100]]);
     $this->container->get('adminMenuLeft')->add($item);
     $item = new Menu('Pages', ['menu_name' => 'section.pages', 'url' => '#', 'link_attr' => ['icon' => 'fa fa-list-alt fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false, 'sort' => 200], 'sub_menu' => [new Menu('Show all pages', ['menu_name' => 'page.list', 'url' => '/admin/pages', 'link_attr' => ['icon' => 'fa fa-file-o fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false]]), new Menu('Add new page', ['menu_name' => 'page.add', 'url' => '/admin/pages/add', 'link_attr' => ['icon' => 'fa fa-pencil-square-o fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false]])]]);
     $this->container->get('adminMenuLeft')->add($item);
     $item = new Menu('Users and Groups', ['menu_name' => 'section.usersandgroups', 'url' => '#', 'link_attr' => ['icon' => 'fa fa-users fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false, 'sort' => 300], 'sub_menu' => [new Menu('Users', ['menu_name' => 'user.list', 'url' => '/admin/users', 'link_attr' => ['icon' => 'fa fa-user fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false]]), new Menu('Groups', ['menu_name' => 'group.list', 'url' => '/admin/groups', 'link_attr' => ['icon' => 'fa fa-group fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false]])]]);
     $this->container->get('adminMenuLeft')->add($item);
     $item = new Menu('System options', ['menu_name' => 'section.options', 'url' => '#', 'link_attr' => ['icon' => 'fa fa-gears fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false, 'sort' => 400], 'sub_menu' => [new Menu('Options', ['menu_name' => 'option.list', 'url' => '/admin/options', 'link_attr' => ['icon' => 'fa fa-gear fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false]]), new Menu('Option groups', ['menu_name' => 'group_options.list', 'url' => '/admin/group_options', 'link_attr' => ['icon' => 'fa fa-gears fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false]])]]);
     $this->container->get('adminMenuLeft')->add($item);
     $item = new Menu('Developer possibility', ['menu_name' => 'section.only_developers', 'url' => '#', 'link_attr' => ['icon' => 'fa fa-flash fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => true, 'sort' => 1000], 'sub_menu' => [new Menu('PHP info', ['menu_name' => 'developer.phpinfo', 'url' => '/admin/phpinfo', 'link_attr' => ['icon' => 'fa fa-gear fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false]])]]);
     $this->container->get('adminMenuLeft')->add($item);
     if (Session::get('auth')) {
         $item = new Menu('', ['url' => '#', 'link_attr' => ['icon' => 'fa fa-user fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false, 'sort' => 100], 'sub_menu' => [new Menu('User edit', ['menu_name' => 'user.profile', 'url' => '/admin/users/edit/' . Session::get('user')['id'], 'link_attr' => ['icon' => 'fa fa-user fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false]]), new Menu('Item delimiter', ['menu_name' => 'user.delimiter', 'url' => '#', 'link_attr' => ['icon' => 'fa fa-ban fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false, 'delimiter' => true]]), new Menu('Logout', ['menu_name' => 'user.logout', 'url' => '/auth/logout', 'link_attr' => ['icon' => 'fa fa-sign-out fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false]])]]);
         $item1 = new Menu('', ['url' => '?clear_cache', 'link_attr' => ['icon' => 'fa fa-refresh fa-fw'], 'meta_attr' => ['onlyDevelopersMode' => false, 'sort' => 100]]);
         $this->container->get('adminMenuTop')->add($item);
         $this->container->get('adminMenuTop')->add($item1);
     }
 }
Exemple #12
0
 protected function initRoute($req, $res)
 {
     $this->request = $req;
     $this->response = $res;
     $s = $req->getAttribute('route')->getName();
     $this->data['current_route_name'] = $s;
     $this->containerSlim->get('logger')->addInfo("Run admin page: ", [Session::get('user')['login']]);
     $this->containerSlim->get('logger')->addInfo("Get route: ", [$s]);
     $model = ModelsFactory::getModel('UserViewsSettings');
     $result = $model->where('user_id', Session::get('user')['id'])->where('group', 'last.page.' . basename($req->getUri()->getPath()))->where('code', 'page')->first();
     if ($result) {
         $current_page = $result->value;
     }
     Paginator::currentPageResolver(function () use($current_page) {
         return $current_page;
     });
     $result = $model->where('user_id', Session::get('user')['id'])->where('group', 'items.perpage.' . basename($req->getUri()->getPath()))->where('code', 'count_page')->first();
     if ($result) {
         $this->pagecount = $result->value;
         $this->data['page_count'] = $this->pagecount;
     }
     $result = $model->where('user_id', Session::get('user')['id'])->where('group', 'order.type.' . basename($req->getUri()->getPath()))->where('code', 'order_by')->first();
     $this->pageOrderBy = "id";
     if ($result) {
         $this->pageOrderBy = $result->value;
     }
     $this->data['page_order_by'] = $this->pageOrderBy;
     $result = $model->where('user_id', Session::get('user')['id'])->where('group', 'order.type.' . basename($req->getUri()->getPath()))->where('code', 'order_type')->first();
     $this->pageOrderType = "asc";
     if ($result) {
         $this->pageOrderType = $result->value;
     }
     $this->data['page_order_type'] = $this->pageOrderType;
     if (!$this->controllerName) {
         $this->controllerName = substr($s, strpos($s, '.') + 1);
     }
     $this->init();
     $this->csrf($req);
 }
 /**
  * @param request $req
  * @param $res
  */
 public function index(request $req, $res)
 {
     $this->initRoute($req, $res);
     $model = ModelsFactory::getModelWithRequest($req);
     if (!$this->containerSlim->systemOptions->isHideFunctionality() || $this->containerSlim->systemOptions->isDevMode()) {
         $this->data['items'] = $model->paginate($this->pagecount);
     } elseif ($this->containerSlim->systemOptions->isHideFunctionality()) {
         $this->data['items'] = $model->where('frozen', '!=', 1)->orWhere('code', 'develop_mode')->paginate($this->pagecount);
     }
     $this->data['items']->setPath($this->router->pathFor($this->data['all_e_link']));
     $this->data['items']->pagenItems = UrlWindow::make($this->data['items']);
     $t = $model->getColumnsNames(['GroupName']);
     $this->data['fields'] = $this->getFields($t, ['id'], ['values', 'type', 'options_group_id', 'frozen']);
     $userField = ModelsFactory::getModel('UserViewsSettings');
     $userField = $userField->where('user_id', Session::get('user')['id'])->where('group', $this->data['all_e_link'])->where('code', 'show_fields_in_table')->first();
     $this->data['showFields'] = array();
     if ($userField) {
         $this->data['showFields'] = (array) json_decode($userField->toArray()['value']);
         $this->data['fields'] = $this->data['showFields'];
     }
     $this->data['allFields'] = array_diff($model->getColumnsNames(), $this->data['showFields']);
     $this->data['developMode'] = $this->containerSlim->systemOptions->isDevMode();
     $this->render('admin\\optionsTable.twig');
 }
Exemple #14
0
 protected static function bootModuleContainer($module)
 {
     if ($module->only_auth && !Session::get('auth')) {
         return;
     }
     if ($module->isInitModule()) {
         self::$loadedModules[$module->system_name] = $module->system_name;
         return;
     }
     self::checkDependency($module->dependeny);
     self::initializationProcess($module, $module->system_name);
 }