Skip to content

Commit

Permalink
Exclude usergroups from accessing the store
Browse files Browse the repository at this point in the history
  • Loading branch information
srexi committed Jul 8, 2020
1 parent 5d73ebe commit ca3be3f
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions inc/plugins/rexshop.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function rexshop_info()
"website" => "https://shop.rexdigital.group",
"author" => "RexDigitalGroup",
"authorsite" => "https://rexdigital.group",
"version" => "1.04",
"version" => "1.05",
"guid" => "",
"compatibility" => "18*,16*"
);
Expand Down Expand Up @@ -78,6 +78,15 @@ function rexshop_install()
"disporder" => 2,
"gid" => intval($gid),
]);
$db->insert_query("settings", [
"name" => "rexshop_exclude_usergroups",
"title" => "Exclude Usergroups",
"description" => "A comma seperated list of usergroups NOT allowed to buy your product. (Example: 2,3,8,10)",
"optionscode" => 'text',
"value" => '',
"disporder" => 2,
"gid" => intval($gid),
]);
rebuild_settings();

//Tables
Expand Down Expand Up @@ -198,7 +207,7 @@ function rexshop_payment_page()
$lang->load('rexshop');

if ($mybb->input['action'] == 'store') {
if (!$mybb->user['uid']) {
if (!$mybb->user['uid'] || !rexshop_allowed_to_buy($mybb->user['usergroup'])) {
error_no_permission();
}
if (!isset($mybb->settings['rexshop_client_id'])) {
Expand Down Expand Up @@ -1195,6 +1204,19 @@ function rexshop_seconds_from_duration($duration, $time)
}
}

function rexshop_allowed_to_buy($usergroup)
{
global $mybb;

if (!empty($mybb->settings['rexshop_exclude_usergroups'])) {
$usergroups = explode(',', ltrim(rtrim(trim($mybb->settings['rexshop_exclude_usergroups'], ' '), ','), ','));

return !in_array((int) $usergroup, $usergroups);
}

return true;
}

function rexshop_on_success()
{
header("Status: 200 OK");
Expand Down

0 comments on commit ca3be3f

Please sign in to comment.