auth.py 803 B

1234567891011121314151617181920
  1. from userprofile.models import Users
  2. from rest_framework.exceptions import APIException
  3. class Authtication(object):
  4. def authenticate(self, request):
  5. if request.path in ['/api/docs/', '/api/debug/', '/api/']:
  6. return (False, None)
  7. else:
  8. token = request.META.get('HTTP_TOKEN')
  9. if token:
  10. if Users.objects.filter(openid__exact=str(token)).exists():
  11. user = Users.objects.filter(openid__exact=str(token)).first()
  12. return (True, user)
  13. else:
  14. raise APIException({"detail": "User Does Not Exists"})
  15. else:
  16. raise APIException({"detail": "Please Add Token To Your Request Headers"})
  17. def authenticate_header(self, request):
  18. pass