Forums de discussion

Custom registration portlet and redirect to login

Odysseas Doumas, modifié il y a 7 années.

Custom registration portlet and redirect to login

New Member Publications: 17 Date d'inscription: 22/06/16 Publications récentes
I have created a custom JSF portlet that serves as a registration form. My goal is NOT to extend the default registration, this portlet is specific to our requirments, and it also registrers a new organization and some other custom Entitites. So far it works.

What i need now is, after the registration logic, to emulate the default registration portlet, redirect to the login page, and show the messages like "your password was sent to email etc etc". I managed to do the redirection but the SessionMessages are never shown. My code is this.

LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
		ExternalContext externalContext = liferayFacesContext.getExternalContext();
	
		PortletRequest portletRequest = liferayFacesContext.getPortletRequest();
		HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest);

		long companyId = liferayFacesContext.getCompanyId();
		
		String registrationType = signInBackingBean.getRegistrationType();		
		User user = null;
		Organization registeredOrganization = null;

		try {

			ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(),portletRequest);
			
			//Register user and organization
			user = registerUser(companyId, registrationType, liferayFacesContext, serviceContext);

			if (!registrationType.equals("")){
				registeredOrganization = registerOrganization(companyId, user, registrationType, serviceContext);
			}		
			
			
			// Session messages
			
			if (user.getStatus() == WorkflowConstants.STATUS_APPROVED) {
				_LOGGER.info("Approved");
				SessionMessages.add(
						request, "userAdded", user.getEmailAddress());
				SessionMessages.add(
						request, "userAddedPassword",
						user.getPasswordUnencrypted());
			}
			else {
				_LOGGER.info("Pending");
				SessionMessages.add(
						request, "userPending", user.getEmailAddress());
			}


			// Send redirect
			
			String login = null;
			String authType = PortalUtil.getCompany(request).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();
			}

			PortletURL loginURL = getLoginURL(request, liferayFacesContext.getThemeDisplay().getPlid());
			loginURL.setParameter("login", login);
			String redirect = loginURL.toString();
			externalContext.redirect(redirect);

                       //Handle exceptions
			


My getLoginURL method is this (taken from the LoginUtil source)

	//Returns the URL for the Liferay login portlet
	private PortletURL getLoginURL(HttpServletRequest request, long plid)
			throws PortletModeException, WindowStateException {

		PortletURL portletURL = PortletURLFactoryUtil.create(
				request, PortletKeys.LOGIN, plid, PortletRequest.RENDER_PHASE);

		portletURL.setParameter("saveLastPath", Boolean.FALSE.toString());
		portletURL.setParameter("struts_action", "/login/login");
		portletURL.setPortletMode(PortletMode.VIEW);
		portletURL.setWindowState(WindowState.MAXIMIZED);

		return portletURL;
	}
thumbnail
Neil Griffin, modifié il y a 7 années.

RE: Custom registration portlet and redirect to login

Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
I would recommend that you look at the source of the jsf-registration-portlet demo.