From bf23d6d7aa58eab16f3a7a1b5719b09a26b279ea Mon Sep 17 00:00:00 2001 From: ibuler Date: Sun, 6 Dec 2015 22:00:44 +0800 Subject: [PATCH] fix some bug --- jumpserver/views.py | 33 +---------- juser/user_api.py | 6 +- juser/views.py | 27 ++++----- templates/base.html | 3 - templates/footer.html | 2 +- templates/juser/change_info.html | 7 ++- templates/juser/reset_password.html | 42 ++++++++++---- templates/juser/user_add.html | 30 +++++----- templates/juser/user_detail.html | 10 +++- templates/juser/user_edit.html | 12 ++-- templates/nav.html | 4 +- templates/nav_li_profile.html | 14 ++--- templates/test.html | 0 templates/test2.html | 85 ----------------------------- 14 files changed, 92 insertions(+), 183 deletions(-) delete mode 100644 templates/test.html delete mode 100644 templates/test2.html diff --git a/jumpserver/views.py b/jumpserver/views.py index ed144bdf6..86d0b34e8 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -78,39 +78,8 @@ def get_count_by_date(date_li, item): @require_role(role='user') def index_cu(request): - # user_id = request.user.id - # user = get_object(User, id=user_id) - login_types = {'L': 'LDAP', 'M': 'MAP'} username = request.user.username - # TODO: need fix,liuzheng need Asset help - GUP = get_group_user_perm(request.user) - print GUP - assets = GUP.get('asset') - idcs = [] - for i in assets: - if i.idc_id: - idcs.append(i.idc_id) - idc_all = IDC.objects.filter(id__in=idcs) - for i in idc_all: - print i.name - # idc_all = [] - # for i in assets: - # idc_all.append(i.idc) - # print i.idc.name - asset_group_all = GUP.get('asset_group') - # posts = Asset.object.all() - # host_count = len(posts) - # - # new_posts = [] - # post_five = [] - # for post in posts: - # if len(post_five) < 5: - # post_five.append(post) - # else: - # new_posts.append(post_five) - # post_five = [] - # new_posts.append(post_five) - return render_to_response('index_cu.html', locals(), context_instance=RequestContext(request)) + return HttpResponseRedirect('/juser/user_detail/') @require_role(role='user') diff --git a/juser/user_api.py b/juser/user_api.py index 0248e5c6d..65f26c810 100644 --- a/juser/user_api.py +++ b/juser/user_api.py @@ -129,8 +129,8 @@ def gen_ssh_key(username, password='', 生成一个用户ssh密钥对 """ logger.debug('生成ssh key, 并设置authorized_keys') - private_key_file = os.path.join(key_dir, username) - mkdir(key_dir, mode=777) + private_key_file = os.path.join(key_dir, username, 'pem') + mkdir(key_dir, mode=0777) if os.path.isfile(private_key_file): os.unlink(private_key_file) ret = bash('echo -e "y\n"|ssh-keygen -t rsa -f %s -b %s -P "%s"' % (private_key_file, length, password)) @@ -142,7 +142,7 @@ def gen_ssh_key(username, password='', with open(private_key_file+'.pub') as pub_f: with open(authorized_key_file, 'w') as auth_f: auth_f.write(pub_f.read()) - os.chmod(authorized_key_file, 0600) + os.chmod(authorized_key_file, mode=0600) chown(authorized_key_file, username) diff --git a/juser/views.py b/juser/views.py index 695873135..0c5017e64 100644 --- a/juser/views.py +++ b/juser/views.py @@ -162,7 +162,7 @@ def user_add(request): ssh_key_pwd = PyCrypt.gen_rand_pass(16) extra = request.POST.getlist('extra', []) is_active = False if '0' in extra else True - ssh_key_login_need = True if '1' in extra else False + ssh_key_login_need = True send_mail_need = True if '2' in extra else False try: @@ -191,7 +191,7 @@ def user_add(request): user_groups = [] for user_group_id in groups: user_groups.extend(UserGroup.objects.filter(id=user_group_id)) - print user_groups + except IndexError, e: error = u'添加用户 %s 失败 %s ' % (username, e) try: @@ -302,7 +302,7 @@ def forget_password(request): """ % (user.name, URL, user.uuid, timestamp, hash_encode) send_mail('忘记跳板机密码', msg, MAIL_FROM, [email], fail_silently=False) msg = u'请登陆邮箱,点击邮件重设密码' - return HttpResponse(msg) + return http_success(request, msg) else: error = u'用户不存在或邮件地址错误' @@ -310,10 +310,16 @@ def forget_password(request): def reset_password(request): - uuid = request.GET.get('uuid', '') + uuid_r = request.GET.get('uuid', '') timestamp = request.GET.get('timestamp', '') hash_encode = request.GET.get('hash', '') - action = '/juser/reset_password/?uuid=%s×tamp=%s&hash=%s' % (uuid, timestamp, hash_encode) + action = '/juser/reset_password/?uuid=%s×tamp=%s&hash=%s' % (uuid_r, timestamp, hash_encode) + + if hash_encode == PyCrypt.md5_crypt(uuid_r + timestamp + KEY): + if int(time.time()) - int(timestamp) > 600: + return http_error(request, u'链接已超时') + else: + return render_to_response('juser/reset_password.html', locals()) if request.method == 'POST': password = request.POST.get('password') @@ -325,16 +331,10 @@ def reset_password(request): if user: user.password = PyCrypt.md5_crypt(password) user.save() - return HttpResponse('密码重设成功') + return http_success(request, u'密码重设成功') else: return HttpResponse('用户不存在') - if hash_encode == PyCrypt.md5_crypt(uuid + timestamp + KEY): - if int(time.time()) - int(timestamp) > 600: - return HttpResponse('链接已超时') - else: - return render_to_response('juser/reset_password.html', locals()) - return http_error(request, u'错误请求') @@ -428,7 +428,8 @@ def change_info(request): if '' in [name, email]: error = '不能为空' - if len(password) > 0 and len(password) < 6: + + if len(password) < 6: error = '密码须大于6位' if not error: diff --git a/templates/base.html b/templates/base.html index d325e9ff1..7b163003d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -2,7 +2,6 @@ - @@ -12,8 +11,6 @@ {% include 'link_css.html' %} {% include 'head_script.html' %} {% block self_head_css_js %} {% endblock %} - - diff --git a/templates/footer.html b/templates/footer.html index 0f1f6f76e..dc2bed153 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -1,6 +1,6 @@ -
-
- -
-
+{#
#} +{#
#} +{# #} +{#
#} +{#
#}
@@ -167,16 +167,16 @@ $('#userForm').validator({ } }); -$("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'); - } - }) -}) +{#$("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');#} +{# }#} +{# })#} +{#})#} {% endblock %} \ No newline at end of file diff --git a/templates/juser/user_detail.html b/templates/juser/user_detail.html index 12d47e84f..e529ee00b 100644 --- a/templates/juser/user_detail.html +++ b/templates/juser/user_detail.html @@ -45,9 +45,17 @@ {{ user.name }} - 角色 + 权限 {{ user.id | get_role }} + + key + {% if user.username|key_exist %} + 下载 + {% else %} + 下载 + {% endif %} + Email {{ user.email }} diff --git a/templates/juser/user_edit.html b/templates/juser/user_edit.html index 80a125d65..4fc083c07 100644 --- a/templates/juser/user_edit.html +++ b/templates/juser/user_edit.html @@ -140,13 +140,9 @@ $('#userForm').validator({ timely: 2, theme: "yellow_right_effect", -{# 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_port: [/^\d{1,5}$/, '端口号不正确'],#} -{# type_m: function (element) {#} -{# return $("#M").is(":checked");#} -{# }#} -{# },#} + rules: { + check_pass: [/^\w+$/, '数字和字符'] + }, fields: { "username": { rule: "required", @@ -155,7 +151,7 @@ $('#userForm').validator({ msg: {required: "必须填写!"} }, "password": { - rule: "length[6~50]", + rule: "length[6~50];check_pass", tip: "输入密码", ok: "", msg: {required: "必须填写!"} diff --git a/templates/nav.html b/templates/nav.html index 1949a66c2..c10f9733c 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -62,8 +62,8 @@