Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Site access permission for admin users

givanz727c2241b068
diff --git a/admin/component/notifications.php b/admin/component/notifications.php
index c9b9bc5..0d510e3 100644
--- a/admin/component/notifications.php
+++ b/admin/component/notifications.php
@@ -255,10 +255,10 @@ class Notifications extends ComponentBase {
$this->questions();
$update = new Update();
- $updates = $update->checkUpdates('core');
+ $updates = $update->checkUpdates('core') ?? [];
$this->notifications['updates']['core'] = $updates;
- $this->count += max($updates['hasUpdate'], 0);
+ $this->count += max($updates['hasUpdate'] ?? 0, 0);
$results = [
'notifications' => $this->notifications,
diff --git a/admin/component/products.php b/admin/component/products.php
index b47aa97..741a93e 100755
--- a/admin/component/products.php
+++ b/admin/component/products.php
@@ -51,6 +51,8 @@ class Products extends ComponentBase {
$results = $products->getAll($this->options);
+ $results['products'] = $results['products'] ?? [];
+
foreach ($results['products'] as $id => &$product) {
if (isset($product['images'])) {
$product['images'] = json_decode($product['images'], true);
diff --git a/admin/component/sites.php b/admin/component/sites.php
index a06e0e1..3bd310e 100755
--- a/admin/component/sites.php
+++ b/admin/component/sites.php
@@ -27,11 +27,13 @@ use Vvveb\System\Component\ComponentBase;
use Vvveb\System\Event;
use Vvveb\System\Session;
use Vvveb\System\Sites as SitesList;
+use Vvveb\System\User\Admin;
class Sites extends ComponentBase {
public static $defaultOptions = [
- 'limit' => 1000,
- 'page' => 1,
+ 'limit' => 1000,
+ 'page' => 1,
+ 'site_access' => 1,
];
protected $options = [];
@@ -52,6 +54,18 @@ class Sites extends ComponentBase {
$results['active'] = SitesList::getSiteById($results['site_id']);
$results['count'] = count($results['sites']);
+ if ($this->options['site_access']) {
+ $site_access = Admin::siteAccess();
+
+ if ($site_access) {
+ foreach ($results['sites'] as $key => $site) {
+ if (! in_array($site['id'], $site_access)) {
+ unset($results['sites'][$key]);
+ }
+ }
+ }
+ }
+
list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);
return $results;
diff --git a/admin/controller/admin/role.php b/admin/controller/admin/role.php
index 0465ae8..d744cf7 100755
--- a/admin/controller/admin/role.php
+++ b/admin/controller/admin/role.php
@@ -47,7 +47,7 @@ class Role extends Base {
if ($this->view->role) {
$this->view->role['permissions'] = json_decode($this->view->role['permissions'], true);
$this->view->role['permissions']['deny'] = $this->view->role['permissions']['deny'] ?? [];
- $this->view->role['permissions']['allow'] = $this->view->role['permissions']['allow'] ?? [];
+ $this->view->role['permissions']['allow'] = $this->view->role['permissions']['allow'] ?? [];
$this->view->role['permissions']['capabilities'] = $this->view->role['permissions']['capabilities'] ?? [];
}
}
diff --git a/admin/controller/admin/user.php b/admin/controller/admin/user.php
index 00a3705..cbd42c2 100755
--- a/admin/controller/admin/user.php
+++ b/admin/controller/admin/user.php
@@ -23,6 +23,7 @@
namespace Vvveb\Controller\Admin;
use Vvveb\Controller\User\User as UserBase;
+use Vvveb\Sql\SiteSQL;
class User extends UserBase {
protected $type = 'admin';
@@ -37,6 +38,9 @@ class User extends UserBase {
] + $this->global;
$roles = $roles->getAll($options);
- $this->view->roles = $roles ? $roles['role'] : [];
+ $sites = new SiteSQL();
+
+ $this->view->sitesList = $sites->getAll()['sites'] ?? [];
+ $this->view->roles = $roles ? $roles['role'] : [];
}
}
diff --git a/admin/controller/settings/site.php b/admin/controller/settings/site.php
index e6ff258..04dd946 100755
--- a/admin/controller/settings/site.php
+++ b/admin/controller/settings/site.php
@@ -38,8 +38,10 @@ class Site extends Base {
$countryModel = new CountrySQL();
$options = $this->global;
$options['status'] = 1;
+
unset($options['limit']);
- $country = $countryModel->getAll($options);
+
+ $country = $countryModel->getAll($options);
$this->view->countries = $country['country'] ?? [];
//set Regions for default store country
@@ -50,7 +52,7 @@ class Site extends Base {
$options['country_id'] = $country_id;
$this->view->regions = $regions['region'] ?? [];
*/
- $this->view->regionsUrl = url(['module' => 'checkout/checkout', 'action' => 'regions']);
+ $this->view->regionsUrl = url(['module' => 'checkout/checkout', 'action' => 'regions']);
}
function dateFormat() {
@@ -60,16 +62,16 @@ class Site extends Base {
}
function regions() {
- $country_id = $this->request->get['country_id'] ?? false;
- $regions = [];
+ $country_id = $this->request->get['country_id'] ?? false;
+ $regions = [];
if ($country_id) {
- $region = new RegionSQL();
- $options = $this->global;
- $options['status'] = 1;
+ $region = new RegionSQL();
+ $options = $this->global;
+ $options['status'] = 1;
unset($options['limit']);
- $options['country_id'] = $country_id;
- $regions = $region->getAll($options)['region'] ?? [];
+ $options['country_id'] = $country_id;
+ $regions = $region->getAll($options)['region'] ?? [];
}
$this->response->setType('json');
@@ -121,7 +123,7 @@ class Site extends Base {
$return = $sites->add($data);
$id = $return['site'];
$site['state'] = 'live';
- $site['id'] = $id;
+ $site['id'] = $id;
Sites::saveSite($site);
if (! $id) {
@@ -144,27 +146,29 @@ class Site extends Base {
function index() {
$themeList = Themes:: getList();
- $site_id = $this->request->get['site_id'] ?? null;
- $view = $this->view;
- $view->themeList = $themeList;
- $view->templateList = \Vvveb\getTemplateList(false, ['email']);
- $site = [];
- $siteSql = new SiteSQL();
+ $site_id = $this->request->get['site_id'] ?? null;
+ $view = $this->view;
+ $site = [];
+ $siteSql = new SiteSQL();
if ($site_id) {
- $site = $siteSql->get(['site_id' => $site_id]);
+ $site = $siteSql->get(['site_id' => $site_id]);
+
+ if (! $site) {
+ return $this->notFound();
+ }
}
- $default = '{"logo":"logo.png","logo-sticky":"logo.png","logo-dark":"logo-white.png","logo-dark-sticky":"logo-white.png","favicon":"favicon.ico", "country_id":223, "region_id":3655}';
- $view->setting = json_decode($site['settings'] ?? $default, true);
+ $default = '{"logo":"logo.png","logo-sticky":"logo.png","logo-dark":"logo-white.png","logo-dark-sticky":"logo-white.png","favicon":"favicon.ico", "country_id":223, "region_id":3655}';
+ $setting = json_decode($site['settings'] ?? $default, true);
foreach (['favicon', 'logo', 'logo-sticky', 'logo-dark', 'logo-dark-sticky'] as $img) {
- if (isset($view->setting[$img])) {
- $view->setting[$img . '-src'] = Images::image($view->setting[$img]);
+ if (isset($setting[$img])) {
+ $setting[$img . '-src'] = Images::image($setting[$img]);
}
}
- $data = $siteSql->getData(($view->setting ?? []) + $this->global);
+ $data = $siteSql->getData(($setting ?? []) + $this->global);
$data['complete_status_id'] = $data['processing_status_id'] = $data['order_status_id'];
$data['timezone'] = [];
@@ -181,16 +185,9 @@ class Site extends Base {
$data['timezone'][$timezone] = $timezone . $hour;
}
- $admin_path = \Vvveb\adminPath();
- $view->site = $site + $view->setting;
+ $admin_path = \Vvveb\adminPath();
$domain = Sites::urlSplit();
- $view->domain = '';
-
- if ($domain) {
- $view->domain = ($domain['domain'] ?? '') . '.' . ($domain['tld'] ?? '');
- }
-
//$data['subtract'] = [1 => __('Yes'), 0 => __('No')]; //Subtract stock options
$date_format = ['F j, Y', 'Y-m-d', 'm/d/Y', 'd/m/Y'];
$time_format = ['g:i a', 'g:i A', 'H:i'];
@@ -203,11 +200,22 @@ class Site extends Base {
$data['time_format'][$format] = date($format);
}
- $view->set($data);
- $view->resize = ['s' => __('Stretch'), 'c' => __('Crop')];
+ if (! defined('CLI')) {
+ $view->domain = '';
+
+ if ($domain) {
+ $view->domain = ($domain['domain'] ?? '') . '.' . ($domain['tld'] ?? '');
+ }
- $controllerPath = $admin_path . 'index.php?module=media/media';
- $view->scanUrl = "$controllerPath&action=scan";
- $view->uploadUrl = "$controllerPath&action=upload";
+ $view->set($data);
+ $view->site = $site + $setting;
+ $view->resize = ['s' => __('Stretch'), 'c' => __('Crop')];
+ $view->themeList = $themeList;
+ $view->templateList = \Vvveb\getTemplateList(false, ['email']);
+
+ $controllerPath = $admin_path . 'index.php?module=media/media';
+ $view->scanUrl = "$controllerPath&action=scan";
+ $view->uploadUrl = "$controllerPath&action=upload";
+ }
}
}
diff --git a/admin/controller/settings/sites.php b/admin/controller/settings/sites.php
index 3dd6e79..8865eda 100755
--- a/admin/controller/settings/sites.php
+++ b/admin/controller/settings/sites.php
@@ -49,7 +49,7 @@ class Sites extends Base {
$site['url'] = SitesList::url($site['host']);
}
- $view->sitesList = $results['sites'];
- $view->count = $results['count'];
+ $view->sitesList = $results['sites'] ?? [];
+ $view->count = $results['count'] ?? 0;
}
}
diff --git a/admin/controller/user/user.php b/admin/controller/user/user.php
index 7db9ee6..c7fb3ff 100755
--- a/admin/controller/user/user.php
+++ b/admin/controller/user/user.php
@@ -56,6 +56,10 @@ class User extends Base {
$user['avatar_url'] = Images::image($user['avatar'], $this->type);
}
+ if (isset($user['site_access'])) {
+ $user['site_access'] = json_decode($user['site_access']);
+ }
+
$view->user = $user;
}
@@ -98,14 +102,24 @@ class User extends Base {
$users = new $sqlModel();
$user = $this->request->post[$this->type] ?? [];
+ //if no password provided don't change
if (empty($user['password'])) {
unset($user['password']);
} else {
$user['password'] = Auth :: password($user['password']);
}
+ if (isset($user['site_access'])) {
+ if (is_array($user['site_access'])) {
+ $user['site_access'] = json_encode($user['site_access']);
+ } else {
+ $user['site_access'] = '[]';
+ }
+ } else {
+ $user['site_access'] = '[]';
+ }
+
if ($user_id) {
- //if no password provided don't change
$result = $users->edit([$this->type . '_id' => $user_id, $this->type => $user]);
if ($result >= 0) {
diff --git a/admin/template/admin/user.tpl b/admin/template/admin/user.tpl
index 0f45564..df01b62 100755
--- a/admin/template/admin/user.tpl
+++ b/admin/template/admin/user.tpl
@@ -48,3 +48,22 @@ import(common.tpl)
[data-v-user] [data-v-avatar]|data-v-avatar = $this->user['avatar_url']
[data-v-user] input[data-v-avatar]|value = $this->user['avatar']
[data-v-user] img[data-v-avatar]|src = <?php echo (isset($this->user['avatar_url']) && $this->user['avatar_url']) ? $this->user['avatar_url'] : 'img/placeholder.svg';?>
+
+/* Site access */
+
+#all-sites-check|addNewAttribute = <?php if (empty($this->user['site_access'])) echo 'checked';?>
+
+[data-v-sites] [data-v-site]|deleteAllButFirstChild
+
+[data-v-sites] [data-v-site]|before = <?php
+if(isset($this->sitesList) && is_array($this->sitesList)) {
+ //$pagination = $this->sites[$_sites_idx]['pagination'];
+ foreach ($this->sitesList as $index => $site) { ?>
+
+ [data-v-sites] [data-v-site] [data-v-*]|innerText = $site['@@__data-v-(*)__@@']
+ [data-v-sites] [data-v-site] input[type="checkbox"]|addNewAttribute = <?php if (in_array($site['site_id'], $this->user['site_access'])) echo 'checked';?>
+
+
+ [data-v-sites] [data-v-site]|after = <?php
+ }
+}?>
diff --git a/admin/template/tools/systeminfo.tpl b/admin/template/tools/systeminfo.tpl
index eb2efea..7c3d332 100755
--- a/admin/template/tools/systeminfo.tpl
+++ b/admin/template/tools/systeminfo.tpl
@@ -15,7 +15,13 @@ foreach ($this->info as $category => $info) {
?>
@entry [data-v-name] = $name
- @entry [data-v-value] = $value
+ @entry [data-v-value] = <?php
+ if (is_string($value)) {
+ echo htmlentities($value);
+ } else {
+ highlight_string(var_export($value, true));
+ }
+ ?>
@entry|after =
diff --git a/install/sql/insert/admin/admin.sql b/install/sql/insert/admin/admin.sql
index 38f19d8..46c5716 100755
--- a/install/sql/insert/admin/admin.sql
+++ b/install/sql/insert/admin/admin.sql
@@ -1,11 +1,11 @@
-INSERT INTO `admin` (`admin_id`, `username`, `first_name`, `last_name`,`password`, `email`, `url`, `created_at`, `token`, `status`, `display_name`, `avatar`, `bio`, `role_id`) VALUES
+INSERT INTO `admin` (`admin_id`, `username`, `first_name`, `last_name`,`password`, `email`, `url`, `created_at`, `token`, `status`, `site_access`, `display_name`, `avatar`, `bio`, `role_id`) VALUES
-(1, 'admin', 'Admin', 'Admin', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, 'Admin', 'vvveb.svg', 'This is a brief biography', 1),
-(2, 'administrator', 'Administrator', 'Administrator', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, 'Administrator', 'vvveb.svg', 'This is a brief biography', 2),
-(3, 'editor', 'Editor', 'Editor','$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, 'Editor', 'vvveb.svg', 'This is a brief biography', 3),
-(4, 'author', 'Author', 'Author', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, 'Author', 'vvveb.svg', 'This is a brief biography', 4),
-(5, 'contributor', 'Contributor', 'Contributor', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, 'Contributor', 'vvveb.svg', 'This is a brief biography', 5),
-(6, 'shop', 'Shop', 'Shop', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, 'Shop assistant', 'vvveb.svg', 'This is a brief biography', 6),
-(7, 'vendor', 'Vendor', 'Vendor', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, 'Vendor', 'vvveb.svg', 'This is a brief biography', 7),
-(8, 'rest', 'Rest', 'Rest', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, 'Rest Api', 'vvveb.svg', 'This is a brief biography', 8),
-(9, 'demo', 'Demo', 'Demo', '$2y$11$oNa5z5S1gabs8vB/GU9KRuFxw1psuMx8rPaVjnVLm8mm./ufAiRgm', '[email protected]', '', '2022-05-01 00:00:00', '', 0, 'Demo', 'vvveb.svg', 'This is a brief biography', 9);
\ No newline at end of file
+(1, 'admin', 'Admin', 'Admin', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, '[]', 'Admin', 'vvveb.svg', 'This is a brief biography', 1),
+(2, 'administrator', 'Administrator', 'Administrator', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, '[]', 'Administrator', 'vvveb.svg', 'This is a brief biography', 2),
+(3, 'editor', 'Editor', 'Editor','$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, '[]', 'Editor', 'vvveb.svg', 'This is a brief biography', 3),
+(4, 'author', 'Author', 'Author', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, '[]', 'Author', 'vvveb.svg', 'This is a brief biography', 4),
+(5, 'contributor', 'Contributor', 'Contributor', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, '[]', 'Contributor', 'vvveb.svg', 'This is a brief biography', 5),
+(6, 'shop', 'Shop', 'Shop', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, '[]', 'Shop assistant', 'vvveb.svg', 'This is a brief biography', 6),
+(7, 'vendor', 'Vendor', 'Vendor', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, '[]', 'Vendor', 'vvveb.svg', 'This is a brief biography', 7),
+(8, 'rest', 'Rest', 'Rest', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', '2022-05-01 00:00:00', '', 0, '[]', 'Rest Api', 'vvveb.svg', 'This is a brief biography', 8),
+(9, 'demo', 'Demo', 'Demo', '$2y$11$oNa5z5S1gabs8vB/GU9KRuFxw1psuMx8rPaVjnVLm8mm./ufAiRgm', '[email protected]', '', '2022-05-01 00:00:00', '', 0, '[]', 'Demo', 'vvveb.svg', 'This is a brief biography', 9);
\ No newline at end of file
diff --git a/install/sql/insert/user/user.sql b/install/sql/insert/user/user.sql
index 1dcbab4..8772f9c 100755
--- a/install/sql/insert/user/user.sql
+++ b/install/sql/insert/user/user.sql
@@ -1,2 +1,2 @@
INSERT INTO `user` (`user_id`, `username`, `first_name`, `last_name`, `password`, `email`, `url`, `display_name`, `created_at`, `token`, `avatar`, `bio`, `status`) VALUES
-(1, 'johndoe', 'John', 'Doe', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', 'johndoe', '2022-05-01 00:00:00', '', 'placeholder.svg', 'This is a brief biography', 1);
+(1, 'johndoe', 'John', 'Doe', '$2y$11$o52ahesifBsklkPV8eTWSeoKbBHJXxaoDZUIDYiFYdAmHQSyfDM3W', '[email protected]', '', 'johndoe', '2022-05-01 00:00:00', '', '', 'This is a brief biography', 1);
diff --git a/install/sql/mysqli/schema/admin/admin.sql b/install/sql/mysqli/schema/admin/admin.sql
index 99d65e9..607a267 100755
--- a/install/sql/mysqli/schema/admin/admin.sql
+++ b/install/sql/mysqli/schema/admin/admin.sql
@@ -13,6 +13,7 @@ CREATE TABLE `admin` (
`avatar` varchar(250) NOT NULL DEFAULT '',
`bio` text,
`role_id` INT UNSIGNED DEFAULT NULL,
+ `site_access` TEXT NOT NULL,
`status` INT UNSIGNED NOT NULL DEFAULT '0',
`token` varchar(32) NOT NULL DEFAULT '',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
diff --git a/install/sql/mysqli/schema/user/user.sql b/install/sql/mysqli/schema/user/user.sql
index 8447611..c78c618 100755
--- a/install/sql/mysqli/schema/user/user.sql
+++ b/install/sql/mysqli/schema/user/user.sql
@@ -3,6 +3,7 @@ DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`user_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`user_group_id` INT UNSIGNED NOT NULL DEFAULT 1,
+ `site_id` INT UNSIGNED NOT NULL DEFAULT 1,
`username` varchar(60) NOT NULL DEFAULT '',
`first_name` varchar(32) NOT NULL DEFAULT '',
`last_name` varchar(32) NOT NULL DEFAULT '',
diff --git a/install/sql/pgsql/schema/admin/admin.sql b/install/sql/pgsql/schema/admin/admin.sql
index cbce022..3397f6e 100755
--- a/install/sql/pgsql/schema/admin/admin.sql
+++ b/install/sql/pgsql/schema/admin/admin.sql
@@ -16,6 +16,7 @@ CREATE TABLE "admin" (
"avatar" varchar(250) NOT NULL DEFAULT '',
"bio" varchar(250) NOT NULL DEFAULT '',
"role_id" int check ("role_id" > 0) DEFAULT NULL,
+ "site_access" text NOT NULL,
"status" int check ("status" >= 0) NOT NULL DEFAULT 0,
"token" varchar(32) NOT NULL DEFAULT '',
"created_at" timestamp(0) NOT NULL DEFAULT '2022-05-01 00:00:00',
diff --git a/install/sql/pgsql/schema/user/user.sql b/install/sql/pgsql/schema/user/user.sql
index e5988e8..14b6e57 100755
--- a/install/sql/pgsql/schema/user/user.sql
+++ b/install/sql/pgsql/schema/user/user.sql
@@ -7,6 +7,7 @@ CREATE SEQUENCE "user_seq";
CREATE TABLE "user" (
"user_id" int check ("user_id" > 0) NOT NULL DEFAULT NEXTVAL ('user_seq'),
"user_group_id" int check ("user_group_id" > 0) NOT NULL DEFAULT 1,
+ "site_id" int check ("site_id" > 0) NOT NULL DEFAULT 1,
"username" varchar(60) NOT NULL DEFAULT '',
"first_name" varchar(32) NOT NULL DEFAULT '',
"last_name" varchar(32) NOT NULL DEFAULT '',
diff --git a/install/sql/sqlite/schema/admin/admin.sql b/install/sql/sqlite/schema/admin/admin.sql
index 93b45b6..4999f37 100755
--- a/install/sql/sqlite/schema/admin/admin.sql
+++ b/install/sql/sqlite/schema/admin/admin.sql
@@ -18,6 +18,7 @@ CREATE TABLE `admin` (
`avatar` TEXT NOT NULL DEFAULT '',
`bio` TEXT NOT NULL DEFAULT '',
`role_id` INT DEFAULT NULL,
+`site_access` INT NOT NULL DEFAULT '[]',
`status` INT NOT NULL DEFAULT '0',
`token` TEXT NOT NULL DEFAULT '',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
diff --git a/install/sql/sqlite/schema/user/user.sql b/install/sql/sqlite/schema/user/user.sql
index d7e440f..92de3d7 100755
--- a/install/sql/sqlite/schema/user/user.sql
+++ b/install/sql/sqlite/schema/user/user.sql
@@ -3,6 +3,7 @@ DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`user_id` INTEGER PRIMARY KEY AUTOINCREMENT,
`user_group_id` INT NOT NULL DEFAULT 1,
+`site_id` INT NOT NULL DEFAULT 1,
`username` TEXT NOT NULL DEFAULT '',
`first_name` TEXT NOT NULL DEFAULT '',
`last_name` TEXT NOT NULL DEFAULT '',
diff --git a/system/user/admin.php b/system/user/admin.php
index 8e49cd3..155c179 100755
--- a/system/user/admin.php
+++ b/system/user/admin.php
@@ -26,6 +26,22 @@ use \Vvveb\Sql\AdminSQL;
use Vvveb\System\PageCache;
class Admin extends Auth {
+ private static function setUserData(&$data) {
+ if (isset($data['password'])) {
+ $data['password'] = self :: password($data['password']);
+ }
+
+ if (isset($data['site_access'])) {
+ if (is_array($data['site_access'])) {
+ $data['site_access'] = json_encode($data['site_access']);
+ }
+ } else {
+ $data['site_access'] = '[]';
+ }
+
+ return $data;
+ }
+
public static function add($data) {
$admin = new \Vvveb\Sql\AdminSQL();
@@ -34,9 +50,10 @@ class Admin extends Auth {
return true;
}
- $data['password'] = self :: password($data['password']);
$data['status'] = 0;
+ self::setUserData($data);
+
return $admin->add(['admin' => $data]);
}
@@ -47,6 +64,19 @@ class Admin extends Auth {
return in_array($capability, $capabilities);
}
+ public static function siteAccess() {
+ $admin = \Vvveb\session('admin', false);
+
+ return $site_access = $admin['site_access'] ?? [];
+ }
+
+ public static function hasSiteAccess($site_id) {
+ $admin = \Vvveb\session('admin', false);
+ $site_access = $admin['site_access'] ?? [];
+
+ return in_array($site_id, $site_access);
+ }
+
public static function hasPermission($permission) {
$admin = \Vvveb\session('admin', false);
$permissions = $admin['permissions'] ?: [];
@@ -59,9 +89,7 @@ class Admin extends Auth {
public static function update($data, $condition) {
$admin = new \Vvveb\Sql\AdminSQL();
- if (isset($data['password'])) {
- $data['password'] = self :: password($data['password']);
- }
+ self::setUserData($data);
return $admin->edit(array_merge(['admin' => $data], $condition));
}
@@ -105,6 +133,10 @@ class Admin extends Auth {
if (isset($adminInfo['permissions'])) {
$adminInfo['permissions'] = json_decode($adminInfo['permissions'], true);
}
+
+ if (isset($adminInfo['site_access'])) {
+ $adminInfo['site_access'] = json_decode($adminInfo['site_access'], true);
+ }
}
if (! $adminInfo) {
@@ -127,13 +159,13 @@ class Admin extends Auth {
unset($adminInfo['password']);
\Vvveb\session(['admin' => $adminInfo + $additionalInfo]);
- PageCache::disable();
+ PageCache::disable('user');
return $adminInfo;
}
public static function logout() {
- PageCache::enable();
+ PageCache::enable('user');
return \Vvveb\session(['admin' => false]);
}
diff --git a/system/user/user.php b/system/user/user.php
index bb14134..74c9dc4 100755
--- a/system/user/user.php
+++ b/system/user/user.php
@@ -111,13 +111,13 @@ class User extends Auth {
unset($userInfo['password']);
\Vvveb\session(['user' => $userInfo]);
- PageCache::disable();
+ PageCache::disable('user');
return $userInfo;
}
public static function logout() {
- PageCache::enable();
+ PageCache::enable('user');
return \Vvveb\session(['user' => false]);
}