From 47a46ee26c663ed51d489b4a796a0ef8597a379e Mon Sep 17 00:00:00 2001 From: qizhicheng Date: Mon, 17 Dec 2018 20:36:10 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9:=20=E9=BB=98=E8=AE=A4=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E7=BB=84,=20=E5=9C=A8=E7=94=A8=E6=88=B7=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=97=B6=E8=87=AA=E5=8A=A8=E5=85=B3=E8=81=94;=20*=20?= =?UTF-8?q?=E6=9B=B4=E6=94=B9user=20=E7=9A=84str=E5=87=BD=E6=95=B0,=20?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=B2=A1=E6=9C=89display=E5=B0=B1=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E8=BF=94=E5=9B=9E=E7=94=A8=E6=88=B7=E5=90=8D;=20*=20?= =?UTF-8?q?=E6=9B=B4=E6=94=B9base.html=20,=20=E6=8A=8A=20user.display=20?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=20=E7=9B=B4=E6=8E=A5user,=20=E8=BF=99?= =?UTF-8?q?=E6=A0=B7=E5=8F=AF=E4=BB=A5=E7=9B=B4=E6=8E=A5=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20str(user)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/auth.py | 19 +++++++++++++++++-- common/templates/base.html | 2 +- common/templates/config.html | 11 +++++++++++ sql/models.py | 2 ++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/common/auth.py b/common/auth.py index 22d14df33e..c733987eeb 100644 --- a/common/auth.py +++ b/common/auth.py @@ -1,5 +1,6 @@ import datetime import logging +import traceback import simplejson as json from django.conf import settings @@ -12,7 +13,7 @@ from django.urls import reverse from common.config import SysConfig -from sql.models import Users +from sql.models import Users, SqlGroup, GroupRelations logger = logging.getLogger('default') login_failure_counter = {} # 登录失败锁定计数器,给loginAuthenticate用的 @@ -92,8 +93,22 @@ def authenticate_entry(request): group = Group.objects.get(name=default_auth_group) user.groups.add(group) except Exception: + logger.error(traceback.format_exc()) logger.error('无name为{}的权限组,无法默认关联,请到系统设置进行配置'.format(default_auth_group)) - + # 添加到默认资源组 + default_resource_group = SysConfig().sys_config.get('default_resource_group', '') + if default_resource_group: + try: + new_relation = GroupRelations( + object_type=0, + object_id = user.id, + object_name = str(user), + group_id = SqlGroup.objects.get(group_name=default_resource_group).group_id, + group_name = default_resource_group) + new_relation.save() + except Exception: + logger.error(traceback.format_exc()) + logger.error('无name为{}的资源组,无法默认关联,请到系统设置进行配置'.format(default_resource_group)) # 调用了django内置登录方法,防止管理后台二次登录 user = authenticate(username=username, password=password) if user: diff --git a/common/templates/base.html b/common/templates/base.html index 3bb78121ce..ec4a252f4c 100644 --- a/common/templates/base.html +++ b/common/templates/base.html @@ -39,7 +39,7 @@