前提・実現したいこと
Django-allauth
と、Django-rest-auth
を利用して、ios,androidアプリ、WEBアプリ共通のログインまわりの機能を開発しています。
ユーザー登録済みのアカウントの、パスワードをリセットするためにaccounts_api/password/reset/
のエンドポイントに、メールアドレスを入力してアクセスすると、入力したアドレス宛にメールを受信します。
メールの内容は下記のようになっております。
このメールは example.com で、あなたのアカウントのパスワードリセットが要求されたため、送信されました。 次のページで新しいパスワードを選んでください: http://example.com/accounts_api/password/reset/confirm/(%3FPMzE%5B0-9A-Za-z_%5C-%5D+)/(%3FP5kt-19a402a967c1faa1d3b3%5B0-9A-Za-z%5D%7B1,13%7D-%5B0-9A-Za-z%5D%7B1,20%7D)/$ あなたのユーザー名 (念のため): my name ご利用ありがとうございました! example.com チーム
通常であれば、example.com
が自分の環境に対応される(ローカルでの開発であれば127.0.0.1:8000
、本番環境であれば登録しているドメイン
)と思うのですが、現在どちらの環境で試してもexample.com
となってしまいます
対象のファイルのパスは以下のとおりです。
allauth/templates/account/messages/password_reset_key_message.txt
ファイル内コードは以下のとおりです。
{% load i18n %}{% autoescape off %}{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Hello from {{ site_name }}! You're receiving this e-mail because you or someone else has requested a password for your user account. It can be safely ignored if you did not request a password reset. Click the link below to reset your password.{% endblocktrans %} {{ password_reset_url }} {% if username %}{% blocktrans %}In case you forgot, your username is {{ username }}.{% endblocktrans %} {% endif %}{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Thank you for using {{ site_name }}! {{ site_domain }}{% endblocktrans %} {% endautoescape %}
そのため、これ以降のパスワードリセット作業ができない状況です。
example.com
の部分を自分の環境に対応した状態で表示するには、どのような方法をとれば良いでしょうか?
該当のソースコード
settings.py
python
1INSTALLED_APPS = [ 2#..... 3 'allauth', 4 'allauth.account', 5 'allauth.socialaccount', 6 'rest_framework.authtoken', 7 'rest_auth', 8 'rest_auth.registration', 9 'rest_framework', 10#..... 11]
project/urls.py
from django.contrib import admin from django.contrib.staticfiles.urls import static from django.urls import path, include from django.views.generic import TemplateView from . import settings_common, settings_dev urlpatterns = [ path('api-auth/', include('rest_framework.urls')), path('admin/', admin.site.urls), path('accounts/', include('allauth.urls')), path('accounts_api/', include('rest_auth.urls')), path('accounts_api/registration/', include('rest_auth.registration.urls')), path('accounts_api/registration/account-confirm-email/(?P<key>[-:\w]+)/$', TemplateView.as_view(), name="account_confirm_email"), path('accounts_api/registration/account-confirm-email/', include('allauth.urls')), path('accounts_api/registration/account-confirm-email/signup/', include('allauth.urls')), #以下django-rest-auth公式ドキュメントを参考に対応 path( 'accounts_api/password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', TemplateView.as_view.as_view(), name="password_reset_confirm"), ]
コメントアウトの部分は公式ドキュメントを参考に追加しています。
試したこと
API経由ではなく、WEBサイト経由の場合は、example.com
に自分の環境が反映され、手続きを正常に行うことができます。
(*WEBサイトはメール内のメッセージをオーバーライドして利用しています。)
補足情報(FW/ツールのバージョンなど)
開発環境
python: 3.7.5
Django:2.2.2
django-allauth:0.41.0
django-rest-auth:0.9.5
djangorestframework:3.12.1
あなたの回答
tips
プレビュー