Skip to content

Instantly share code, notes, and snippets.

@darkcar
Created March 20, 2018 16:19
Show Gist options
  • Save darkcar/173fe8a5750b40d3f2ca8c26cd377120 to your computer and use it in GitHub Desktop.
Save darkcar/173fe8a5750b40d3f2ca8c26cd377120 to your computer and use it in GitHub Desktop.
The login portlet
package elvis.sgi.sk.ca.signin.portlet;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.portlet.NoRedirectActionResponse;
import com.liferay.portal.kernel.struts.PortletActionInvoker;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
/**
* Portlet implementation class ELVISSignInPortlet
*/
public class ELVISSignInPortlet extends MVCPortlet {
private static Log _log = LogFactoryUtil.getLog(ELVISSignInPortlet.class);
@Override
public void processAction(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
String className = "com.liferay.portlet.login.action.LoginAction";
PortletConfig portletConfig = getPortletConfig();
NoRedirectActionResponse noRedirectActionResponse =
new NoRedirectActionResponse(actionResponse);
try {
PortletActionInvoker.processAction(className, portletConfig, actionRequest, noRedirectActionResponse);
} catch (Exception e) {
_log.error(e, e);
}
String login = ParamUtil.getString(actionRequest, "login");
String password = ParamUtil.getString(actionRequest, "password");
String rememberMe = ParamUtil.getString(actionRequest, "rememberMe");
if (Validator.isNull(noRedirectActionResponse.getRedirectLocation())) {
actionResponse.setRenderParameter("login", login);
actionResponse.setRenderParameter("rememberMe", rememberMe);
} else {
String redirect = "/web/elvis/login";
actionResponse.sendRedirect(redirect);
}
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long companyId = themeDisplay.getCompanyId();
int status = 0;
try {
status = UserLocalServiceUtil.authenticateByScreenName(companyId, login, password, null, null, null);
System.out.println(status);
User userString = null;
if(status==1){
userString = UserLocalServiceUtil.getUserByScreenName(companyId, login);
String redirect = PortalUtil.getPathMain() + "/portal/login?login=" + userString.getEmailAddress() + "&password=" + password;
System.out.println(redirect);
actionResponse.sendRedirect(redirect);
}
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment