简体   繁体   中英

How to get Liferay user email address in JavaScript?

I can able to get themeDisplay object in JavaScript.

Refereed : https://web.liferay.com/web/pankaj.kathiriya/blog/-/blogs/usage-of-liferay-js-object

$( document ).ready(function() {
  var userid=Liferay.ThemeDisplay.getUserId;
  alert(userid);
});

How to get User email Address ?

Liferay JS utility's Liferay.ThemeDisplay or just themeDisplay does not implicitly contain user's email address. It just exposes userId and userName while it doesn't have any getUser or User object in it.

However, you can achieve that by overridding \\html\\common\\themes\\top_js.jspf using JSP hook. All you need to do is to add following lines below getUserName: function() { :

getUserEmailAddress: function() {
    <c:choose>
        <c:when test="<%= themeDisplay.isSignedIn() %>">
            return "<%= UnicodeFormatter.toString(user.getEmailAddress()) %>";
        </c:when>
        <c:otherwise>
            return "";
        </c:otherwise>
    </c:choose>
},

Then you will be able to get user's email address by either Liferay.ThemeDisplay.getUserEmailAddress(); or themeDisplay.getUserEmailAddress(); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM