Skip to main content

Set Up New User Registration

Deepser allows you to implement a self-service registration procedure so new users can register independently. This guide covers the steps required to create and configure a registration form, including custom validation, token-based email verification, and enabling registration on the login page.

Create Registration Steps

Deepser allows you to create a registration form by combining one or more Step components.

To create a Step, go to System > Permissions > User Registration > Step.

On the screen that opens, click the Add Step button.

You will be redirected to the creation screen for a new step.

Below is a brief description of each field:

FieldDescription
NameStep name
PositionPosition in the step grid
LabelText that will appear to users when the step loads
Is Default stepIndicates whether this is the step from which registration begins
Is Final stepIndicates whether this is the step that ends registration
Next stepNext step in the registration; null if the current step is the final step
Check TokenChecks whether the verification token is present in the request
Send TokenSends the verification token
Token DurationToken duration in hours and minutes
MailboxThe mailbox used to send messages to the user during registration
Email EventEmail event associated with registration (if any)
StepData FormtemplateForm template associated with the current step
Validate ExpressionCustom code that validates the input data
Final MessageFinal message displayed to the user if the current step is the final step
Create UserIndicates whether a user will be created in this step
Create Active UserIndicates whether an active user will be created in this step
Send Reset PasswordIndicates whether a password reset email will be sent to the user
Field ConfigMapping of user principal fields to form template fields
User Create ExpressionCustom code used to create a user
StatusIndicates whether this step is active or not

Registration Form Creation Example

In the following sections, we cover the creation of a registration form that allows a user to register and access support, but only if they belong to a company registered in Deepser. This prevents external users from creating Service Operations without authorization.

Creating a Custom Field to Receive User Input

Before proceeding with the actual form creation, you must create a custom field to receive user input.

In the following example, we create a user only if the VAT number entered corresponds to one of the companies present in Deepser. For this example, we assume there is a custom field named "cust_vat_number" that contains the company's VAT number.

Custom Fields are covered in the Custom Fields documentation.

To create a custom field, go to System > Custom Fields.

Click on the model DeepRegistration - stepData.

On the next screen, click the Add Field button.

On the screen that appears, fill in the fields as follows:

note

Set the Column Type and Element Type fields to text.

Click the Save button. Once this is done, you can proceed to implement the registration form.

Form Creation

To create the registration form, go to the step creation menu to create a new step.

The Step section is located under System > Permissions > User Registration > Step.

Give your registration form a name by entering the desired name in the Name field.

Set the Position field to zero.

Set the label displayed on the registration screen by entering the desired text in the Label field. The Label field can contain plain text or HTML with CSS styles.

Set Is Default Step to Yes to define this as the step from which registration begins.

Since this example has only one registration step, also set Is Final Step to Yes.

Since this example has only one registration step, set Next Step to none. In a multi-step registration, you can set the next step through this field.

Set the email mailbox for sending password change emails through the Mailbox field.

Select the form template to display during registration using the StepData Formtemplate field.

In the Validate Expression field, you can define custom code to verify the validity of input data.

Enter the following code in this field:


/**Defining Variables**/

//Assigning StepDatas to a variable.
$stepData = $this->getStepdata();

//Assigning the value of the cust_vat_number field to a variable.
$vatNumber = $stepData->getData('cust_vat_number');

//Assigning the value of the email field to a variable.
$email = $stepData->getData('email');

//If the email is not in a valid format, return an error to the user.
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->addError("Email is not in a valid format");
}
//Retrieving from the user collection all users that have the username equivalent to the given email.
$usersCollection = Deep::getResourceModel("deep_admin/user_collection")->addFieldToFilter("username",["eq" => $email]);
//Retrieving from the user collection all StepData that have the username equivalent to the given email.
$stepDataCollection = Deep::getResourceModel("deep_userregistration/stepdata_collection")->addFieldToFilter("email",["eq" => $email]);

//If one or more users or StepDatas were found, return an error to the user.
if($usersCollection->count() || $stepDataCollection->count()){
$this->addError("Email Already Registered");
}


/**If the company is present in Deepser we allow the registration, otherwise throw an error**/

//Loading a company given the cust_piva field; if there is no company with this field, this method retrieves a new object.
$company = Deep::getModel("deep_company/company")->load($vatNumber,'cust_piva');

//If the returned object doesn't have the id or is null, return an error to the user.
if(!($company && $company->getId())){
$this->addError("We are sorry, but only employee of our customer can register an account");
}


In the Final Message field, define the message shown to the user after successful registration.

Enter the following code:




## Success



Congratulations, your account has been created!.



Username:



<?php echo $this->getStepdata()->getData('email'); ?>



###### We have sent you an email with the link to reset your password.




Set Create User to Yes to create a user in this step.

Set Create Active User to Yes to define whether the user will be active.

Set the Send Reset Password field to send the user an email at the end of the procedure that allows them to reset their password.

In the Field Config field, define the mapping of user template fields to form fields. To add a new field to map with the form data, click the + button.

The user fields are defined as follows:

In the User Create Expression field, you can define custom code to set user attributes or perform actions when creating a new user. Enter the following code:


//getting the data from the form
$stepData = $this->getStepdata();
// assigning the end user role to the created user by passing the role id
$this->getUser()->setData("role",73);


Finally, set the Status field to Enabled (if not already set).

Click the Save or Apply button.

Editing the Form Template

To modify the form template displayed during registration:

  1. Click the Preview button.

  2. Click the pencil button, then go to the StepData tab:

  1. Add fields by dragging them from the right column into the grid:

  1. Click the Save button to confirm.

Token Usage

During registration, you may need to validate the user's email. You can send a token to verify the email address.

Building on the previous example, create another step that omits the account creation part and instead configures token sending.

Email Template Creation

To send the verification token to the user, you must create an email event with an associated template form that Deepser uses to send the email.

  1. Go to System > Tools > Email > Template.

  2. Click the Add MailTemplate button.

  3. Define a name for the template by entering the desired name in the Name field.

  4. Define a code for the template by filling in the Code field.

  5. In the Subject section, insert the PHP code that composes the email subject. You can use the following code as a reference:


<?php echo Deep::helper('deep_email')->__('DEEPSER - Confirm your Registration'); ?>


  1. In the Body section, insert the PHP/HTML code that generates the email body. You can use the following code as a reference:
<?php
$username = $this->getModel()->getEmail();
$firstname = trim($this->getModel()->getFirstname());
$lastname = trim($this->getModel()->getLastname());
$tmpFullname = $firstname . $lastname;
$fullname = $fullanme != "" ? $tmpFullname : "user";
$url = $this->getModel()->getTokenStepUrl();
?>
<?php $this->includeTemplate("header") ?>
<!-- Start of Main Content -->
<tr style="">
<td bgcolor="#FFFFFF" align="center" style="">
<table width="100%" align="center" cellpadding="0" cellspacing="0" border="0" class="devicewidth" style="">
<tbody style="">
<!-- Start Spacer -->
<tr>
<td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
<td class="h26" height="36" style="font-size:1px; line-height:1px;">&nbsp;</td>
<td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
</tr>
<!-- End Spacer -->
<tr style="">
<td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
<td class="mktEditable content mktEditable content" id="edit_text_1" valign="middle" style="font-family:Calibri, Helvetica, sans-serif; font-size:16px; color:#505050; text-align:left; line-height:25.6px; font-weight:normal; text-transform:none;">
<p>
<br>
<?php echo Deep::helper('deep_email')->__('Dear %s',$fullname);?>,<br>
<?php echo Deep::helper('deep_email')->__('Please confirm your registration by clicking the link below'); ;?><br>
</p>
</td>
</tr>
<!-- Start Spacer -->
<tr>
<td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
<td height="30" style="font-size:1px; line-height:1px;">&nbsp;</td>
<td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
</tr>
<!-- End Spacer -->
</tbody>
</table>
</td>
</tr>
<!-- End of Main Content -->
<!-- start of Button -->
<tr style="">
<td bgcolor="#FFFFFF" align="center" class="mktEditable" id="edit_cta_button" style="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="w22" width="41" style="font-size: 1px; line-height: 1px;">&nbsp;</td>
<td align="left">
<table class="button" cellpadding="0" cellspacing="0" border="0" align="left" bgcolor="#0080ff" style="-webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px;">
<tbody>
<tr>
<td width="518" align="center" valign="middle" height="65">
<span style="color: #ffffff; text-decoration: none;">
<a class="mobButton mktNoTok" href="<?php echo $url ?>" style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; color: #ffffff; display: block; height: 65px; mso-line-height-rule: exactly; line-height: 65px; font-weight: normal; text-decoration: none; text-align: center!important;" target="_blank" title="Link al ticket">
<?php echo Deep::helper('deep_email')->__('Confirm the registration')?>
</a>
</span>
</td>
</tr>
</tbody>
</table> </td>
<td class="w22" width="41" style="font-size: 1px; line-height: 1px;">&nbsp;</td>
</tr>
</tbody>
</table>
</td>
</tr>
<!-- end of Button -->
<?php $this->includeTemplate("footer") ?>
  1. Click Save or Apply.

Email Event Creation

  1. Go to System > Tools > Email > Event.

  2. Click the Add Event button.

The following page will appear:

  1. Give the event a name by filling in the Name field.

  2. Set Send Attachments to No.

  3. In the Email Template field, select the template created in the previous step.

  4. In the Event Trigger section, select DeepUserregistration-StepData in the Model field.

  5. In the Event Expression entry, insert the following code:


return true;



  1. In the To section, insert the following code:

/**Configuring the language with locale **/
$this->changeLanguage($this->getModel()->getCustLocale());
/**Getting the email from the current model**/
$this->addTo($this->getModel()->getEmail());


  1. Click Save or Apply. The event will be saved.

Add a New Form Template

  1. Click Preview.
  2. Click the button with the arrow icon.
  3. Click New Formtemplate.
  4. Enter the name of the new form template in the Enter Template Name field.
  5. Click Save. The new form template will be created.

Set a Field as Required

  1. Click Preview.
  2. Click the button with the pencil icon.
  3. Go to the Fieldset: Step data.
  4. Locate the field you want to make mandatory and click its gear icon.
  5. Set the Required field to Yes.
  6. Click OK on the field configuration screen.
  7. Click Save in the form configuration window. The field is now mandatory.

Edit Form Template Priority

Deepser evaluates form templates from highest priority to lowest. The priority determines which form template the user sees.

  1. Click the arrow key.
  2. Click on the template you want to edit.
  3. Click the button with the pencil icon.
  4. Click the Edit Rules button and then set a value in the Priority field.
  5. Click Save.

Step Creation

For this example, use the step created in the previous sections as a basis. Create two form templates: the first named "First" with the Email, Firstname, and Lastname fields, and the second named "Second" with only the Vat Number field (cust_vat_number) created in the previous steps.

Initial Step

  1. Go to the Step section and click the Add Step button.
  2. Configure the Name field with the desired step name.
  3. Set the Position field to 0.
  4. Configure the Label field with the text the user will see when arriving at this form.
  5. Set Is Default Step to Yes.
  6. Set Is Final Step to Yes.
  7. Set the Next Step field to the step created in the previous section (User Support Registration).
  8. Set Check Token to No.
  9. Set Send Token to Yes.
  10. Set the Token Duration field to an hour, or at least a duration you believe is sufficient for registration.
  11. Configure the Mailbox field with the outgoing mailbox you will use for registration.
  12. Configure the Email Event field with the mail event created above.
  13. Set the StepData Formtemplate field to the form template you want to use in this first step. In the form template, set all required fields as mandatory so the user must fill them in to continue.
  14. Set Create User and Create Active User to No.
  15. In the Validate Expression field, insert the following code to verify the form template:

/**Variables Initialization**/

//Assigning the stepDatas to a variable.
$stepData = $this->getStepdata();

//Assigning the value of the email field to a variable.
$email = $stepData->getData('email');

/**Verifications**/

//If the email is not in a valid format, return an error to the user.
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->addError("Email is not in a valid format");
}
//Retrieving from the user collection all users that have the username equivalent to the given email.
$usersCollection = Deep::getResourceModel("deep_admin/user_collection")->addFieldToFilter("username",["eq" => $email]);
//Retrieving from the user collection all StepData that have the username equivalent to the given email.
$stepDataCollection = Deep::getResourceModel("deep_userregistration/stepdata_collection")->addFieldToFilter("email",["eq" => $email]);

//If one or more users or StepDatas were found, return an error to the user.
if($usersCollection->count() || $stepDataCollection->count()){
$this->addError("Email Already Registered");
}


  1. Leave the Field Config field as-is, since user creation will be managed in the last step.
  2. Leave the User Create Expression field blank because you will not create users in this step.
  3. Click Apply or Save. The step will be saved.

Final Registration Step

  1. Set the Check Token field to Yes.
  2. Configure the form template associated with this step using the StepData Formtemplate field.
  3. Modify the Validate Expression field to perform only the Vat Number validation:

**Defining Variables**/

//Assigning StepDatas to a variable.
$stepData = $this->getStepdata();

//Assigning the value of the cust_vat_number field to a variable.
$vatNumber = $stepData->getData('cust_vat_number');

/**If the company is present in Deepser we allow the registration, otherwise throw an error**/

//Loading a company given the cust_piva field; if there is no company with this field, this method retrieves a new object.
$company = Deep::getModel("deep_company/company")->load($vatNumber,'cust_piva');

//If the returned object doesn't have the id or is null, return an error to the user.
if(!($company && $company->getId())){
$this->addError("We are sorry, but only employee of our customer can register an account");
}


note

This form template must have a higher priority than all others.

  1. Click Save or Apply.

Enabling Registration

To enable registration through the form:

  1. Go to System > Configurations > Admin > Security.
  2. Set the Enable User Registration field to Yes.
  3. Click the Save Config button to save the changes.

The registration link will now appear on the main login page: