增加/admin/和/api/admin/的权限控制middleware
This commit is contained in:
16
admin/middleware.py
Normal file
16
admin/middleware.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# coding=utf-8
|
||||
import json
|
||||
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
|
||||
|
||||
class AdminRequiredMiddleware(object):
|
||||
def process_request(self, request):
|
||||
path = request.path_info
|
||||
if path.startswith("/admin/") or path.startswith("/api/admin/"):
|
||||
if not request.user.is_authenticated():
|
||||
if request.is_ajax():
|
||||
return HttpResponse(json.dumps({"code": 1, "data": u"请先登录"}),
|
||||
content_type="application/json")
|
||||
else:
|
||||
return HttpResponseRedirect("/login/")
|
||||
Reference in New Issue
Block a user