How to know if a user is authenticated or not in WCM 8 and 8.5

Lock-simple-128

This is pretty simple way to check if any user has a session started or not; this is useful in cases where you want to display or execute an specific code depending on the user session. To create this kind of validation we can take advantage of the WCM plugins Equals and NotEquals

[Plugin:Equals text1="true" text2="[Plugin:RequestAttribute key='userLoggedIn' mode='get']"]
<!-- Authenticated block -->
<p class="authenticated">I have a session.</p>
[/Plugin:Equals]

[Plugin:NotEquals text1="true" text2="[Plugin:RequestAttribute key='userLoggedIn' mode='get']"]
<!-- Not authenticated block -->
<p class="anonymous">I DON'T have a session.</p>
[/Plugin:NotEquals]

 

Leave a Reply

Your email address will not be published. Required fields are marked *