Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Login.event.post PROBLEM
Hello to everyone, I'm new into this big world, and I using Liferay 7.1 G.A 1.
I do an practice example:
1- I have 4 users group: A, B, C, D.
2- Each group have an homepage.
3- Everyone group contein some users.
4- If a user login, he must see the homepage of the group to which he belongs. E.g (Nicolas belongs at user group A, if he will login he must see the homepage of group user A).
To do this scenario I write my login.event.post. Follow below:
Now I know getGroupName is wrong, how can I take the name of the Users Group (like on top A, B, C D)?
And how can (go to specific URL site templete) of each group like in if else construct?
I do an practice example:
1- I have 4 users group: A, B, C, D.
2- Each group have an homepage.
3- Everyone group contein some users.
4- If a user login, he must see the homepage of the group to which he belongs. E.g (Nicolas belongs at user group A, if he will login he must see the homepage of group user A).
To do this scenario I write my login.event.post. Follow below:
package content;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.LifecycleAction;
import com.liferay.portal.kernel.events.LifecycleEvent;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.CompanyLocalServiceUtil;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@Component(immediate = true, property = { "key=login.events.post" }, service = LifecycleAction.class)
public class MyLoginLoginPostAction implements LifecycleAction {
@Override
public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {
if (_log.isInfoEnabled()) {
_log.info("login.event.post=" + lifecycleEvent);
}
try {
User screenName = _portal.getUser(lifecycleEvent.getRequest());
String url = _portal.getHomeURL(lifecycleEvent.getRequest());
if (_log.isInfoEnabled()) {
if ([b][color=#ff0000]getGroupName[/color][/b]() == "GruppoAdminDoc") {
// [b][color=#006400]go to specific URL admin documentation site templete[/color][/b]
} else if ([color=#ff0000][b]getGroupName [/b][/color]== "GruppoAdminNews") {
// [color=#006400][b]go to specific URL admin news site templete[/b][/color]
} else if ([color=#ff0000][b]getGroupName [/b][/color]== "GruppoAdminServizi") {
//[color=#006400] [b]go to specific URL admin service site templete[/b][/color]
} else if ([b][color=#ff0000]getGroupName [/color][/b]== "GruppoUtenti") {
// [b][color=#006400]go to specific URL user site templete[/color][/b]
}
}
} catch (Exception e) {
throw new ActionException(e);
}
}
@Reference(unbind = "-")
protected void setPortal(Portal portal) {
_portal = portal;
}
private Portal _portal;
private static final Log _log = LogFactoryUtil.getLog(MyLoginLoginPostAction.class);
}
Now I know getGroupName is wrong, how can I take the name of the Users Group (like on top A, B, C D)?
And how can (go to specific URL site templete) of each group like in if else construct?
And how can (go to specific URL site templete) of each group like in if else construct?
Regular users cannot view user group site templates, because they're restricted to administrators.
If these are User Group sites (as opposed to regular sites), then as long as the user is a member of the user group, they will see the user group's pages in their own personal pages.
Tanks for reply! I understood what you say, regard the Users and the restricted rules by the administrator but:
- Now, I know the function getGroupName is wrong, how can I take the NAME of the Group (e.g on top A, B, C D)?
- How I can (go to specific URL site templete) of each group like in if else construct?
- Now, I know the function getGroupName is wrong, how can I take the NAME of the Group (e.g on top A, B, C D)?
- How I can (go to specific URL site templete) of each group like in if else construct?
Liferay Noob myself, so not sure if this will actually help. I'm going to do something similar so I had a quick look around.
My impression would be
- Get current user
User user = PortalUtil.getUser(lifecycleEvent.getRequest());
- Get his Group(s)
(https://docs.liferay.com/portal/7.0/javadocs/portal-kernel/com/liferay/portal/kernel/model/User.html)
Group g = user.getGroup() / List<Group> g = user.getGroups()
- Now there's a couple of things I found (and didn't try out
)
maybe: if(g.isUserGroup()){ /* build the URL from g.getDescriptiveName() */ }
https://docs.liferay.com/portal/7.0/javadocs/portal-kernel/com/liferay/portal/kernel/model/Group.html#getDisplayURL-com.liferay.portal.kernel.theme.ThemeDisplay-
g.getDisplayURL(/*Find out how to get ThemeDisplay*/)
This guy seems to be doing what you want, but I think it's for Liferay 6, considering the publication date. Might be helpful
http://www.sonicon.net/ca/bloc/-/blogs/liferay-redirect-after-log-1
Hope this help and keep this updated if you find out how to do it