无法使用 django-graphql-auth 设置新密码
Posted
技术标签:
【中文标题】无法使用 django-graphql-auth 设置新密码【英文标题】:cannot set new password using django-graphql-auth 【发布时间】:2021-09-21 00:16:33 【问题描述】:Graphene 发送电子邮件,但 url 不存在。我应该如何为此设置令牌网址?
我找不到有关如何配置 urls.py 以便它通过电子邮件发送的链接有效的文档。
http://127.0.0.1:8090/activate/eyJ1c2VybmFtZSI6ImtkZWVuZXl6eiIsImFjdGlvbiI6ImFjdGl2YXRpb24ifQ:1m2a0v:04V3Ho0msVn7nHuFW469DC9GBYuUz2czfsFai09EOyM
settings.py
GRAPHQL_JWT =
'JWT_VERIFY_EXPIRATION': True,
'JWT_LONG_RUNNING_REFRESH_TOKEN': True,
'ALLOW_LOGIN_NOT_VERIFIED': True,
'JWT_ALLOW_ARGUMENT': True,
"JWT_ALLOW_ANY_CLASSES": [
"graphql_auth.mutations.Register",
"graphql_auth.mutations.VerifyAccount",
"graphql_auth.mutations.ResendActivationEmail",
"graphql_auth.mutations.SendPasswordResetEmail",
"graphql_auth.mutations.PasswordReset",
"graphql_auth.mutations.ObtainJSONWebToken",
"graphql_auth.mutations.VerifyToken",
"graphql_auth.mutations.RefreshToken",
"graphql_auth.mutations.RevokeToken",
"graphql_auth.mutations.VerifySecondaryEmail",
],
schema.py
class AuthMutation(graphene.ObjectType):
register = mutations.Register.Field()
verify_account = mutations.VerifyAccount.Field()
token_auth = mutations.ObtainJSONWebToken.Field()
update_account = mutations.UpdateAccount.Field()
resend_activation_email = mutations.ResendActivationEmail.Field()
send_password_reset_email = mutations.SendPasswordResetEmail.Field()
password_reset = mutations.PasswordReset.Field()
password_change = mutations.PasswordChange.Field()
【问题讨论】:
【参考方案1】:你需要创建一个视图来处理这个 url。
from django.http import HttpResponseRedirect
from django.views import View
from graphql_auth.models import UserStatus
class ActivateView(View):
def get(self, request, **kwargs):
try:
token = kwargs.get("token")
UserStatus.verify(token)
except Exception:
return HttpResponseRedirect(f"/some/error/url")
return HttpResponseRedirect(f"/activate/thankyou")
在你的urls.py
urlpatterns = [
....
path("activate/<str:token>", ActivateView.as_view()),
...
]
【讨论】:
以上是关于无法使用 django-graphql-auth 设置新密码的主要内容,如果未能解决你的问题,请参考以下文章
pip - 如何使用预先构建的***而不是再次拉动 git 以避免冲突?
无法使用 StorageClass 配置卷 - 无法获取存储帐户的存储密钥