Front Page
<a href= "javascript:void (0);" onclick= "Changpassword ()" >
<i class= "Ace-icon fa fa-cog" ></i>
Change Password
</a>
<script type= "Text/javascript" >
Open Modal Box
function Changpassword () {
$ ("#navbar_edit"). Modal ({
Backdrop: ' Static '
});
}
</script>
< #include "/include/navbar_edit.html" >
<!--modal frame (Modal)--
<div class= "Modal Fade" id= "Navbar_edit" tabindex= "-1" role= "dialog"
Aria-labelledby= "Roleeditlabel" aria-hidden= "true" >
<div class= "Modal-dialog" style= "width:500px;" >
<div class= "Modal-content" >
<div class= "Modal-header" >
<button type= "button" class= "Close" data-dismiss= "modal" >×</button>
</div>
<div class= "Modal-body" >
<div style= "width:90%;" >
<form class= "Form-horizontal" id= "Navbar_pwd_reset" >
<div class= "Form-group" >
<label class= "col-sm-4 control-label" for= "old_password" > Old password:</label>
<div class= "col-sm-8" style= "padding:0" >
<input class= "col-sm-12" type= "password" id= "Old_password"
Name= "Old_password" placeholder= "Please enter old password"/>
</div>
</div>
<div class= "Form-group" >
<label class= "col-sm-4 control-label" for= "New_password" > New password:</label>
<div class= "col-sm-8" style= "padding:0" >
<input class= "col-sm-12" type= "password" id= "New_password"
Name= "New_password" placeholder= "Please enter a new password"/>
</div>
</div>
<div class= "Form-group" >
<label class= "col-sm-4 control-label" for= "Confirm_password" > Confirm New Password:</label>
<div class= "col-sm-8" style= "padding:0" >
<input class= "col-sm-12" type= "password" id= "Confirm_password"
Name= "Confirm_password" placeholder= "Confirm New password"/>
</div>
</div>
</form>
</div>
</div>
<div class= "Modal-footer" >
<button type= "button" class= "Btn btn-xs btn-default"
Data-dismiss= "modal" id= "navbar_close_btn" >
<i class= "Ace-icon fa fa-times bigger-110" ></i> <span
class= "bigger-110 No-text-shadow" > Close </span>
</button>
<button type= "button" class= "btn btn-xs btn-primary" id= "navbar_save_btn" >
<i class= "Ace-icon fa fa-floppy-o bigger-110" ></i> <span
class= "bigger-110 No-text-shadow" > Save </span>
</button>
</div>
</div>
<!--/.modal-content--
</div>
<!--/.modal--
</div>
<script type= "Text/javascript" >
$ ("#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 ("The related field is not empty, please enter!");
return false;
};
if (old_psd = = new_psd) {
Bootbox.alert ("The old password and the new password are the same, please re-enter!");
return false;
};
if (new_psd! = con_psd) {
Bootbox.alert ("Two times input new password is not the same, please re-enter!");
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 ("Server connection error, please try again later");
},
Success:function (data) {
if (Sq.isok (data)) {
Bootbox.alert ("Reset succeeded", function () {
$ ("#navbar_close_btn"). Click ();
});
} else {
Bootbox.alert ("Reset failed:" + sq.getmessage (data));
}
},
});
});
</script>
Back-end Page
public void Modifypassword () {
Basmember Sysuser = This.getloginuser ();
if (Sysuser = = NULL | | sysuser.getint (basmember.isdelete). Equals (1)) {
Render (New Jsonrender Ajaxresult (Constants.response_status_fail, "The session has expired, please sign in again!"). Forie ());
Return
}
Old Secret
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, "Old password incorrect!")). Forie ());
Return
}
New password
Password = Getpara ("New_password");
Password = commonutil.getencryptedpwd (password);
Assign value
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, "Exception on Modification")). Forie ());
}
Render (New Jsonrender (New Ajaxresult (CONSTANTS.RESPONSE_STATUS_OK, "modified successfully!")). Forie ());
}
Modal boxes invoke and change passwords using AJAX requests