Best way to do front-end public and restricted area with October CMS?

- 1 answer

Ad

I have to create a website with limited public access pages.

All pages have a header section with a signin / signup link and when the user is already logged in, a logout link. To do this, I must place the rainlab user plugin session component in my layout with security=all (to prevent the ajax onLogout administrator error from being detected)

But by doing this, I can no longer use this layout for restricted access pages.

So, what is the right way to do it?

I thought of using 2 layout, one to public access with security = all and one to restricted access with security=user, but I'm not really satisfied to have to use 2 layout for a difference so minimal

any smarter solution ? thanks by advance

Ad

Answer

Ad

You can use the same layout for both restricted and public pages. Add the [session] component reference to the layout but don't set properties on it in the layout itself. Set the 'security' property on a per page (and not on the layout itself) basis.

So the top of your layout would look something like:

name="Master Layout"
description = "Master layout for almost all frontend pages."


[session]
==

<!DOCTYPE html>
<html lang="en">
<head>
.....

And the top of your pages would look like:

title = "Restricted Page"
url = "/classified"
layout = "master"

[session]
security = "user"
redirect = "account"
==

<div class="container">

I use it all the time without a problem.

Ad
source: stackoverflow.com
Ad