Tuesday, 10 December 2019

Pre and Post Login Events using blade hook in Liferay DXP

For Post Login Event we need to setup the @Component in class

@Component(
immediate = true, property = {"key=login.events.post"},
service = LifecycleAction.class
)

For Pre Login Event we need to setup the @Component like this -:

@Component(
immediate = true, property = {"key=login.events.pre"},
service = LifecycleAction.class
)

PreLogin Code

@Component(
immediate = true, property = {"key=login.events.pre"},
service = LifecycleAction.class
)

public class PreLoginHook implements LifecycleAction {

@Override
public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {

log.info("Call Pre Action" );

}
}



Post Login Code

@Component(
immediate = true, property = {"key=login.events.post"},
service = LifecycleAction.class
)

public class PostLoginHook implements LifecycleAction {

@Override
public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {

HttpServletRequest req = lifecycleEvent.getRequest();
PermissionChecker permissionChecker;
ThemeDisplay themeDisplay = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);
User user = null;
try {​​​​​
user = PortalUtil.getUser(req);
}​​​​​ catch (PortalException e) {​​​​​
e.printStackTrace();
}​​​​​
permissionChecker = PermissionCheckerFactoryUtil.create(user);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
String PhoneNum = user.getExpandoBridge().getAttribute("PhoneNumber");

}


}

 Form Entries API Controller Class ============ render(){ String dataIs = getData(); //make your changes try { long formIns...