前端页面
修改密码
//打开模态框
function changPassword(){
$("#navbar_edit").modal({
backdrop :‘static‘
});
}
$("#navbar_edit").on("show.bs.modal", function() {
$("#navbar_edit #navbar_pwd_reset").formClear();
});
$("#navbar_edit").on("hidden.bs.modal", function() {
$(this).removeData("bs.modal");
});
$(document).on("click", "#navbar_save_btn", function(e) {
var old_psd = $("#navbar_pwd_reset #old_password").val();
var new_psd = $("#navbar_pwd_reset #new_password").val();
var con_psd = $("#navbar_pwd_reset #confirm_password").val();
//alert(old_psd);
//alert(new_psd);
//alert(con_psd);
if (old_psd == "" || new_psd == "" || con_psd == "") {
bootbox.alert("相关字段不为空,请输入!");
return false;
};
if (old_psd == new_psd) {
bootbox.alert("旧密码和新密码相同,请重新输入!");
return false;
};
if (new_psd != con_psd) {
bootbox.alert("两次输入新密码不相同,请重新输入!");
return false;
};
var params = $("#navbar_pwd_reset").serialize();
//alert(params);
$.ajax({
cache : true,
type : "POST",
url : "${ctx!}/modifyPassword",
data : params,
async : false,
error : function(request) {
bootbox.alert("服务器连接错误,请稍后再试");
},
success : function(data) {
if (SQ.isOK(data)) {
bootbox.alert("重置成功", function() {
$("#navbar_close_btn").click();
});
} else {
bootbox.alert("重置失败:" + SQ.getMessage(data));
}
},
});
});
后端页面
public void modifyPassword() {
BasMember sysUser = this.getLoginUser();
if (sysUser == null || sysUser.getInt(BasMember.IsDelete).equals(1)) {
render(new JsonRender(new AjaxResult(Constants.RESPONSE_STATUS_FAIL, "会话已过期,请重新登录!")).forIE());
return;
}
// 旧秘密
String password = getPara("old_password");
password = CommonUtil.getEncryptedPwd(password);
if (!password.equals(sysUser.get(BasMember.Password))) {
render(new JsonRender(new AjaxResult(Constants.RESPONSE_STATUS_FAIL, "旧密码不正确!")).forIE());
return;
}
// 新密码
password = getPara("new_password");
password = CommonUtil.getEncryptedPwd(password);
// 赋值
sysUser.set(BasMember.Password, password);
sysUser.set(BasMember.ModifyBy, this.getLoginId());
sysUser.set(BasMember.ModifyTime, StringUtil.getNowTime());
if (!sysUser.update()) {
render(new JsonRender(new AjaxResult(Constants.RESPONSE_STATUS_FAIL, "修改时出现异常")).forIE());
}
render(new JsonRender(new AjaxResult(Constants.RESPONSE_STATUS_OK, "修改成功!")).forIE());
}