Blogs
This is the second part of the "Extending Liferay DXP - User Registration" blog. In this blog we explore the ways of implementing registration process for a portal with multiple sites.
Portal Sites Configuration
Let’s presume we have a portal with the following sites configured:
- "Liferay", default site, will not be listed
 - "Site 1", site with open membership
 - "Site 2", site with restricted membership
 - "Site 3", site with restricted membership
 - "Site 4", private site, will not be listed
 
 
Each of the sites has its own description which we want to display to the user:
 ![]()
User Registration Process Flow
The main steps of the user registration process that we are going to implement here are:
- Check if a user already has an account
 - If user already has an account but is not signed in, ask to sign in
 - If user is already signed in, show current read-only details of a user
 - Show the sites which is the user is not a member of with the description of the site when the site is selected
 - Collect additional information from the user if the user has selected a 'restricted' site
 - User reviews the request, with the ability to save request as PDF file, and submits the form
 - On form submission: 
    
- Automatically create user account if user does not exist
 - If the site selected is 'open', user is automatically enrolled into this site
 - If the site selected is 'restricted', site membership request is created for this user
 - If the site selected is 'restricted', notification email is sent to site owners with user details attached as PDF
 
 
For the implementation of this process we use SmartForms.
Here we show only essential screenshots of the User Registration Form, the entire form definition can be downloaded (see link at the end of this blog). Once it is imported you can use Visual Designer to see how the business rules are implemented.
User Flow
1. User is asked to enter an email, SmartForms connects to portal webservices to check if such email is already registered (the source code for all webservices is at the end of the blog)
2. If user already has an account, then 'must log in' message is displayed
 
3. If user is already signed in, the form is automatically populated with user details (user data is automatically brought by SmartForms from Liferay environment).
 
4. On the next page the user is asked to select a site from the site list obtained via webservice. When user selects a site the description of the site is displayed (webservice again). You can put your own definition of Terms & Conditions together with 'I agree' checkbox.
 
.
5. If the site the user selected is of 'restricted' type, the user is asked to provide additional information.
 
SmartForms will automatically handle this rule once you add the following state condition to 'Company/Organisation Details' page. Visual Designer screenshot:
 
6. The membership request summary is displayed on a final page, allowing the user to save membership request details as PDF file and Submit the form when ready.
 
7. Processing the submitted form. There are two form submission handlers :
- Emailer, which sends a 'membership site request' email to Site Owner(s) if the selected site is 'restricted', attaching PDF that contains all data submitted by the user (implemented using SmartForms workflow, but of course you can use your own).
 - Webhook, that creates user account if the user is not registered yet and submits membership request of this user to a selected site. (the source code for this webhook is at the end of the blog).
 
That's it. That is the user flow, which is probably longer than the implementation notes listed below.
Implementation Notes
Data Flow
Below is the generic data flow where the Form Controller could be implemented inside or outside of the portal.
 
In our implementation we are using SmartForms to build and run User Registration Form. SmartForms Cloud is acting as Form Controller.
 
User Registration Handler Code
User registration handler implements:
- SOAP webservices to query portal data and populate form fields
 - JSON REST endpoint to executes all relevant actions on form submission, creation of portal users and site membership requests
 
Here we provide source code for essential functions, link to get the full source code is at the end of the blog.
Checking if User is Registered
                                                                 |  
    
Getting List of Open and Protected Sites
                                                                                                             |  
    
Getting Email Addresses of Owners of a Site
                                                                                                   |  
    
Creating User Account and Site Membership Request
                                                                                                                                                                                    
                      |  
    
Full source code for Form Handler project can be downloaded from here:
http://extras.repo.smartfor.ms/blogs/Extending-Liferay-User-Registration/userRegistration-source.zip
To make it work on your Liferay installation using SmartForms you will need to:
- install SmartForms, instructions are here: Getting Started
 - download Liferay User Registration Form definition from here: http://extras.repo.smartfor.ms/blogs/Extending-Liferay-User-Registration/smartforms.form.Liferay_Registration_Form.v1.far
 - import this definition into your SmartForms library, instructions are here: Managing SmartForms Library
 - deploy User Registration handler OSGI module to your portal by downloading it from here: http://extras.repo.smartfor.ms/blogs/Extending-Liferay-User-Registration/userRegistration-1.0-SNAPSHOT.jar
 - make sure that your portal is accessible from the internet via domain name or IP Address (localhost will not do the job as SmartForms Cloud will not be able to reach your SmartForm Handler module)
 
One more thing, in SmartForm webhook configuration please change the localhost to URL of your portal:
 
Feel free to ask questions if you run into problems ...

