mirror of https://github.com/jumpserver/jumpserver
修改修改用户bug
parent
c21cdc2131
commit
3efd810fe1
|
@ -27,10 +27,9 @@ def int2str(value):
|
||||||
|
|
||||||
@register.filter(name='get_role')
|
@register.filter(name='get_role')
|
||||||
def get_role(user_id):
|
def get_role(user_id):
|
||||||
user_role = {'SU': u'超级管理员', 'DA': u'部门管理员', 'CU': u'普通用户'}
|
user_role = {'SU': u'超级管理员', 'GA': u'组管理员', 'CU': u'普通用户'}
|
||||||
user = User.objects.filter(id=user_id)
|
user = get_object(User, id=user_id)
|
||||||
if user:
|
if user:
|
||||||
user = user[0]
|
|
||||||
return user_role.get(str(user.role), u"普通用户")
|
return user_role.get(str(user.role), u"普通用户")
|
||||||
else:
|
else:
|
||||||
return u"普通用户"
|
return u"普通用户"
|
||||||
|
|
|
@ -130,4 +130,7 @@ class AdminGroup(models.Model):
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
group = models.ForeignKey(UserGroup)
|
group = models.ForeignKey(UserGroup)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return '%s: %s' % (self.user.username, self.group.name)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -81,19 +81,28 @@ def db_update_user(**kwargs):
|
||||||
数据库更新用户信息
|
数据库更新用户信息
|
||||||
"""
|
"""
|
||||||
groups_post = kwargs.pop('groups')
|
groups_post = kwargs.pop('groups')
|
||||||
|
admin_groups_post = kwargs.pop('admin_groups')
|
||||||
user_id = kwargs.pop('user_id')
|
user_id = kwargs.pop('user_id')
|
||||||
user = User.objects.filter(id=user_id)
|
user = User.objects.filter(id=user_id)
|
||||||
if user:
|
if user:
|
||||||
user.update(**kwargs)
|
user.update(**kwargs)
|
||||||
user = User.objects.get(id=user_id)
|
user = user[0]
|
||||||
user.save()
|
user.save()
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
group_select = []
|
||||||
if groups_post:
|
if groups_post:
|
||||||
group_select = []
|
|
||||||
for group_id in groups_post:
|
for group_id in groups_post:
|
||||||
group = UserGroup.objects.filter(id=group_id)
|
group = UserGroup.objects.filter(id=group_id)
|
||||||
group_select.extend(group)
|
group_select.extend(group)
|
||||||
user.group = group_select
|
user.group = group_select
|
||||||
|
|
||||||
|
if admin_groups_post != '':
|
||||||
|
user.admingroup_set.all().delete()
|
||||||
|
for group_id in admin_groups_post:
|
||||||
|
group = get_object(UserGroup, id=group_id)
|
||||||
|
AdminGroup(user=user, group=group).save()
|
||||||
|
|
||||||
|
|
||||||
def db_del_user(username):
|
def db_del_user(username):
|
||||||
|
|
|
@ -527,54 +527,60 @@ def user_edit(request):
|
||||||
if not user_id:
|
if not user_id:
|
||||||
return HttpResponseRedirect('/')
|
return HttpResponseRedirect('/')
|
||||||
|
|
||||||
user_role = {'SU': u'超级管理员', 'DA': u'组管理员', 'CU': u'普通用户'}
|
user_role = {'SU': u'超级管理员', 'GA': u'组管理员', 'CU': u'普通用户'}
|
||||||
user = get_object(User, id=user_id)
|
user = get_object(User, id=user_id)
|
||||||
group_all = UserGroup.objects.all()
|
group_all = UserGroup.objects.all()
|
||||||
|
|
||||||
if user:
|
if user:
|
||||||
groups_str = ' '.join([str(group.id) for group in user.group.all()])
|
groups_str = ' '.join([str(group.id) for group in user.group.all()])
|
||||||
|
admin_groups_str = ' '.join([str(admin_group.group.id) for admin_group in user.admingroup_set.all()])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
user_id = request.POST.get('user_id', '')
|
user_id = request.GET.get('id', '')
|
||||||
password = request.POST.get('password', '')
|
password = request.POST.get('password', '')
|
||||||
name = request.POST.get('name', '')
|
name = request.POST.get('name', '')
|
||||||
email = request.POST.get('email', '')
|
email = request.POST.get('email', '')
|
||||||
dept_id = request.POST.get('dept_id')
|
|
||||||
groups = request.POST.getlist('groups', [])
|
groups = request.POST.getlist('groups', [])
|
||||||
role_post = request.POST.get('role', 'CU')
|
role_post = request.POST.get('role', 'CU')
|
||||||
ssh_key_pwd = request.POST.get('ssh_key_pwd', '')
|
admin_groups = request.POST.getlist('admin_groups', [])
|
||||||
is_active = True if request.POST.get('is_active', '1') == '1' else False
|
extra = request.POST.getlist('extra', [])
|
||||||
|
is_active = True if '0' in extra else False
|
||||||
|
email_need = True if '2' in extra else False
|
||||||
user_role = {'SU': u'超级管理员', 'DA': u'部门管理员', 'CU': u'普通用户'}
|
user_role = {'SU': u'超级管理员', 'DA': u'部门管理员', 'CU': u'普通用户'}
|
||||||
dept = DEPT.objects.filter(id=dept_id)
|
print '#'*10 + str(email_need)
|
||||||
if dept:
|
print extra
|
||||||
dept = dept[0]
|
|
||||||
else:
|
|
||||||
dept = DEPT.objects.get(id='2')
|
|
||||||
|
|
||||||
if user_id:
|
if user_id:
|
||||||
user = User.objects.filter(id=user_id)
|
user = get_object(User, id=user_id)
|
||||||
if user:
|
|
||||||
user = user[0]
|
|
||||||
else:
|
else:
|
||||||
return HttpResponseRedirect('/juser/user_list/')
|
return HttpResponseRedirect('/juser/user_list/')
|
||||||
|
|
||||||
if password != user.password:
|
if password != user.password:
|
||||||
|
password_decode = password
|
||||||
password = CRYPTOR.md5_crypt(password)
|
password = CRYPTOR.md5_crypt(password)
|
||||||
|
else:
|
||||||
if ssh_key_pwd != user.ssh_key_pwd:
|
password_decode = None
|
||||||
gen_ssh_key(user.username, ssh_key_pwd)
|
|
||||||
ssh_key_pwd = CRYPTOR.encrypt(ssh_key_pwd)
|
|
||||||
|
|
||||||
db_update_user(user_id=user_id,
|
db_update_user(user_id=user_id,
|
||||||
password=password,
|
password=password,
|
||||||
name=name,
|
name=name,
|
||||||
email=email,
|
email=email,
|
||||||
groups=groups,
|
groups=groups,
|
||||||
dept=dept,
|
admin_groups=admin_groups,
|
||||||
role=role_post,
|
role=role_post,
|
||||||
is_active=is_active,
|
is_active=is_active)
|
||||||
ssh_key_pwd=ssh_key_pwd)
|
|
||||||
|
if email_need:
|
||||||
|
|
||||||
|
msg = u"""
|
||||||
|
Hi %s:
|
||||||
|
您的信息已修改,请登录跳板机查看详细信息
|
||||||
|
地址:%s
|
||||||
|
用户名: %s
|
||||||
|
密码:%s (如果密码为None代表密码为原密码)
|
||||||
|
角色:%s
|
||||||
|
|
||||||
|
""" % (user.name, URL, user.username, password_decode, user_role.get(role_post, u''))
|
||||||
|
|
||||||
|
send_mail('您的信息已修改', msg, MAIL_FROM, [email], fail_silently=False)
|
||||||
|
|
||||||
return HttpResponseRedirect('/juser/user_list/')
|
return HttpResponseRedirect('/juser/user_list/')
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div class="footer fixed">
|
<div class="footer fixed">
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
Version <strong>2.0.0</strong> GPL.
|
Version <strong>0.2.0</strong> GPL.
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<strong>Copyright</strong> Jumpserver.org Team © 2014-2015
|
<strong>Copyright</strong> Jumpserver.org Team © 2014-2015
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ibox-content">
|
<div class="ibox-content">
|
||||||
<form method="post" id="userForm" class="form-horizontal" action="">
|
<form method="post" id="userForm" class="form-horizontal" action="/juser/user_edit/?id={{ user.id }}">
|
||||||
{% if error %}
|
{% if error %}
|
||||||
<div class="alert alert-warning text-center">{{ error }}</div>
|
<div class="alert alert-warning text-center">{{ error }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -33,7 +33,6 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="username" class="col-sm-2 control-label">用户名<span class="red-fonts">*</span></label>
|
<label for="username" class="col-sm-2 control-label">用户名<span class="red-fonts">*</span></label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input id="user_id" name="user_id" type="text" value="{{ user.id }}" style="display: none">
|
|
||||||
<input id="username" name="username" placeholder="Username" type="text" class="form-control" value="{{ user.username }}" readonly>
|
<input id="username" name="username" placeholder="Username" type="text" class="form-control" value="{{ user.username }}" readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -48,16 +47,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="hr-line-dashed"></div>
|
<div class="hr-line-dashed"></div>
|
||||||
<div class="form-group">
|
|
||||||
<label for="ssh_key_pwd" class="col-sm-2 control-label">密钥密码<span class="red-fonts">*</span></label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<input id="ssh_key_pwd" name="ssh_key_pwd" placeholder="SSH Key Password" type="password" class="form-control" value="{{ user.ssh_key_pwd }}">
|
|
||||||
<span class="help-block m-b-none">
|
|
||||||
登陆 Jumpserver 使用的SSH密钥的密码,更改密钥密码需要重新下载密钥
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="hr-line-dashed"></div>
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="name" class="col-sm-2 control-label">姓名<span class="red-fonts">*</span></label>
|
<label for="name" class="col-sm-2 control-label">姓名<span class="red-fonts">*</span></label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
|
@ -79,23 +68,38 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% ifequal session_role_id 2 %}
|
|
||||||
<div class="hr-line-dashed"></div>
|
<div class="hr-line-dashed"></div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="role" class="col-lg-2 control-label">角色<span class="red-fonts">*</span></label>
|
<label for="role" class="col-lg-2 control-label">角色<span class="red-fonts">*</span></label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<select id="role" name="role" class="form-control m-b">
|
{% for r, role_name in user_role.items %}
|
||||||
{% for r, role_name in user_role.items %}
|
<div class="col-sm-3">
|
||||||
{% ifequal r user.role %}
|
<div class="radio i-checks">
|
||||||
<option value="{{ r }}" selected>{{ role_name }}</option>
|
<label><input type="radio" value="{{ r }}" class="role" name="role" {% ifequal r user.role %} checked {% endifequal %}>{{ role_name }}</label>
|
||||||
{% else %}
|
</div>
|
||||||
<option value="{{ r }}">{{ role_name }}</option>
|
</div>
|
||||||
{% endifequal %}
|
{% endfor %}
|
||||||
{% endfor %}
|
</div>
|
||||||
</select>
|
</div>
|
||||||
|
<div class="form-group" id="admin_groups" {% ifnotequal user.role "GA" %} style="display: none" {% endifnotequal %}>
|
||||||
|
<label for="role" class="col-sm-2 control-label">管理用户组</label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
{% for user_group in group_all %}
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<div class="checkbox i-checks">
|
||||||
|
<label>
|
||||||
|
{% if user_group.id|int2str in admin_groups_str %}
|
||||||
|
<input type="checkbox" value="{{ user_group.id }}" name="admin_groups" checked >
|
||||||
|
{% else %}
|
||||||
|
<input type="checkbox" value="{{ user_group.id }}" name="admin_groups" >
|
||||||
|
{% endif %}
|
||||||
|
{{ user_group.name }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endifequal %}
|
|
||||||
<div class="hr-line-dashed"></div>
|
<div class="hr-line-dashed"></div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="email" class="col-sm-2 control-label">Email<span class="red-fonts">*</span></label>
|
<label for="email" class="col-sm-2 control-label">Email<span class="red-fonts">*</span></label>
|
||||||
|
@ -104,15 +108,15 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="hr-line-dashed"></div>
|
<div class="hr-line-dashed"></div>
|
||||||
<div class="form-group"><label class="col-sm-2 control-label">是否启用</label>
|
<div class="form-group"><label class="col-sm-2 control-label">额外</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-2">
|
||||||
<div class="radio i-checks">
|
<div class="checkbox i-checks">
|
||||||
<label>
|
<label><input type="checkbox" value="0" name="extra" {% ifequal user.is_active 1 %} checked {% endifequal %} >禁用 </label>
|
||||||
<input type="radio" value="1" name="is_active" {% if user.is_active %} } checked {% endif %}>启用
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="radio i-checks">
|
</div>
|
||||||
<label><input type="radio" value="0" name="is_active" {% if not user.is_active %} checked {% endif %}>禁用 </label>
|
<div class="col-sm-2">
|
||||||
|
<div class="checkbox i-checks">
|
||||||
|
<label><input type="checkbox" value="2" name="extra">发送邮件 </label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -129,18 +133,20 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block self_footer_js %}
|
||||||
<script>
|
<script>
|
||||||
$('#userForm').validator({
|
$('#userForm').validator({
|
||||||
timely: 2,
|
timely: 2,
|
||||||
theme: "yellow_right_effect",
|
theme: "yellow_right_effect",
|
||||||
rules: {
|
{# rules: {#}
|
||||||
check_ip: [/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/, 'ip地址不正确'],
|
{# check_ip: [/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/, 'ip地址不正确'],#}
|
||||||
check_port: [/^\d{1,5}$/, '端口号不正确'],
|
{# check_port: [/^\d{1,5}$/, '端口号不正确'],#}
|
||||||
type_m: function(element){
|
{# type_m: function (element) {#}
|
||||||
return $("#M").is(":checked");
|
{# return $("#M").is(":checked");#}
|
||||||
}
|
{# }#}
|
||||||
},
|
{# },#}
|
||||||
fields: {
|
fields: {
|
||||||
"username": {
|
"username": {
|
||||||
rule: "required",
|
rule: "required",
|
||||||
|
@ -154,18 +160,6 @@ $('#userForm').validator({
|
||||||
ok: "",
|
ok: "",
|
||||||
msg: {required: "必须填写!"}
|
msg: {required: "必须填写!"}
|
||||||
},
|
},
|
||||||
"ssh_key_pwd": {
|
|
||||||
rule: "required;length[6~50]",
|
|
||||||
tip: "ssh私钥密码",
|
|
||||||
ok: "",
|
|
||||||
msg: {required: "必须填写"}
|
|
||||||
},
|
|
||||||
"dept_id": {
|
|
||||||
rule: "checked",
|
|
||||||
tip: "选择部门",
|
|
||||||
ok: "",
|
|
||||||
msg: {checked: "至少选择一个部门"}
|
|
||||||
},
|
|
||||||
"name": {
|
"name": {
|
||||||
rule: "required",
|
rule: "required",
|
||||||
tip: "姓名",
|
tip: "姓名",
|
||||||
|
@ -178,19 +172,21 @@ $('#userForm').validator({
|
||||||
ok: "",
|
ok: "",
|
||||||
msg: {required: "必须填写"}
|
msg: {required: "必须填写"}
|
||||||
},
|
},
|
||||||
"role": {
|
valid: function (form) {
|
||||||
rule: "checked",
|
form.submit();
|
||||||
tip: "角色",
|
|
||||||
ok: "",
|
|
||||||
msg: {required: "选择一个"}
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
valid: function(form) {
|
|
||||||
form.submit();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("document").ready(function(){
|
||||||
|
$("input.role").click(function(){
|
||||||
|
if($("input.role[value=GA]").is( ":checked" )){
|
||||||
|
$("#admin_groups").css("display", 'block');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$("#admin_groups").css("display", 'none');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in New Issue