使用电子邮件或电话号码在Django中使用oAuth2登录

时间:2020-03-08 11:39:28

标签: django authentication oauth-2.0

我正在尝试使用Django中的oauth2实现登录。当前,我正在使用TokenView来登录用户。但这使用了用户名。 我试图通过编写如下代码来覆盖默认的TokenView:

#canvas {
  border: 1px solid red;
  z-index = -1;
}
#container {
  position : relative;
  z-index = 0;
}
#container canvas , #buttoncnt {
  position : absolute;
  border: 1px solid red;
  z-index = 1;
}

这是我的用户模型:

function showCoords(event) {
  var x = event.clientX - 10;
  var y = event.clientY - 10;
  var coords = "X coordinates: " + x + ", Y coordinates: " + y;
  document.getElementById('showCoords').innerHTML = coords;
  var button = document.getElementById("showCoords");
  button.style.top = y;
  button.style.left = x;
  button.style.width = 10;
  button.style.height = 10;
}

但是我遇到这样的错误

class TokenView(OAuthLibMixin, View):
    server_class = oauth2_settings.OAUTH2_SERVER_CLASS
    validator_class = oauth2_settings.OAUTH2_VALIDATOR_CLASS
    oauthlib_backend_class = oauth2_settings.OAUTH2_BACKEND_CLASS

    @method_decorator(sensitive_post_parameters("password"))
    def create_token_response(self, request):
        email = request.POST.get('email', None)
        contact = request.POST.get('contact', None)

        if email or contact:
            username = get_user_model().objects.filter(Q(email__iexact=email)).first()
                       | get_user_model().objects.filter(Q(contact__iexact=contact)).first()

            request.POST['email'] = username
        return super(TokenView, self).create_token_response(request)

我得到我无法更改POST请求的值。 那我该如何实现呢?

0 个答案:

没有答案