/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This file is part of Liferay Social Office. Liferay Social Office is free * software: you can redistribute it and/or modify it under the terms of the GNU * Affero General Public License as published by the Free Software Foundation, * either version 3 of the License, or (at your option) any later version. * * Liferay Social Office is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License * for more details. * * You should have received a copy of the GNU General Public License along with * Liferay Social Office. If not, see http://www.gnu.org/licenses/agpl-3.0.html. */ package com.liferay.so.hook.action; import com.liferay.portal.kernel.exception.NoSuchUserException; import com.liferay.portal.kernel.model.User; import com.liferay.portal.kernel.service.UserLocalServiceUtil; import com.liferay.portal.kernel.struts.BaseStrutsAction; import com.liferay.portal.kernel.theme.ThemeDisplay; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.kernel.util.PortalUtil; import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.util.WebKeys; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @author Matthew Kong */ public class FindUserAction extends BaseStrutsAction { @Override public String execute( HttpServletRequest request, HttpServletResponse response) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute( WebKeys.THEME_DISPLAY); long userId = ParamUtil.getLong(request, "p_u_i_d"); User user = UserLocalServiceUtil.fetchUser(userId); if ((user != null) && user.hasPublicLayouts()) { response.sendRedirect(user.getDisplayURL(themeDisplay, false)); return null; } String noSuchEntryRedirect = ParamUtil.getString( request, "noSuchEntryRedirect"); if (Validator.isNotNull(noSuchEntryRedirect)) { response.sendRedirect( PortalUtil.escapeRedirect(noSuchEntryRedirect)); } else { PortalUtil.sendError(new NoSuchUserException(), request, response); } return null; } }