This project consists of a registration form developed with Angular ready to be deployed as a Liferay portlet. A Headless API has also been developed to serve as the backend of the application.
The Service Builder tool has been used to generate the necessary code (classes and interfaces) to provide a persistence layer to the API. In the feature/service-builder-tier
branch, as an example, the code generated by the tool is included, since it has not yet been implemented.
This portlet has been developed using Liferay Portal CE 7.4 GA3. Specifically, the Tomcat Bundle has been used using the Hypersonic embedded database.
To adapt the Angular application, generator-liferay-js has been used.
Location: /register-form-liferay
- Access the
register-form-liferay
directory. - Install the dependencies:
npm install
- Set the variable
liferayDir
(directory where Liferay is installed) to.npmbuildrc.
- Access the
register-form-liferay/src/environments
directory and modify theenvironment.ts
andenvironment.prod.ts
files to set the following variables:- apiUrl: API URL.
- storage: persistence type
storage="local"
if you want the form to store the data in the browser's Local Storage,storage="persistent"
if you want the application to send the information to the API. - recaptchaSiteKey: key required for Google reCAPTCHA. A valid key is provided for development environments.
- Run
npm run deploy:liferay
.
To add the widget to a Liferay page you should perform the following steps:
- Access the desired page and log in with an account with the necessary permissions.
- Click the edit button.
- Go to the Widgets section in the right sidebar.
- Go to the Tools category and drag the 'Registration Form' widget to the desired location.
- Click on the publish button.
Location: /register-headless
If you choose to use "persistent" storage, you need to deploy the API.
- Access the
register-headless
directory. - Set the variable
liferay.workspace.home.dir
(directory where Liferay is installed) in the gradle.properties file. - Execute
./gradlew deploy
in the root of the project.
To allow requests to the API to be made from the portlet, a series of additional steps must be carried out.
-
Go to Control Panel > Security > Service Access Policies.
-
Click on the add button.
-
Fill in the following fields:
-
Name: headless-register-api
-
Enabled: True
-
Default: True
-
Title: Headless Register API
-
Allowed Service Signatures:
-
Service Class:
com.darroyo.headless.register.internal.resource.v1_0.FormUserResourceImpl
-
Method Name:
getRegisterFormPage
-
Service Class:
com.darroyo.headless.register.internal.resource.v1_0.FormUserResourceImpl
-
Method Name:
postRegisterForm
-
-
-
Click on save.
You also need to configure CORS to allow the Angular portlet to be able to communicate with the API.
- Access the Control Panel > System Settings > Security > Security Tools.
- Access Web Contexts Cross-Origin Resource Sharing (CORS).
- Click Add.
- Check that all the fields are set to default values.
- Click on save.