简体   繁体   English

使用rest-auth从Django all-auth检索给定确认密钥(电子邮件验证)的用户电子邮件地址

[英]Retrieve user e-mailaddress given confirmation key (email verification) from Django all-auth with rest-auth

The application is using Django backend and ReactJS frontend.该应用程序使用 Django 后端和 ReactJS 前端。 I created user accounts using the standard rest-auth package in Django, calling the endpoints from the ReactJS frontend forms.我使用 Django 中的标准 rest-auth 包创建了用户帐户,从 ReactJS 前端表单调用端点。

Sign up and login works fine, but when it comes to e-mail confirmation, I haven't been able to find where confirmation keys are stored and how this is accessed.注册和登录工作正常,但是当涉及到电子邮件确认时,我无法找到确认密钥的存储位置以及如何访问它。 I've overridden get_email_confirmation_url from DefaultAccountAdapter to change the URL confirmation link that is being sent out from [backend]/rest-auth/registration/account-confirm-email/[KEY] to [frontend]/registration/confirm-email/[KEY].我已经从DefaultAccountAdapter覆盖了get_email_confirmation_url以更改从 [backend]/rest-auth/registration/account-confirm-email/[KEY] 发送到 [frontend]/registration/confirm-email/[钥匙]。

I'm able to read out [KEY] at the frontend.我可以在前端读出 [KEY]。 However, how do I retrieve the e-mailaddress and name of the user that's trying to confirm their address?但是,如何检索尝试确认其地址的用户的电子邮件地址和姓名? In the standard Django template this is possible (email_confirm.html):在标准的 Django 模板中,这是可能的(email_confirm.html):

{% extends "account/base.html" %}

{% load i18n %}
{% load account %}

{% block head_title %}{% trans "Confirm E-mail Address" %}{% endblock %}


{% block content %}
<h1>{% trans "Confirm E-mail Address" %}</h1>

{% if confirmation %}

{% user_display confirmation.email_address.user as user_display %}

<p>{% blocktrans with confirmation.email_address.email as email %}Please confirm that <a href="mailto:{{ email }}">{{ email }}</a> is an e-mail address for user {{ user_display }}.{% endblocktrans %}</p>

<form method="post" action="{% url 'account_confirm_email' confirmation.key %}">
{% csrf_token %}
    <button type="submit">{% trans 'Confirm' %}</button>
</form>

{% else %}

{% url 'account_email' as email_url %}

<p>{% blocktrans %}This e-mail confirmation link expired or is invalid. Please <a href="{{ email_url }}">issue a new e-mail confirmation request</a>.{% endblocktrans %}</p>

{% endif %}

{% endblock %}

Where does the information from confirmation.email_address.user and confirmation.email_address.email come from?来自confirmation.email_address.user 和confirmation.email_address.email 的信息从何而来? The account_emailconfirmation table is empty and account_emailaddress only contains a boolean saying whether the emailaccount is verified or not, but no confirmation key. account_emailconfirmation表是空的, account_emailaddress只包含一个布尔值,说明emailaccount 是否经过验证,但没有确认键。

Keys are no longer stored https://stackoverflow.com/a/41364419/3241374密钥不再存储https://stackoverflow.com/a/41364419/3241374

I use url confirmation:我使用网址确认:

  1. I grab the key on the front end我抓住前端的钥匙
  2. Post it to the backend confirmation url发布到后台确认url
  3. Check the response / login user检查响应/登录用户

Good starting point is this answer: https://stackoverflow.com/a/59327408/3241374好的起点是这个答案: https : //stackoverflow.com/a/59327408/3241374

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM