Django Rest Auth自定义重置密码确认网址 [英] Django Rest Auth custom reset password confirm url
问题描述
使用django-rest-framework,当您发布重置密码(rest-auth/password/reset/)时,会有一封电子邮件发送到用户电子邮件.该电子邮件包含确认网址.我想更改此URL,因为我使用的是REST应用程序案例,我希望此电子邮件指向我的前端而不是django后端.
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.
在确认电子邮件的情况下,我不得不从AccountAdapter
中重写get_email_confirmation_url
方法.但是,在使用重设密码的情况下,我不知道该怎么做(适配器中没有关于重设密码的方法).
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).
有什么主意吗?
推荐答案
我使用templatetags做到了: https://docs.djangoproject.com/fr/1.10/howto/custom-template-tags/
I did it with templatetags: https://docs.djangoproject.com/fr/1.10/howto/custom-template-tags/
我的模板标签文件(例如settings_vars.py
):
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)
我的settings.py
中的变量:
FRONTEND_URL = 'http://localhost:4200/'
ACCOUNT_EMAIL_CONFIRMATION_URL = FRONTEND_URL + 'verify-email/{}'
ACCOUNT_PASSWORD_RESET_CONFIRM = FRONTEND_URL + 'password-reset/confirm/'
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.
希望它可以帮助某人.
这篇关于Django Rest Auth自定义重置密码确认网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!