from userprofile.models import Users from rest_framework.exceptions import APIException class Authtication(object): def authenticate(self, request): token = request.META.get('HTTP_TOKEN') appid = request.META.get('HTTP_APPID') if token: if Users.objects.filter(openid__exact=str(token)).exists(): from staff.models import ListModel as staff staff_detail = staff.objects.filter(openid__exact=str(token), appid__exact=str(appid)).first() if staff_detail: user = Users.objects.filter(name__exact=staff_detail.staff_name).first() return (True, user) else: user = Users.objects.filter(openid__exact=str(token)).first() return (True, user) else: raise APIException({"detail": "用户不存在"}) else: raise APIException({"detail": "Please Add Token To Your Request Headers"}) def authenticate_header(self, request): pass