|
|
|
@ -31,18 +31,18 @@ class JWTMiddleware:
|
|
|
|
|
# 将解码后的 Token 数据存储在 request 中,以便视图可以访问
|
|
|
|
|
if payload.get("type") == "student":
|
|
|
|
|
if not Student.objects.filter(username=payload.get("username")).exists():
|
|
|
|
|
return JsonResponse(ResponseUtil.error("错误信息!"), status=401)
|
|
|
|
|
return JsonResponse(ResponseUtil.error("用户不存在!"), status=401)
|
|
|
|
|
if payload.get("type") == "teacher":
|
|
|
|
|
if not Teacher.objects.filter(username=payload.get("username")).exists():
|
|
|
|
|
return JsonResponse(ResponseUtil.error("错误信息!"), status=401)
|
|
|
|
|
return JsonResponse(ResponseUtil.error("用户不存在!"), status=401)
|
|
|
|
|
if payload.get("type") == "admin":
|
|
|
|
|
if not Admin.objects.filter(username=payload.get("username")).exists():
|
|
|
|
|
return JsonResponse(ResponseUtil.error("错误信息!"), status=401)
|
|
|
|
|
return JsonResponse(ResponseUtil.error("用户不存在!"), status=401)
|
|
|
|
|
request.jwt_payload = payload
|
|
|
|
|
except jwt.ExpiredSignatureError:
|
|
|
|
|
return JsonResponse(ResponseUtil.error("登录失效!"), status=401)
|
|
|
|
|
return JsonResponse(ResponseUtil.error("Token 失效,请重新登录!"), status=401)
|
|
|
|
|
except jwt.DecodeError:
|
|
|
|
|
return JsonResponse(ResponseUtil.error("登录失效!"), status=401)
|
|
|
|
|
return JsonResponse(ResponseUtil.error("Token Error!"), status=401)
|
|
|
|
|
# 继续处理请求
|
|
|
|
|
response = self.get_response(request)
|
|
|
|
|
return response
|