使用 Blade 在 Liferay 7 中自定义 Post 登录操作挂钩

Custom Post Login Action Hook in Liferay 7 using Blade

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

您可以在此处找到插件示例:

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

基本上,如果您想要一个 post 登录挂钩,这个示例应该足够了。

要使用 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 中的重定向参数。

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

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 属性