Q&A
実現したいこと
バックエンドはDRF
フロントエンドはReact.jsにて
アプリを作っており、ユーザーがパスワードを忘れた場合、
EmailをSubmitするとユーザーのメールにパスワードリセットシンクが届くように実装をしています。
前提
現在、下記のライブラリを使用し
https://github.com/anexia-it/django-rest-passwordreset/blob/master/README.md
実装しているのですが
リセットを行うと
Please reset your password from the link below. http://localhost:8000/api/password_reset/confirm/?token=604c13ce7bff445
のようなメールが届きます。これは
ライブラリのデフォルトでこのようなURLが送られてくるのですが
このURLを例えば
React.jsのURL
1http://localhost:3002/password_reset/confirm/?token=604c13ce7bff445
のように変更したいのですがそんなことは可能なのでしょうか?
URLを司っているのは下記コードの
reset_password_urlの部分かと思いますが
こちらをカスタマイズする方法はドキュメントには見当たらないように思います。。
発生している問題・エラーメッセージ
エラーメッセージ
該当のソースコード
models.py
1@receiver(reset_password_token_created) 2def password_reset_token_created(sender, instance, reset_password_token, *args, **kwargs): 3 """ 4 Handles password reset tokens 5 When a token is created, an e-mail needs to be sent to the user 6 :param sender: View Class that sent the signal 7 :param instance: View Instance that sent the signal 8 :param reset_password_token: Token Model Object 9 :param args: 10 :param kwargs: 11 :return: 12 """ 13 # send an e-mail to the user 14 context = { 15 'current_user': reset_password_token.user, 16 'username': reset_password_token.user.username, 17 'email': reset_password_token.user.email, 18 'reset_password_url': "{}?token={}".format( 19 instance.request.build_absolute_uri(reverse('password_reset:reset-password-confirm')), 20 reset_password_token.key) 21 } 22 23 # render email text 24 email_html_message = render_to_string('email/user_reset_password.html', context) 25 email_plaintext_message = render_to_string('email/user_reset_password.txt', context) 26 27 msg = EmailMultiAlternatives( 28 # title: 29 "Password Reset for {title}".format(title="Some website title"), 30 # message: 31 email_plaintext_message, 32 # from: 33 "noreply@somehost.local", 34 # to: 35 [reset_password_token.user.email] 36 ) 37 msg.attach_alternative(email_html_message, "text/html") 38 msg.send()
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。