Browse Source

is_admin_role

pull/2/head
guanghongwei 10 years ago
parent
commit
d0a5274214
  1. 23
      webroot/AutoSa/AutoSa/views.py
  2. 4
      webroot/AutoSa/templates/chgUser.html
  3. 4
      webroot/AutoSa/templates/info.html

23
webroot/AutoSa/AutoSa/views.py

@ -186,7 +186,7 @@ def login_required(func):
def admin_required(func):
"""要求用户是admin的装饰器"""
def _deco(request, *args, **kwargs):
if not request.session.get('admin'):
if request.session.get('admin') < 1:
return HttpResponseRedirect('/')
return func(request, *args, **kwargs)
return _deco
@ -201,6 +201,13 @@ def superuser_required(func):
return _deco
def is_admin_role(request):
if request.session.get('admin') > 0:
return True
else:
return False
def is_admin_user(request):
if request.session.get('admin') == 1:
return True
@ -570,7 +577,7 @@ def chgGroup(request):
error = u'不能为空'
else:
group = Group.objects.get(id=group_id)
group['name'] = group_name
group.name = group_name
group.save()
msg = u'修改成功'
@ -709,13 +716,13 @@ def chgPass(request):
is_self = False
if request.method == 'GET':
if is_admin_user(request):
if is_admin_role(request):
username = request.GET.get('username')
else:
username = request.session.get('username')
is_self = True
return render_to_response('chgKey.html',
return render_to_response('chgPass.html',
{'username': username, 'is_self': is_self},
context_instance=RequestContext(request))
else:
@ -724,7 +731,7 @@ def chgPass(request):
password = request.POST.get('password')
password_again = request.POST.get('password_again')
if not is_admin_user(request):
if not is_admin_role(request):
oldpass = request.POST.get('oldpass')
if oldpass != user.password:
error = '原来密码不正确'
@ -735,7 +742,7 @@ def chgPass(request):
if error:
return render_to_response('info.html', {'error': error})
user['password'] = password
user.password = password
user.save()
return render_to_response('info.html', {'msg': '修改密码成功'})
@ -749,7 +756,7 @@ def chgKey(request):
is_self = False
if request.method == 'GET':
if is_admin_user(request):
if is_admin_role(request):
username = request.GET.get('username')
else:
username = request.session.get('username')
@ -764,7 +771,7 @@ def chgKey(request):
password = request.POST.get('password')
password_again = request.POST.get('password_again')
if not is_admin_user(request):
if not is_admin_role(request):
oldpass = request.POST.get('oldpass')
if oldpass != user.key_pass:
error = '原来密码不正确'

4
webroot/AutoSa/templates/chgUser.html

@ -34,7 +34,9 @@
</div>
<div class="form-group">
<label for="key_pass" class="col-sm-2 control-label">密钥密码<span style="color: red"> *</span></label>
<a href="/chgKey/?username={{ user.username }}">修改密码</a>
<div class="col-sm-4">
<a href="/chgKey/?username={{ user.username }}">修改密码</a>
</div>
</div>
<div class="form-group">
<label for="name" class="col-sm-2 control-label">姓名<span style="color: red"> *</span></label>

4
webroot/AutoSa/templates/info.html

@ -8,15 +8,13 @@
<style type="text/css">
body{
font-family:"Hiragino Sans GB W3", "微软雅黑", "Helvetica Neue", Helvetica, Arial, "宋体", sans-serif;
color: #575757;
background: #444 url(/static/images/bg-login.gif)
}
</style>
<script language="javascript">
var i=2;
window.setInterval("settime()",1000);
window.setTimeout("toload()",5000);
window.setTimeout("toload()",3000);
function settime(){
var divinner=document.getElementById("settime");
divinner.innerText=i;

Loading…
Cancel
Save