【问题标题】:cannot set new password using django-graphql-auth无法使用 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()

【问题讨论】:

    标签: graphql graphene-python graphene-django


    【解决方案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()),
        ...
    ]
    

    【讨论】:

      猜你喜欢
      • 2013-09-21
      • 2019-05-25
      • 2020-05-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多