Skip to content

Commit

Permalink
用户修改密码时需校验原密码
Browse files Browse the repository at this point in the history
  • Loading branch information
zmister committed Oct 28, 2021
1 parent 0fff3cf commit 2324148
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
6 changes: 5 additions & 1 deletion app_admin/views.py
Expand Up @@ -1009,9 +1009,13 @@ def admin_register_code(request):
def change_pwd(request):
if request.method == 'POST':
try:
old_pwd = request.POST.get('old_pwd', None)
password = request.POST.get('password',None)
password2 = request.POST.get('password2',None)
print(password, password2)
# print(password, password2)
user = request.user.check_password(old_pwd)
if user is False:
return JsonResponse({'status':False,'data':_('密码错误!')})
if password and password== password2:
if len(password) >= 6:
user = User.objects.get(id=request.user.id)
Expand Down
33 changes: 21 additions & 12 deletions template/app_doc/manage/manage_self.html
Expand Up @@ -66,25 +66,34 @@
title:'{% trans "修改密码" %}',
area:'300px;',
id:'changePwd',
content:'<div style="padding:10px 0 0 20px;">修改用户密码:</div><div style="padding: 20px;"><input class="layui-input" type="password" id="newPwd1" style="margin-bottom:10px;" placeholder="输入新密码" required lay-verify="required"><input class="layui-input" type="password" id="newPwd2" placeholder="再次确认新密码" required lay-verify="required"></div>',
content:'<div style="padding:10px 0 0 20px;">修改用户密码:</div><div style="padding: 20px;"><input class="layui-input" type="password" id="oldPwd" style="margin-bottom:10px;" placeholder="输入原密码" required lay-verify="required"><input class="layui-input" type="password" id="newPwd1" style="margin-bottom:10px;" placeholder="输入新密码" required lay-verify="required"><input class="layui-input" type="password" id="newPwd2" placeholder="再次确认新密码" required lay-verify="required"></div>',
btn:['{% trans "确认修改" %}','{% trans "取消" %}'],
yes:function (index,layero) {
layer.load(1);
data = {
'old_pwd':$("#oldPwd").val(),
'password':$("#newPwd1").val(),
'password2':$("#newPwd2").val(),
}
$.post("{% url 'modify_pwd' %}",data,function(r){
layer.closeAll("loading");
if(r.status){
//修改成功
// window.location.reload();
layer.close(index)
layer.msg("{% trans '修改成功' %}")
}else{
//修改失败,提示
//console.log(r)
layer.msg(r.data)
$.ajax({
url:"{% url 'modify_pwd' %}",
type:"post",
data:data,
success:function(r){
layer.closeAll('loading');
if(r.status){
//修改成功
layer.close(index)
layer.msg("{% trans '修改成功' %}")
}else{
//修改失败,提示
//console.log(r)
layer.msg(r.data,{icon:2})
}
},
error:function(){
layer.closeAll('loading');
layer.msg("修改异常",{icon:2})
}
})
},
Expand Down
32 changes: 21 additions & 11 deletions template/app_doc/pro_list.html
Expand Up @@ -447,24 +447,34 @@
title:'{% trans "修改密码" %}',
area:'300px;',
id:'changePwd',
content:'<div style="padding:10px 0 0 20px;">修改用户[' + username + ']的密码:</div><div style="padding: 20px;"><input class="layui-input" type="password" id="newPwd1" style="margin-bottom:10px;" placeholder="输入新密码" required lay-verify="required"><input class="layui-input" type="password" id="newPwd2" placeholder="再次确认新密码" required lay-verify="required"></div>',
content:'<div style="padding:10px 0 0 20px;">修改用户[' + username + ']的密码:</div><div style="padding: 20px;"><input class="layui-input" type="password" id="oldPwd" style="margin-bottom:10px;" placeholder="输入原密码" required lay-verify="required"><input class="layui-input" type="password" id="newPwd1" style="margin-bottom:10px;" placeholder="输入新密码" required lay-verify="required"><input class="layui-input" type="password" id="newPwd2" placeholder="再次确认新密码" required lay-verify="required"></div>',
btn:['{% trans "确认修改" %}','{% trans "取消" %}'],
yes:function (index,layero) {
layer.load(1);
data = {
'old_pwd':$("#oldPwd").val(),
'password':$("#newPwd1").val(),
'password2':$("#newPwd2").val(),
}
$.post("{% url 'modify_pwd' %}",data,function(r){
layer.closeAll("loading");
if(r.status){
//修改成功
window.location.reload();
//layer.close(index)
}else{
//修改失败,提示
//console.log(r)
layer.msg(r.data)
$.ajax({
url:"{% url 'modify_pwd' %}",
type:"post",
data:data,
success:function(r){
layer.closeAll('loading');
if(r.status){
//修改成功
window.location.reload();
//layer.close(index)
}else{
//修改失败,提示
//console.log(r)
layer.msg(r.data,{icon:2})
}
},
error:function(){
layer.closeAll('loading');
layer.msg("修改异常",{icon:2})
}
})
},
Expand Down

0 comments on commit 2324148

Please sign in to comment.