utils.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:django-rest-framework-passwordless 作者: aaronn 项目源码 文件源码
def authenticate_by_token(callback_token):
    try:
        token = CallbackToken.objects.get(key=callback_token, is_active=True)

        # Returning a user designates a successful authentication.
        token.user = User.objects.get(pk=token.user.pk)
        token.is_active = False  # Mark this token as used.
        token.save()

        return token.user

    except CallbackToken.DoesNotExist:
        log.debug("drfpasswordless: Challenged with a callback token that doesn't exist.")
    except User.DoesNotExist:
        log.debug("drfpasswordless: Authenticated user somehow doesn't exist.")
    except PermissionDenied:
        log.debug("drfpasswordless: Permission denied while authenticating.")

    return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号