From a998de59734a1993906488be25442f7bfefa0c37 Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Wed, 1 Apr 2015 22:54:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E8=AF=A6?= =?UTF-8?q?=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jumpserver/context_processors.py | 12 ++- jumpserver/templatetags/mytags.py | 9 +- juser/urls.py | 2 +- juser/views.py | 41 ++++++++-- templates/footer.html | 2 +- templates/jperm/sudo_list.html | 25 +----- templates/juser/chg_info.html | 132 ++++++++++++++++++++++++++++++ templates/juser/user_detail.html | 86 ++++++++++--------- templates/juser/user_list.html | 20 ++++- templates/nav_li_profile.html | 27 ++++-- 10 files changed, 264 insertions(+), 92 deletions(-) create mode 100644 templates/juser/chg_info.html diff --git a/jumpserver/context_processors.py b/jumpserver/context_processors.py index 0d8308ff4..6fdd4d07f 100644 --- a/jumpserver/context_processors.py +++ b/jumpserver/context_processors.py @@ -1,12 +1,18 @@ from juser.models import User from jasset.models import Asset - +from jumpserver.api import * def name_proc(request): user_id = request.session.get('user_id') role_id = request.session.get('role_id') - user_total_num = User.objects.all().count() - user_active_num = User.objects.filter(is_active=True).count() + if role_id == 2: + user_total_num = User.objects.all().count() + user_active_num = User.objects.filter().count() + else: + user, dept = get_session_user_dept(request) + user_total_num = dept.user_set.all().count() + user_active_num = dept.user_set.filter(is_active=True).count() + host_total_num = Asset.objects.all().count() host_active_num = Asset.objects.filter(is_active=True).count() request.session.set_expiry(3600) diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py index 1f264f4e4..a0e1f5a34 100644 --- a/jumpserver/templatetags/mytags.py +++ b/jumpserver/templatetags/mytags.py @@ -1,11 +1,9 @@ # coding: utf-8 -import re import time from django import template from juser.models import User, UserGroup, DEPT -from jasset.models import BisGroup from jumpserver.api import * register = template.Library() @@ -179,12 +177,19 @@ def to_name(user_id): except: return '非法用户' + @register.filter(name='to_role_name') def to_role_name(role_id): role_dict = {'0': '普通用户', '1': '部门管理员', '2': '超级管理员'} return role_dict.get(str(role_id), '未知') + @register.filter(name='to_avatar') def to_avatar(role_id='0'): role_dict = {'0': 'user', '1': 'admin', '2': 'root'} return role_dict.get(str(role_id), 'user') + + +@register.filter(name='get_user_asset_group') +def get_user_asset_group(user): + return user_perm_group_api(user) \ No newline at end of file diff --git a/juser/urls.py b/juser/urls.py index acb5d6064..71bc09ee7 100644 --- a/juser/urls.py +++ b/juser/urls.py @@ -27,6 +27,6 @@ urlpatterns = patterns('juser.views', (r'^user_del_ajax/$', 'user_del_ajax'), (r'^user_edit/$', view_splitter, {'su': user_edit, 'adm': user_edit_adm}), (r'^profile/$', 'profile'), - (r'^chg_pass/$', 'chg_pass'), + (r'^chg_info/$', 'chg_info'), (r'^chg_role/$', 'chg_role'), ) diff --git a/juser/views.py b/juser/views.py index 2b6530969..eb0a361ec 100644 --- a/juser/views.py +++ b/juser/views.py @@ -233,10 +233,13 @@ def dept_list_adm(request): return render_to_response('juser/dept_list.html', locals(), context_instance=RequestContext(request)) - -@require_admin def chg_role(request): - request.session['role_id'] = 0 + role = {'SU': 2, 'DA': 1, 'CU': 0} + user, dept = get_session_user_dept(request) + if request.session['role_id'] > 0: + request.session['role_id'] = 0 + elif request.session['role_id'] == 0: + request.session['role_id'] = role.get(user.role, 0) return HttpResponseRedirect('/') @@ -953,8 +956,36 @@ def profile(request): return render_to_response('juser/user_detail.html', locals(), context_instance=RequestContext(request)) -def chg_pass(request): +def chg_info(request): header_title, path1, path2 = '修改信息 | Edit Info', '用户管理', '修改个人信息' + user_id = request.session.get('user_id') + user_set = User.objects.filter(id=user_id) + error = '' + if user_set: + user = user_set[0] + else: + return HttpResponseRedirect('/') - return render_to_response('juser/user_add.html', locals(), context_instance=RequestContext(request)) + if request.method == 'POST': + name = request.POST.get('name', '') + password = request.POST.get('password', '') + ssh_key_pwd = request.POST.get('ssh_key_pwd', '') + email = request.POST.get('email', '') + + if '' in [name, password, ssh_key_pwd, email]: + error = '不能为空' + + if len(password) < 6 or len(ssh_key_pwd) < 6: + error = '密码须大于6位' + + if not error: + if password != user.password: + password = md5_crypt(password) + + if ssh_key_pwd != user.ssh_key_pwd: + ssh_key_pwd = md5_crypt(ssh_key_pwd) + user_set.update(name=name, password=password, ssh_key_pwd=ssh_key_pwd, email=email) + msg = '修改成功' + + return render_to_response('juser/chg_info.html', locals(), context_instance=RequestContext(request)) diff --git a/templates/footer.html b/templates/footer.html index 3574f1c9e..00305471b 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -1,6 +1,6 @@ diff --git a/templates/juser/user_list.html b/templates/juser/user_list.html index 6f2389e04..d6b362f00 100644 --- a/templates/juser/user_list.html +++ b/templates/juser/user_list.html @@ -72,7 +72,7 @@ {{ user.id | get_role }} {{ user.is_active|bool2str }} - 详情 + 详情 {% ifequal session_role_id 2 %} 编辑 删除 @@ -80,7 +80,6 @@ 编辑 删除 {% endifequal %} - {% endfor %} @@ -102,8 +101,21 @@