美文网首页
django重定义authenticate方法

django重定义authenticate方法

作者: ___大鱼___ | 来源:发表于2018-12-02 20:43 被阅读6次


class EmailCheckModelBackend(ModelBackend):
    """
    重新定义authenticate方法
    """
    def authenticate(self, username=None, password=None):
        try:
            user = models.User.objects.get(Q(email=username)| Q(username=username))
            if user.check_password(password):
                return user

        except models.User.DoesNotExist:
            return None

相关文章

网友评论

      本文标题:django重定义authenticate方法

      本文链接:https://www.haomeiwen.com/subject/vzsscqtx.html