数据库添加用户

pull/6/head
guanghongwei 10 years ago
parent 796533b7a9
commit f7a54e13c3

@ -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})

@ -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

@ -45,6 +45,16 @@
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="j_ssh_key_pwd1" class="col-sm-2 control-label">瀵嗛挜瀵嗙爜<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input id="j_ssh_key_pwd1" name="j_ssh_key_pwd1" placeholder="SSH Key Password" type="password" class="form-control">
<span class="help-block m-b-none">
鐧婚檰Jumpserver Terminal 浣跨敤SSH瀵嗛挜鐨勫瘑鐮
</span>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="j_name" class="col-sm-2 control-label">濮撳悕<span class="red-fonts">*</span></label>
<div class="col-sm-8">
@ -63,7 +73,7 @@
<label for="j_group" class="col-lg-2 control-label">灞炵粍<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<select id="j_group" name="j_group" class="form-control m-b" multiple>
{% for group in groups %}
{% for group in all_group %}
{% if forloop.first %}
<option value="{{ group.id }}" selected>{{ group.name }}</option>
{% else %}
@ -79,16 +89,16 @@
<div class="col-sm-8">
<select id="j_role" name="j_role" class="form-control m-b">
{% for r, role in roles.items %}
<option value="{{ r }}">{{ role }}</option>
<option value="{{ r }}">{{ role }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="j_ldap_pwd" class="col-sm-2 control-label">SSH瀵嗙爜</label>
<label for="j_ssh_pwd" class="col-sm-2 control-label">SSH瀵嗙爜</label>
<div class="col-sm-8">
<input id="j_ldap_pwd" name="j_ldap_pwd" type="password" placeholder="LDAP Password" class="form-control">
<input id="j_ssh_pwd" name="j_ssh_pwd" type="password" placeholder="SSH Password" class="form-control">
<span class="help-block m-b-none">
濡傛灉浣跨敤password鏂瑰紡璇ュ瘑鐮佹槸鐢ㄦ埛鍦ㄥ悗绔湇鍔″櫒鐨勫瘑鐮
</span>

Loading鈥
Cancel
Save