Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liferay: change the users landing page depending on organization

Tags:

java

liferay

I'm using Liferay 6.0. I have multiple organizations and would like to change the user's landing page depending on organization.

I'm new to Liferay, tried to find some suggestions but could not find the correct answer.

Is it possible to do with out-of-the-box tools? without writing a code?

If code needed, what is the best solution?

Please help, Thank you

like image 781
V.K. Avatar asked Jan 30 '12 22:01

V.K.


1 Answers

In Liferay 6 the default landing page can be set with the property default.landing.page.path, but it is a general setting affecting each user in the portal instance.

To change the landing page of a user depending on the organization a custom action for the "post login" portal event is needed. Eventually, the property login.events.post has to point to a custom login action:

login.events.post=yourcode.CustomLandingPageAction

There are two options to achieve this:

  • With a hook: http://www.liferay.com/es/community/forums/-/message_boards/message/9824650
  • Modifying portal-ext.properties accordingly within your portlet project: http://liferaydemystified.blogspot.com/2011/04/liferay-default-landing-page.html

A custom action to make the user of an organization to land in the organization's private pages (derived from the links above):

public class CustomLandingPageAction extends Action {

    public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {
            try {
                    doRun(request, response);
            } catch (Exception e) {
                    throw new ActionException(e);
            }
    }

    protected void doRun(HttpServletRequest request, HttpServletResponse response) 
            throws Exception {

        long companyId = PortalUtil.getCompanyId(request);
        String path = PrefsPropsUtil.getString(companyId, PropsKeys.DEFAULT_LANDING_PAGE_PATH);;

        if (Validator.isNull(path)) {
            User user = PortalUtil.getUser(request);
            String language = user.getLocale().getLanguage();
            List<Organization> orgList = OrganizationLocalServiceUtil.getUserOrganizations(user.getUserId());

            // Default landing page: go to the path in DefaultLandingPageAction
            LastPath lastPath = new LastPath(StringPool.BLANK, path, new HashMap<String, String[]>());

            // But if the logged user is in some community
            if (!orgList.isEmpty()){
                // and such community has a private page
                if (orgList.get(0).hasPrivateLayouts()) {
                    // go there instead
                    String orgFriendlyURL = orgList.get(0).getGroup().getFriendlyURL();
                    String myPath = "/" + language + "/group" + orgFriendlyURL;

                    lastPath = new LastPath(StringPool.BLANK, myPath);
                }
            }

            HttpSession session = request.getSession();                        
            session.setAttribute(WebKeys.LAST_PATH, lastPath);
        }
    }
}
like image 185
jalopaba Avatar answered Nov 15 '22 08:11

jalopaba