Hello,
I wanted to detect if an user is logged in or not using sightly. I know because of this link: https://docs.adobe.com/docs/en/aem/6-0/develop/sightly/global-objects.html
That I have access to the currentSession from sightly. Sadly I cannot find any documentation on how to use this object, I was reading the java documentation of javax.servlet.http.HttpSession but I have no idea how to use it within sightly. Does somebody have examples regarding this currentSession object or even better knows how to detect if the user is logged in or not using sightly only.
Thanks for reading and all the help you can provide
Solved! Go to Solution.
${currentSession.userID}
The above sightly expression should give you the details of the current logged in user. If this returns a value of null / anonymous (not sure which value is returned) then there is no logged in session available.
You cannot log in to AEM using Sightly. Sightly is a template language that you use to create components that an author drops into an AEM web page (as opposed to JSP). We have a lot of community sourced articles that discuss how to build AEM components using Sightly. See this thread for a reference of Sightly articles.
Plus - we are having a webinar on Sightly later this month for all community members:
http://scottsdigitalcommunity.blogspot.ca/2016/03/ask-aem-community-experts-deep-dive.html
BTW - you do not use javax.servlet.http.HttpSession in AEM. You work with JCR Sessions.
https://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Session.html
Hope this helps.
Views
Replies
Total Likes
I did not mean to Log in using sightly. According to the documentation I have access to some global objects from sightly, One of them is called currentSession, and for a description it says "javax.servlet.http.HttpSession" in the adobe documentation see docs
I just wanted to know if by using this I could detect if there is a valid session or not (Someone is logged in or not)
Views
Replies
Total Likes
OK - that makes more sense. You can access all objects easily using Sightly, For example - notice on that list - there is wcmmode. You can get this object in Sightly using this syntax:
<div data-sly-test="${wcmmode.edit}">Show this only in edit mode to the author</div>
Likewise, consider currentPage. You can get this object in Sightly using this syntax:
<div>currentPageName : ${currentPage.name}</div>
You should be able to get all objects on that list using:
${ObjectName}
See all five blog articles here:
http://blogs.adobe.com/experiencedelivers/experience-management/sightly-intro-part-1/
As well to learn more about Sightly - please sign up to March version of Ask the COmmuiity Experts - this month Praveen Is presenting - a top AEM COmmuntiy member and very knowledge on Sightly.
Views
Replies
Total Likes
${currentSession.userID}
The above sightly expression should give you the details of the current logged in user. If this returns a value of null / anonymous (not sure which value is returned) then there is no logged in session available.
Hi
As mentioned by Naveen, you can use ${currentSession.userID}. apart from this, please find below the list of objects that could be used:
These objects provide the standard AEM execution context (as global.jsp does for JSPs, for example). Each object is backed by the corresponding Java object.
Variable Name | Description |
---|---|
component | com.day.cq.wcm.api.components.Component |
componentContext | com.day.cq.wcm.api.components.ComponentContext |
currentDesign | com.day.cq.wcm.api.designer.Design |
currentNode | javax.jcr.Node |
currentPage | com.day.cq.wcm.api.Page |
currentSession | javax.servlet.http.HttpSession |
currentStyle | com.day.cq.wcm.api.designer.Style |
designer | com.day.cq.wcm.api.designer.Designer |
editContext | com.day.cq.wcm.api.components.EditContext |
log | org.slf4j.Logger |
out | java.io.PrintWriter |
pageManager | com.day.cq.wcm.api.PageManager |
reader | java.io.BufferedReader |
request | org.apache.sling.api.SlingHttpServletRequest |
resource | org.apache.sling.api.resource.Resource |
resourceDesign | com.day.cq.wcm.api.designer.Design |
resourcePage | com.day.cq.wcm.api.Page |
response | org.apache.sling.api.SlingHttpServletResponse |
sling | org.apache.sling.api.scripting.SlingScriptHelper |
slyWcmHelper | com.adobe.cq.sightly.WCMScriptHelper |
wcmmode | com.day.cq.wcm.api.WCMMode (in Sightly, evaluates to a string, either "EDIT" or "DESIGN") |
xssAPI | com.adobe.granite.xss.impl.XSSAPImpl |
Link:- https://docs.adobe.com/docs/en/aem/6-1/develop/sightly/global-objects.html
I hope this will help you.
Thanks and Regards
Kautuk Sahni
Thanks Naveem, that was exactly what I needed a thousand brownie points for you.
Views
Replies
Total Likes