List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getCompany
public Company getCompany()
From source file:com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand.java
License:Open Source License
protected void sendRedirect(ActionRequest actionRequest, ActionResponse actionResponse, ThemeDisplay themeDisplay, User user, String password) throws Exception { String login = null;//from w w w . j av a2 s .c o m Company company = themeDisplay.getCompany(); String authType = company.getAuthType(); if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) { login = String.valueOf(user.getUserId()); } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) { login = user.getScreenName(); } else { login = user.getEmailAddress(); } HttpServletRequest request = _portal.getHttpServletRequest(actionRequest); String redirect = _portal.escapeRedirect(ParamUtil.getString(actionRequest, "redirect")); if (Validator.isNotNull(redirect)) { HttpServletResponse response = _portal.getHttpServletResponse(actionResponse); _authenticatedSessionManager.login(request, response, login, password, false, null); } else { PortletURL loginURL = LoginUtil.getLoginURL(request, themeDisplay.getPlid()); loginURL.setParameter("login", login); redirect = loginURL.toString(); } actionResponse.sendRedirect(redirect); }
From source file:com.liferay.login.web.internal.portlet.action.CreateAnonymousAccountMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletConfig portletConfig = (PortletConfig) actionRequest .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG); String portletName = portletConfig.getPortletName(); if (!portletName.equals(LoginPortletKeys.FAST_LOGIN)) { throw new PrincipalException("Unable to create anonymous account"); }/* w w w. j a v a 2 s. c om*/ if (actionRequest.getRemoteUser() != null) { actionResponse.sendRedirect(themeDisplay.getPathMain()); return; } String cmd = ParamUtil.getString(actionRequest, Constants.CMD); String emailAddress = ParamUtil.getString(actionRequest, "emailAddress"); PortletURL portletURL = PortletURLFactoryUtil.create(actionRequest, LoginPortletKeys.FAST_LOGIN, PortletRequest.RENDER_PHASE); portletURL.setParameter("mvcRenderCommandName", "/login/login_redirect"); portletURL.setParameter("emailAddress", emailAddress); portletURL.setParameter("anonymousUser", Boolean.TRUE.toString()); portletURL.setWindowState(LiferayWindowState.POP_UP); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); try { if (cmd.equals(Constants.ADD)) { addAnonymousUser(actionRequest, actionResponse); sendRedirect(actionRequest, actionResponse, portletURL.toString()); } else if (cmd.equals(Constants.UPDATE)) { Company company = themeDisplay.getCompany(); if (!company.isStrangers()) { throw new PrincipalException.MustBeEnabled(company.getCompanyId(), PropsKeys.COMPANY_SECURITY_STRANGERS); } jsonObject = updateIncompleteUser(actionRequest, actionResponse); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } } catch (Exception e) { if (cmd.equals(Constants.UPDATE)) { jsonObject.putException(e); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } else if (e instanceof UserEmailAddressException.MustNotBeDuplicate) { User user = _userLocalService.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress); if (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE) { SessionErrors.add(actionRequest, e.getClass()); } else { sendRedirect(actionRequest, actionResponse, portletURL.toString()); } } else if (e instanceof CaptchaConfigurationException || e instanceof CaptchaTextException || e instanceof CompanyMaxUsersException || e instanceof ContactNameException || e instanceof EmailAddressException || e instanceof GroupFriendlyURLException || e instanceof UserEmailAddressException) { SessionErrors.add(actionRequest, e.getClass(), e); } else { _log.error("Unable to create anonymous account", e); _portal.sendError(e, actionRequest, actionResponse); } } }
From source file:com.liferay.login.web.internal.portlet.action.ForgotPasswordMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); if (!company.isSendPassword() && !company.isSendPasswordResetLink()) { throw new PrincipalException.MustBeEnabled(company.getCompanyId(), PropsKeys.COMPANY_SECURITY_SEND_PASSWORD, PropsKeys.COMPANY_SECURITY_SEND_PASSWORD_RESET_LINK); }/*from w w w .ja v a 2 s. c o m*/ try { if (PropsValues.USERS_REMINDER_QUERIES_ENABLED) { checkReminderQueries(actionRequest, actionResponse); } else { checkCaptcha(actionRequest); sendPassword(actionRequest, actionResponse); } } catch (Exception e) { if (e instanceof CaptchaConfigurationException || e instanceof CaptchaTextException || e instanceof UserEmailAddressException) { SessionErrors.add(actionRequest, e.getClass()); } else if (e instanceof NoSuchUserException || e instanceof RequiredReminderQueryException || e instanceof SendPasswordException || e instanceof UserActiveException || e instanceof UserLockoutException || e instanceof UserReminderQueryException) { if (PropsValues.LOGIN_SECURE_FORGOT_PASSWORD) { sendRedirect(actionRequest, actionResponse, null); } else { SessionErrors.add(actionRequest, e.getClass(), e); } } else { _portal.sendError(e, actionRequest, actionResponse); } } }
From source file:com.liferay.login.web.internal.portlet.action.ForgotPasswordMVCActionCommand.java
License:Open Source License
protected void sendPassword(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); User user = getUser(actionRequest);// ww w . jav a2s .c o m if (PropsValues.USERS_REMINDER_QUERIES_ENABLED) { if (PropsValues.USERS_REMINDER_QUERIES_REQUIRED && !user.hasReminderQuery()) { throw new RequiredReminderQueryException( "No reminder query or answer is defined for user " + user.getUserId()); } String answer = ParamUtil.getString(actionRequest, "answer"); String reminderQueryAnswer = user.getReminderQueryAnswer(); if (!reminderQueryAnswer.equals(answer)) { throw new UserReminderQueryException("Reminder query answer does not match answer"); } } PortletPreferences portletPreferences = actionRequest.getPreferences(); String languageId = LanguageUtil.getLanguageId(actionRequest); String emailFromName = portletPreferences.getValue("emailFromName", null); String emailFromAddress = portletPreferences.getValue("emailFromAddress", null); String emailToAddress = user.getEmailAddress(); String emailParam = "emailPasswordSent"; if (company.isSendPasswordResetLink()) { emailParam = "emailPasswordReset"; } String subject = portletPreferences.getValue(emailParam + "Subject_" + languageId, null); String body = portletPreferences.getValue(emailParam + "Body_" + languageId, null); LoginUtil.sendPassword(actionRequest, emailFromName, emailFromAddress, emailToAddress, subject, body); HttpServletRequest request = _portal.getHttpServletRequest(actionRequest); SessionMessages.add(request, "passwordSent"); sendRedirect(actionRequest, actionResponse, null); }
From source file:com.liferay.login.web.internal.portlet.action.ForgotPasswordMVCRenderCommand.java
License:Apache License
@Override public String render(RenderRequest renderRequest, RenderResponse renderResponse) { System.out.println("In " + getClass().getName() + " render"); ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); if (!company.isSendPassword() && !company.isSendPasswordResetLink()) { return "/login.jsp"; }/*from w ww. j a v a 2 s.com*/ renderResponse.setTitle(themeDisplay.translate("forgot-password")); return "/forgot_password.jsp"; }
From source file:com.liferay.login.web.internal.portlet.util.LoginUtil.java
License:Open Source License
public static Map<String, String> getEmailDefinitionTerms(PortletRequest portletRequest, String emailFromAddress, String emailFromName, boolean showPasswordTerms) { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); Map<String, String> definitionTerms = new LinkedHashMap<>(); definitionTerms.put("[$FROM_ADDRESS$]", HtmlUtil.escape(emailFromAddress)); definitionTerms.put("[$FROM_NAME$]", HtmlUtil.escape(emailFromName)); if (showPasswordTerms) { definitionTerms.put("[$PASSWORD_RESET_URL$]", LanguageUtil.get(themeDisplay.getLocale(), "the-password-reset-url")); }/*from ww w. j av a2s . c o m*/ Company company = themeDisplay.getCompany(); definitionTerms.put("[$PORTAL_URL$]", company.getVirtualHostname()); definitionTerms.put("[$REMOTE_ADDRESS$]", LanguageUtil.get(themeDisplay.getLocale(), "the-browser's-remote-address")); definitionTerms.put("[$REMOTE_HOST$]", LanguageUtil.get(themeDisplay.getLocale(), "the-browser's-remote-host")); definitionTerms.put("[$TO_ADDRESS$]", LanguageUtil.get(themeDisplay.getLocale(), "the-address-of-the-email-recipient")); definitionTerms.put("[$TO_NAME$]", LanguageUtil.get(themeDisplay.getLocale(), "the-name-of-the-email-recipient")); definitionTerms.put("[$USER_ID$]", LanguageUtil.get(themeDisplay.getLocale(), "the-user-id")); if (showPasswordTerms) { definitionTerms.put("[$USER_PASSWORD$]", LanguageUtil.get(themeDisplay.getLocale(), "the-user-password")); } definitionTerms.put("[$USER_SCREENNAME$]", LanguageUtil.get(themeDisplay.getLocale(), "the-user-screen-name")); return definitionTerms; }
From source file:com.liferay.login.web.internal.portlet.util.LoginUtil.java
License:Open Source License
public static void sendPassword(ActionRequest actionRequest, String fromName, String fromAddress, String toAddress, String subject, String body) throws Exception { HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); if (!company.isSendPassword() && !company.isSendPasswordResetLink()) { return;// w ww . j a v a 2 s .c om } ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest); UserLocalServiceUtil.sendPassword(company.getCompanyId(), toAddress, fromName, fromAddress, subject, body, serviceContext); }
From source file:com.liferay.login.web.internal.servlet.taglib.include.CreateAccountNavigationPostPageInclude.java
License:Open Source License
@Override public void include(PageContext pageContext) throws JspException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String mvcRenderCommandName = request.getParameter("mvcRenderCommandName"); if ("/login/create_account".equals(mvcRenderCommandName)) { return;/* w w w.ja v a 2s . com*/ } ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); if (!company.isStrangers()) { return; } PortletConfig portletConfig = (PortletConfig) request.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG); String portletName = portletConfig.getPortletName(); if (portletName.equals(PortletKeys.FAST_LOGIN)) { return; } IconTag iconTag = new IconTag(); iconTag.setIconCssClass("icon-plus"); iconTag.setMessage("create-account"); try { iconTag.setUrl(_portal.getCreateAccountURL(request, themeDisplay)); } catch (Exception e) { throw new JspException(e); } iconTag.doTag(pageContext); }
From source file:com.liferay.login.web.internal.servlet.taglib.include.ForgetPasswordNavigationPostPageInclude.java
License:Open Source License
@Override public void include(PageContext pageContext) throws JspException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String mvcRenderCommandName = request.getParameter("mvcRenderCommandName"); if ("/login/forgot_password".equals(mvcRenderCommandName)) { return;/*from ww w . j av a 2s. c o m*/ } ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); if (!company.isSendPassword() && !company.isSendPasswordResetLink()) { return; } RenderURLTag renderURLTag = new RenderURLTag(); renderURLTag.setPageContext(pageContext); renderURLTag.addParam("mvcRenderCommandName", "/login/forgot_password"); renderURLTag.setVar("forgotPasswordURL"); renderURLTag.setWindowState(WindowState.MAXIMIZED.toString()); renderURLTag.doTag(pageContext); String forgetPasswordURL = (String) pageContext.getAttribute("forgotPasswordURL"); IconTag iconTag = new IconTag(); iconTag.setIconCssClass("icon-question-sign"); iconTag.setMessage("forgot-password"); iconTag.setUrl(forgetPasswordURL); iconTag.doTag(pageContext); }
From source file:com.liferay.site.admin.web.internal.display.context.SiteAdminDisplayContext.java
License:Open Source License
public int getOrganizationsCount(Group group) { LinkedHashMap<String, Object> organizationParams = new LinkedHashMap<>(); ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); organizationParams.put("groupOrganization", group.getGroupId()); organizationParams.put("organizationsGroups", group.getGroupId()); return OrganizationLocalServiceUtil.searchCount(company.getCompanyId(), OrganizationConstants.ANY_PARENT_ORGANIZATION_ID, null, null, null, null, organizationParams); }