def authenticate(self, pk, token): try: user = User.objects.get(pk=pk) except User.DoesNotExist: return None if token_generator.check_token(user, token): return user return None
def token(request, token, user): data = {} try: user = User.objects.get(pk=user) except User.DoesNotExist: return JSONError("User does not exist.") if token_generator.check_token(user, token): data['success'] = True else: return JSONError("Token did not match user.") return JSONResponse(data)