authentication_new_form
The authentication_new_form tag renders a form that allows the visitor to create an account as a certain Authentication Type on the site. After the visitor submits this form, she will receive an email, asking to confirm her email adress. After she confirms her email, she can login to the site using an authentication_login_form.
The authentication_new_form tag takes the plural name of an Authentication Type as input.
It is also possible to give extra arguments as a key,value pair. These arguments are transformed into html attributes on the generated form html tag.
The authentication_new_form tag requires that the authentication_field tag is called inside of it for each of the inputs:
'email'
'password'
'confirm_password'
Accepts a parameter error_msg
to use a custom message when registering does not work, for example when the wrong credentials are used. Message is returned in request.flash object.
Example:
{% authentication_new_form "dealers", error_msg: "custom error message" %}
{% authentication_field "email", class: "form-field" %}
{% authentication_field "password", class: "form-field" %}
{% authentication_field "confirm_password", class: "form-field" %}
<input type="submit" value="Register as dealer!">
{% endauthentication_new_form %}
Note: Do not forget to display the output of [request.flash], since that contains potential error messages.
JSON endpoint
Also accepts parameter output_as
, which currently only accepts "json"
as value. If this parameter is set, no html is returned, but everything needed for the payload in authentication endpoints is returned in JSON format. With this you can call the following endpoint in order to create an authentication object through a JSON request:
POST /:authentication_type_name
Accept: application/json
{
"authentication_object": {
"email": "test@test.nl",
"password": "Pa55word",
"confirm_password": "Pa55word",
... # JSON output from tag
}
}
Confirmation email
When the form created by this tag is submitted successfully, an email will be sent to the submitted email address. It is possible to provide a custom mail template for this in a theme file located at the following path:
/mails/authentication/[authentication_type_plural_name]/confirm_email.plate
In this file you have access to the following variables:
[authentication_type_single_name], e.g. dealer
: The authentication object that was created through the form. This would return it’s email, for example:dealer.email
.confirmation_url
: The url that the user can use to verify her email address. You can setup the redirect url after user confirm their email address through:redirect_to_url
params. For example:
Note: It is required that the 'confirmation_url' variable is used in the template, otherwise the user will never be able to verify her email.
submitted_form_fields
object
Inside the 'authentication_new_form
' block, you have access to the submitted_form_fields
object. This is a liquid object, representing all the fields that were submitted. This allows you to keep your form fields filled when a validation error occurred.
For example, you can use this object when rendering a form field, as follows:
By setting the value of the input field to the value in the submitted_form_fields
object, this input field will retain its value when the form is rendered again after a validation error on submitting the form.