You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
634 B
24 lines
634 B
from django.http import JsonResponse
|
|
|
|
|
|
class AuthMiddleware:
|
|
"""
|
|
验证权限登录中间件
|
|
"""
|
|
def __init__(self, get_response):
|
|
self.get_response = get_response
|
|
|
|
def __call__(self, request):
|
|
path = request.path
|
|
if path in [
|
|
"/login",
|
|
]:
|
|
response = self.get_response(request)
|
|
return response
|
|
|
|
session = request.session
|
|
if not session.get("username") and not session.get("type"):
|
|
return JsonResponse({"code": -1, "msg": "not login!"}, status=401)
|
|
response = self.get_response(request)
|
|
return response
|