change role finished , but need more think

pull/26/head
liuzheng712 2015-10-28 21:03:54 +08:00
parent 4d3e7d694b
commit ac5ac5e06b
5 changed files with 21 additions and 19 deletions

View File

@ -217,12 +217,12 @@ def Login(request):
# if PyCrypt.md5_crypt(password) == user.password: # if PyCrypt.md5_crypt(password) == user.password:
# request.session['user_id'] = user.id # request.session['user_id'] = user.id
# user_filter.update(last_login=datetime.datetime.now()) # user_filter.update(last_login=datetime.datetime.now())
# if user.role == 'SU': if user.role == 'SU':
# request.session['role_id'] = 2 request.session['role_id'] = 2
# elif user.role == 'GA': elif user.role == 'GA':
# request.session['role_id'] = 1 request.session['role_id'] = 1
# else: else:
# request.session['role_id'] = 0 request.session['role_id'] = 0
return HttpResponseRedirect('/', ) return HttpResponseRedirect('/', )
# response.set_cookie('username', username, expires=604800) # response.set_cookie('username', username, expires=604800)
# response.set_cookie('seed', PyCrypt.md5_crypt(password), expires=604800) # response.set_cookie('seed', PyCrypt.md5_crypt(password), expires=604800)

View File

@ -22,6 +22,6 @@ urlpatterns = patterns('juser.views',
(r'^profile/$', 'profile'), (r'^profile/$', 'profile'),
(r'^change_info/$', 'change_info'), (r'^change_info/$', 'change_info'),
(r'^regen_ssh_key/$', 'regen_ssh_key'), (r'^regen_ssh_key/$', 'regen_ssh_key'),
(r'^chg_role/$', 'chg_role'), (r'^change_role/$', 'chg_role'),
(r'^down_key/$', 'down_key'), (r'^down_key/$', 'down_key'),
) )

View File

@ -14,14 +14,11 @@ from juser.user_api import *
def chg_role(request): def chg_role(request):
# TODO: disable it! by liuzheng
role = {'SU': 2, 'GA': 1, 'CU': 0} role = {'SU': 2, 'GA': 1, 'CU': 0}
user, dept = get_session_user_dept(request)
# TODO: liuzheng's work
if request.session['role_id'] > 0: if request.session['role_id'] > 0:
request.session['role_id'] = 0 request.session['role_id'] = 0
elif 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('/') return HttpResponseRedirect('/')

View File

@ -1,4 +1,4 @@
{% ifequal session_role_id 2 %} {% if request.session.role_id == 2 %}
<nav class="navbar-default navbar-static-side" role="navigation"> <nav class="navbar-default navbar-static-side" role="navigation">
<div class="sidebar-collapse"> <div class="sidebar-collapse">
<ul class="nav" id="side-menu"> <ul class="nav" id="side-menu">
@ -51,8 +51,8 @@
</div> </div>
</nav> </nav>
{% endifequal %} {% endif %}
{% ifequal session_role_id 1 %} {% if request.session.role_id == 1 %}
<nav class="navbar-default navbar-static-side" role="navigation"> <nav class="navbar-default navbar-static-side" role="navigation">
<div class="sidebar-collapse"> <div class="sidebar-collapse">
<ul class="nav" id="side-menu"> <ul class="nav" id="side-menu">
@ -103,9 +103,9 @@
</ul> </ul>
</div> </div>
</nav> </nav>
{% endifequal %} {% endif %}
{% ifequal session_role_id 0 %} {% if request.session.role_id == 0 %}
<nav class="navbar-default navbar-static-side" role="navigation"> <nav class="navbar-default navbar-static-side" role="navigation">
<div class="sidebar-collapse"> <div class="sidebar-collapse">
<ul class="nav" id="side-menu"> <ul class="nav" id="side-menu">
@ -144,4 +144,4 @@
</ul> </ul>
</div> </div>
</nav> </nav>
{% endifequal %} {% endif %}

View File

@ -17,8 +17,13 @@
<ul class="dropdown-menu animated fadeInRight m-t-xs"> <ul class="dropdown-menu animated fadeInRight m-t-xs">
<li><a value="/juser/profile/?id={{ session_user_id }}" class="iframe_user">个人信息</a></li> <li><a value="/juser/profile/?id={{ session_user_id }}" class="iframe_user">个人信息</a></li>
<li><a href="/juser/change_info/">修改信息</a></li> <li><a href="/juser/change_info/">修改信息</a></li>
<li><a href="/juser/change_role/">切换角色</a></li> {% if not user.role == 'CU' %}
{% if request.session.role_id == 0 %}
<li><a href="/juser/change_role/">系统后台</a></li>
{% else %}
<li><a href="/juser/change_role/">主机控制台</a></li>
{% endif %}
{% endif %}
<li class="divider"></li> <li class="divider"></li>
<li><a href="/logout/">注销</a></li> <li><a href="/logout/">注销</a></li>
</ul> </ul>