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