Adding user self registration
Posted by Giampiero Granatella
on 18th February, 2010
This is the fourth tutorial of the user management series. In this tutorial we are going to explore user self-registration: a functionality that is often required by public web apps but is quite difficult to implement or even integrate with existing Java libraries.
A prerequisite is to have user management enabled and the email parameters configured as explained in the first tutorial. Check the presence of the following lines (customized as needed) in your portofino-custom.properties:
model.users.enabled=true mail.smtp.host=smtp.gmail.com mail.smtp.port=465 email@example.com mail.smtp.password=your_password mail.smtp.ssl.enabled=true
To enable self registration you have to add following parameter:
Setting only this parameter allows users to self register and immediately log on to the system.
If you also want that self-registrations be moderated by user administrators, set:
With this flag set, self-registered users have to wait for the activation from an administrator.
With self registration enabled, you'll find a new link called "Register" in the top right corner. Click on it.
A self-registration page is presented.
Enter the fields as required: login, password and email. Click on create to complete your registration.
Portofino will check:
- that the login and the email are unique in the application
- that passwords match and are compliant with what you specified in the portofino-custom.properties.
Click on "Create". You'll be presented with a confirmation page.
The last step is to verify your registration. A confirmation email with the following link is automatically sent to you account:
"Please go to http://www.example.com/VerifyEmail.action?token=... to complete your registration"
Click on the link (or copy it in your browser) to complete the registration.
There are situations where you need to customize the User class. For instance you may want to add new attributes for "name" and "surname".
Self registration can handle this situation and prompt the user for the extra attributes. The only requirement is that those attributes are flagged as required in the "User" class.
Previous tutorials in the user management series: