1

我正在开发一个 liferay 项目,其中有 2 个站点,1 个用于管理员,1 个用于用户。管理员和用户根据用户组进行区分。当管理员登录时,他应该被重定向到管理页面,当用户登录时,他们应该被重定向到用户页面。我们如何使用 Blade 或 Hook 插件在 Liferay 7 中实现此功能?任何帮助,将不胜感激。谢谢!!!

4

1 回答 1

3

你可以在这里找到一个插件示例:

https://www.e-systems.tech/blog/-/blogs/liferay-7-how-to-get-a-session-object-after-login-

基本上,如果你想要一个登录后挂钩,这个例子就足够了。

要使用 liferay 服务,在新样式中,您需要一些参考资料

private Portal portal;
private UserLocalService userLocalService;

@Reference
private void setUserLocalService(UserLocalService service){
    this.userLocalService=service;
}

@Reference
private void setPortalUtil(Portal portal){
    this.portal=portal;
}

现在,获取有关门户的用户信息和更多数据

final long companyId = portal.getCompanyId(request);
final HttpSession session = request.getSession();

这条线应该对:

User user = (User)session.getAttribute(WebKeys.USER);

对于重定向:在 URL 中使用 redirect 参数。

或者,这段代码会有所帮助..

Map params = new HashMap();

params.put("p_l_id", new String[] {"PRI.1.1"});

LastPath lastPath = new LastPath("/c", "/portal/layout", params);

ses.setAttribute(WebKeys.LAST_PATH, lastPath);

为此,您还可以检查 auth.forward.by.last.path 属性

于 2016-09-12T21:21:56.323 回答