From ac5ac5e06b62c4c81a0e3cce1f23760cb7f1fcb7 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Wed, 28 Oct 2015 21:03:54 +0800 Subject: [PATCH] change role finished , but need more think --- jumpserver/views.py | 12 ++++++------ juser/urls.py | 2 +- juser/views.py | 5 +---- templates/nav.html | 12 ++++++------ templates/nav_li_profile.html | 9 +++++++-- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/jumpserver/views.py b/jumpserver/views.py index cdae32617..f8fc6a21d 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -217,12 +217,12 @@ def Login(request): # if PyCrypt.md5_crypt(password) == user.password: # request.session['user_id'] = user.id # user_filter.update(last_login=datetime.datetime.now()) - # if user.role == 'SU': - # request.session['role_id'] = 2 - # elif user.role == 'GA': - # request.session['role_id'] = 1 - # else: - # request.session['role_id'] = 0 + if user.role == 'SU': + request.session['role_id'] = 2 + elif user.role == 'GA': + request.session['role_id'] = 1 + else: + request.session['role_id'] = 0 return HttpResponseRedirect('/', ) # response.set_cookie('username', username, expires=604800) # response.set_cookie('seed', PyCrypt.md5_crypt(password), expires=604800) diff --git a/juser/urls.py b/juser/urls.py index 5e6f354bf..3b786051f 100644 --- a/juser/urls.py +++ b/juser/urls.py @@ -22,6 +22,6 @@ urlpatterns = patterns('juser.views', (r'^profile/$', 'profile'), (r'^change_info/$', 'change_info'), (r'^regen_ssh_key/$', 'regen_ssh_key'), - (r'^chg_role/$', 'chg_role'), + (r'^change_role/$', 'chg_role'), (r'^down_key/$', 'down_key'), ) diff --git a/juser/views.py b/juser/views.py index 4a9f69d1a..aafa10d15 100644 --- a/juser/views.py +++ b/juser/views.py @@ -14,14 +14,11 @@ from juser.user_api import * def chg_role(request): - # TODO: disable it! by liuzheng role = {'SU': 2, 'GA': 1, 'CU': 0} - user, dept = get_session_user_dept(request) - # TODO: liuzheng's work if request.session['role_id'] > 0: request.session['role_id'] = 0 elif request.session['role_id'] == 0: - request.session['role_id'] = role.get(user.role, 0) + request.session['role_id'] = role.get(request.user.role, 0) return HttpResponseRedirect('/') diff --git a/templates/nav.html b/templates/nav.html index f08339d83..5337b749a 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -1,4 +1,4 @@ -{% ifequal session_role_id 2 %} +{% if request.session.role_id == 2 %} -{% endifequal %} -{% ifequal session_role_id 1 %} +{% endif %} +{% if request.session.role_id == 1 %} -{% endifequal %} +{% endif %} -{% ifequal session_role_id 0 %} +{% if request.session.role_id == 0 %} -{% endifequal %} \ No newline at end of file +{% endif %} \ No newline at end of file diff --git a/templates/nav_li_profile.html b/templates/nav_li_profile.html index 972a57f50..5a277698c 100644 --- a/templates/nav_li_profile.html +++ b/templates/nav_li_profile.html @@ -17,8 +17,13 @@