Django Rest Auth custom reset password confirm url

社会主义新天地 提交于 2019-12-05 08:12:37

问题


With django-rest-framework, when you post a reset password (rest-auth/password/reset/), there is an email send to the user email. This email contains a confirmation URL. I would like to change this url because I'm on a REST app case, I want this email to point on my frontend instead of the django backend.

With the confirmation email case, I had to override get_email_confirmation_url method from the AccountAdapter. But with the reset password case, I have no clue how to do it (there is no method in the adapter about reseting password).

Any idea?


回答1:


I did it with templatetags: https://docs.djangoproject.com/fr/1.10/howto/custom-template-tags/

My templatetags file (e.g. settings_vars.py):

from django import template
from django.conf import settings

register = template.Library()

@register.simple_tag
def get_settings_var(name):
    return getattr(settings, name)

My variable in my settings.py:

FRONTEND_URL = 'http://localhost:4200/'
ACCOUNT_EMAIL_CONFIRMATION_URL = FRONTEND_URL + 'verify-email/{}'
ACCOUNT_PASSWORD_RESET_CONFIRM = FRONTEND_URL + 'password-reset/confirm/'

Usage in my password_reset_email.html:

{% load settings_vars %}

{% trans "Please go to the following page and choose a new password:" %}
{% block reset_link %}
{% get_settings_var 'ACCOUNT_PASSWORD_RESET_CONFIRM' %}?uidb64={{ uid }}&token={{ token }}
{% endblock %}

If someone know a better solution feel free to comment.

Hope it can helps someone.



来源:https://stackoverflow.com/questions/40344898/django-rest-auth-custom-reset-password-confirm-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!