From f7a54e13c3045742dc22cbc1bdf0929b7b41b174 Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Sat, 10 Jan 2015 14:52:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- juser/views.py | 39 ++++++++++++++++++++++++++++++++--- static/css/style.css | 2 +- templates/juser/user_add.html | 18 ++++++++++++---- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/juser/views.py b/juser/views.py index 5c44bdc16..21174962d 100644 --- a/juser/views.py +++ b/juser/views.py @@ -55,12 +55,27 @@ def user_list(request): pass +def db_add_user(**kwargs): + user = User(**kwargs) + group_select = [] + for group_id in groups: + group = UserGroup.objects.filter(id=group_id) + group_select.extend(group) + user.user_group = group_select + user.save() + + +def db_del_user(username): + user = User.objects.get(username=username) + user.delete() + + def user_add(request): error = '' msg = '' - user_role = {'SU': 'SuperUser', 'GA': 'GroupAdmin', 'CU': 'CommonUser'} - groups = UserGroup.objects.all() + user_role = {'SU': u'超级管理员', 'GA': u'组管理员', 'CU': u'普通用户'} + all_group = UserGroup.objects.all() if request.method == 'POST': username = request.POST.get('j_username', None) password = request.POST.get('j_password', None) @@ -69,12 +84,30 @@ def user_add(request): groups = request.POST.getlist('j_group', None) role = request.POST.get('j_role', None) ssh_pwd = request.POST.get('j_ssh_pwd', None) + ssh_key_pwd1 = request.POST.get('j_ssh_key_pwd1', None) is_active = request.POST.get('j_is_active', None) + try: + if None in [username, password, ssh_key_pwd1, name, groups, role, is_active]: + error = u'带*内容不能为空' + raise AddError + user = User.objects.filter(username=username) + if user: + error = u'用户 %s 已存在' % username + raise AddError + + except AddError: + pass + else: + db_add_user(username=username, password=password, name=name, email=email, + groups=groups, role=role, ssh_pwd=ssh_pwd, ssh_key_pwd1=ssh_key_pwd1, + is_active=is_active) + msg = u'添加用户成功' return render_to_response('juser/user_add.html', {'header_title': u'添加用户 | Add User', 'path1': 'juser', 'path2': 'user_add', - 'roles': user_role, 'groups': groups}) + 'roles': user_role, 'all_group': all_group, + 'error': error, 'msg': msg}) diff --git a/static/css/style.css b/static/css/style.css index 9c9fc28d3..956572145 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -1,4 +1,4 @@ -/*@import url("//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&lang=en");*/ +@import url("//fonts.useso.com/css?family=Open+Sans:300,400,600,700&lang=en"); /* * * INSPINIA - Responsive Admin Theme diff --git a/templates/juser/user_add.html b/templates/juser/user_add.html index bc24ab1fa..5bd387430 100644 --- a/templates/juser/user_add.html +++ b/templates/juser/user_add.html @@ -45,6 +45,16 @@
+
+ +
+ + + 登陆Jumpserver Terminal 使用SSH密钥的密码 + +
+
+
@@ -63,7 +73,7 @@
{% for r, role in roles.items %} - + {% endfor %}
- +
- + 如果使用password方式,该密码是用户在后端服务器的密码