Email Registration
API Views
There are two views used in the email registration / change workflow:
register-email
- rest_registration.api.views.register_email(request, *args, **kwargs)
verify-email
- rest_registration.api.views.verify_email(request, *args, **kwargs)
Assuming that the Django REST Registration views are served at
https://backend-host/api/v1/accounts/
then the register_email
, verify_email
views are served as:
https://backend-host/api/v1/accounts/register-email/
https://backend-host/api/v1/accounts/verify-email/
accordingly.
Verification workflow
Let’s describe it by example. We’re assuming that:
the Django REST Registration views are served at
https://backend-host/api/v1/accounts/
you have ‘REGISTER_EMAIL_VERIFICATION_ENABLED’ set to
True
(this by default)you configured ‘REGISTER_EMAIL_VERIFICATION_URL’ to be
https://frontend-host/verify-email/
Then the verification workflow looks as follows:
The user who wants to register new email (which is currently equivalent to changing the e-mail) sends AJAX POST request to
https://backend-host/api/v1/accounts/register-email/
endpoint. Usually this happens via front-end aplication, which could be hosted onhttps://frontend-host/
.Assuming the registration was correct, The
register_email
endpoint will generate an e-mail which will contain an URL which the user should click to register new e-mail. the URL would be in a form:https://frontend-host/verify-email/?user_id=<user id>&email=<email>×tamp=<timestamp>&signature=<signature>
(You can change the way the URL is generated by overriding ‘VERIFICATION_URL_BUILDER’)
The frontend endpoint (which is not provided by Django REST Registration)
https://frontend-host/verify-email/
would receive following GET parameters:user_id
email
timestamp
signature
and then it should perform AJAX request to
https://backend-host/api/v1/accounts/verify-email/
via HTTP POST with following JSON payload:{ "user_id": "<user id>", "email": "<email>", "timestamp": "<timestamp>", "signature": "<signature>" }
and then show a message to the user depending on the response from backend server.
Default serializers
DefaultRegisterEmailSerializer
List of settings
These settings can be used to configure email registration workflow.
You should add them as keys (with values)
to your settings.REST_REGISTRATION
dict.
‘REGISTER_EMAIL_SERIALIZER_CLASS’
Default:
'rest_registration.api.serializers.DefaultRegisterEmailSerializer'
The serializer used by register-email endpoint.
It is used to validate the input data and obtain new e-mail.
You can use your custom serializer
to customise validation logic. The important part is that it should contain
email
field.
‘REGISTER_EMAIL_VERIFICATION_ENABLED’
Default:
True
No description available, please add it here!
‘REGISTER_EMAIL_VERIFICATION_EMAIL_SENDER’
Default:
'rest_registration.verification_notifications.send_register_email_verification_email_notification'
By default the email sender function will work with the build-in email sending mechanism.
You can handle email sending all by yourself by overriding this setting.
‘REGISTER_EMAIL_VERIFICATION_PERIOD’
Default:
datetime.timedelta(days=7)
No description available, please add it here!
‘REGISTER_EMAIL_VERIFICATION_URL’
Default:
None
No description available, please add it here!
‘REGISTER_EMAIL_VERIFICATION_EMAIL_TEMPLATES’
Default:
{'body': 'rest_registration/register_email/body.txt',
'subject': 'rest_registration/register_email/subject.txt'}
No description available, please add it here!