修改用户信息

pull/6/head
ibuler 2015-01-23 22:44:29 +08:00
parent d5cf3935d8
commit 3dca51d23c
2 changed files with 56 additions and 3 deletions

View File

@ -188,6 +188,8 @@ def user_del(request):
def user_edit(request):
header_title, path1, path2 = '编辑用户 | Edit User', 'juser', 'user_edit'
disabled = 'disabled'
if request.method == 'GET':
username = request.GET.get('username', None)
if not username:
@ -205,6 +207,43 @@ def user_edit(request):
ssh_pwd = user.ssh_pwd
email = user.email
else:
username = request.POST.get('username', None)
password = request.POST.get('password', None)
name = request.POST.get('name', None)
email = request.POST.get('email', '')
groups = request.POST.getlist('groups', None)
groups_str = ' '.join(groups)
role_post = request.POST.get('role', None)
ssh_pwd = request.POST.get('ssh_pwd', None)
ssh_key_pwd1 = request.POST.get('ssh_key_pwd1', None)
is_active = request.POST.get('is_active', '1')
ldap_pwd = gen_rand_pwd(16)
if username:
user = User.objects.filter(username=username)
else:
return HttpResponseRedirect('/')
if password != user.password:
password = md5_crypt(password)
if ssh_pwd != user.ssh_pwd:
ssh_pwd = CRYPTOR.encrypt(ssh_pwd)
if ssh_key_pwd1 != user.ssh_key_pwd1:
ssh_key_pwd1 = CRYPTOR.encrypt(ssh_key_pwd1)
db_update_user(username=username,
password=password,
name=name,
email=email,
groups=groups,
role=role_post,
ssh_pwd=ssh_pwd,
ssh_key_pwd1=ssh_key_pwd1)
msg = u'修改用户成功'
return render_to_response('juser/user_add.html', locals())
@ -219,6 +258,20 @@ def db_add_user(**kwargs):
user.user_group = group_select
def db_update_user(**kwargs):
groups_post = kwargs.pop('groups')
username = kwargs.get('username')
user = User.objects.filter(username=username)
user.update(**kwargs)
user = User.objects.get(username=username)
group_select = []
for group_id in groups_post:
group = UserGroup.objects.filter(id=group_id)
group_select.extend(group)
user.save()
user.user_group = group_select
def db_del_user(username):
try:
user = User.objects.get(username=username)
@ -301,7 +354,7 @@ def ldap_del_user(username):
group_dn = "cn=%s,ou=Group,%s" % (username, LDAP_BASE_DN)
sudo_dn = 'cn=%s,ou=Sudoers,%s' % (username, LDAP_BASE_DN)
ldap_conn = LDAPMgmt()
ldap_conn = LDAPMgmt(LDAP_HOST_URL, LDAP_BASE_DN, LDAP_ROOT_DN, LDAP_ROOT_PW)
ldap_conn.delete(user_dn)
ldap_conn.delete(group_dn)
ldap_conn.delete(sudo_dn)

View File

@ -38,7 +38,7 @@
<div class="form-group">
<label for="username" class="col-sm-2 control-label">用户名<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input id="username" name="username" placeholder="Username" type="text" class="form-control" value={{ username }}>
<input id="username" name="username" placeholder="Username" type="text" class="form-control" value={{ username }} {{ disabled }}>
</div>
</div>
<div class="hr-line-dashed"></div>