NameFlag Posted February 19, 2018 Share Posted February 19, 2018 I'm currently working on a new concept for my website, and i'm just wondering if it's possible to restrict access to a custom page unless the person is a member of the group? - which is assigned to them upon ordering the related product? Link to comment Share on other sites More sharing options...
twhiting9275 Posted February 21, 2018 Share Posted February 21, 2018 Are you referring to admin pages, or actual website pages (public)? Admin shouldn't be too hard to configure, but you probably won't get where you're looking for without a plugin for public sites. Link to comment Share on other sites More sharing options...
sentq Posted February 21, 2018 Share Posted February 21, 2018 On 2/20/2018 at 1:11 AM, NameFlag said: I'm currently working on a new concept for my website, and i'm just wondering if it's possible to restrict access to a custom page unless the person is a member of the group? - which is assigned to them upon ordering the related product? assuming that you follow this documentation, at the end of your custom page code replace this line: $ca->setTemplate('{your-template-file-name}'); with this: $client = Menu::context("client"); /* Only clients from the specified groups will be able to see content of this page others will see the restrictive message instead separate group ids by comma */ $allowedGroups = array(1, 2, 4); # Display page content if client assigned to one of the specified groups # Replace {your-template-file-name} with your template name if (in_array($client->groupid, $allowedGroups) || isset($_SESSION['adminid'])){ $ca->setTemplate('{your-template-file-name}'); } # Display special message for others else { $ca->setTemplate('content_restricted'); } now inside your active template directory, create new file called "content_restricted.tpl" and put the following lines inside it: <div class="alert alert-warning"><p>content of this page only available to specific clients under specific criteria</p></div> after this, when a client from one of the specified groups access the page, content of that page will be displayed normally (the same for logged in admins), but for visitors or clients from other groups it will display a message indicating that the content of this page is restricted. it's also possible to redirect user to specific URL instead of displaying the restricted message, for this replace the $ca->setTemplate('content_restricted'); with: header("Location: index.php"); exit; 1 Link to comment Share on other sites More sharing options...
NameFlag Posted February 26, 2018 Author Share Posted February 26, 2018 On 2/21/2018 at 6:37 AM, sentq said: assuming that you follow this documentation, at the end of your custom page code replace this line: $ca->setTemplate('{your-template-file-name}'); with this: $client = Menu::context("client"); /* Only clients from the specified groups will be able to see content of this page others will see the restrictive message instead separate group ids by comma */ $allowedGroups = array(1, 2, 4); # Display page content if client assigned to one of the specified groups # Replace {your-template-file-name} with your template name if (in_array($client->groupid, $allowedGroups) || isset($_SESSION['adminid'])){ $ca->setTemplate('{your-template-file-name}'); } # Display special message for others else { $ca->setTemplate('content_restricted'); } now inside your active template directory, create new file called "content_restricted.tpl" and put the following lines inside it: <div class="alert alert-warning"><p>content of this page only available to specific clients under specific criteria</p></div> after this, when a client from one of the specified groups access the page, content of that page will be displayed normally (the same for logged in admins), but for visitors or clients from other groups it will display a message indicating that the content of this page is restricted. it's also possible to redirect user to specific URL instead of displaying the restricted message, for this replace the $ca->setTemplate('content_restricted'); with: header("Location: index.php"); exit; Perfect! Thank you. 1 Link to comment Share on other sites More sharing options...
Recommended Posts