Django AllAuth のパスワードリセット用のURL を手動で作る

投稿者: ytyng 1年, 6ヶ月 前

Django all_auth でパスワードリセット URL を作るコードです。

生のパスワードを扱うのと同レベルのリスクがあるので運用には最新の注意を払うこと。

from django.contrib.auth import get_user_model
from django.urls import reverse
from allauth.account.forms import default_token_generator
from allauth.account.utils import user_pk_to_url_str


user = get_user_model().objects.get(id=user_id)

temp_key = default_token_generator.make_token(user)

path = reverse(
    "account_reset_password_from_key",
    kwargs=dict(uidb36=user_pk_to_url_str(user), key=temp_key),
)

print('https://www.example.com' + path)
現在の評価: 1

コメント

アーカイブ

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011