1 Star 0 Fork 0

小浩/crm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
xx.py 3.72 KB
一键复制 编辑 原始数据 按行查看 历史
小浩 提交于 2020-05-10 23:07 . crm上线了
import re
from rbac import models
from django.conf import settings
from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import redirect,render,HttpResponse
from django.urls import reverse
class Auth(MiddlewareMixin):
def process_request(self,request):
# 登录认证白名单
white_list = [reverse('login'),reverse('register'),'/admin/.*']
# 登录认证
# 权限认证白名单
white_permission_list = ['/rbac/multi/permissions/','/rbac/distribute/permissions/']
bread_crumb = [
{'title':'首页','url':reverse('home')},
]
request.pid = None
current_path = request.path
for i in white_list:
if re.match(i,current_path):
break
else:
is_login = request.session.get('name')
if not is_login:
return redirect('/login/')
else:
for purl in white_permission_list:
# print(purl)
if re.match(purl,current_path):
return
else:
# 权限认证
permission_dict = request.session.get(settings.PERMISSION_KEY)
# re.match('/customer/edit/(?P<cid>\d+)/',customer/edit/2/)
#/customer/edit/(?P<cid>\d+)/ -- customer/edit/2/
for permission in permission_dict.values(): #[{'url':'/custer/'}]
# if current_path == permission['permissions__url']:
reg = r'^%s$'%permission['permissions__url']
if re.match(reg,current_path): #/customer/add/
pid = permission['permissions__parent_id'] #None
if pid:
# obj = models.Permission.objects.filter(id=pid).first()
parent_dict = permission_dict[str(pid)]
# 添加二级菜单
bread_crumb.append({
'title': parent_dict['permissions__title'],
'url': parent_dict['permissions__url'],
})
# 添加子权限
bread_crumb.append({
'title': permission['permissions__title'],
'url': permission['permissions__url'],
})
# bread_crumb = [
# {'title': '首页', 'url': 'javascript:void(0);'},
# {'title': '客户展示', 'url': 'javascript:void(0);'},
# {'title': '客户添加', 'url': 'javascript:void(0);'},
#
# ]
request.pid = pid #wsgihttprequest对象
else:
if permission['permissions__url'] != reverse('home'):
bread_crumb.append({
'title':permission['permissions__title'],
'url':permission['permissions__url'],
})
request.pid = permission['permissions__id']
request.session['bread_crumb'] = bread_crumb
return
else:
return HttpResponse('您不配!!!')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xiaohaoge/crm.git
git@gitee.com:xiaohaoge/crm.git
xiaohaoge
crm
crm
dev

搜索帮助