var baseUrl = 'https://citizenstatus.com';
(function($) {
/* Available for ajax functions */
/* Change Password Ajax save */
$("#changePass").on('submit', function(e) {
e.preventDefault();
var password = $('#password').val();
var userID = $('#user_id').val();
var csrf = $('#csrf_token').val();
var submitTo = baseUrl + '/changepass';
$.ajax({
type: "POST",
dataType: 'json',
url: submitTo,
data: {
type : 'changePassword',
password: password,
userID : userID,
csrf : csrf
},
success: function(response) {
if (response.changed == 'ok') {
$('#password').val('');
bootstrap.Modal.getInstance(document.getElementById("createmodal")).hide();
$('.message').html("
"
+ "Password Updated! "
+ " "
+ "
");
} else {
$('.msg').removeClass('d-none');
//alert(response.msg);
}
}
});
});
/* Save User Form Ajax */
$("#userForm").on('submit', function(e) {
e.preventDefault();
var firstName = $('#firstName').val();
var lastName = $('#lastName').val();
var roles = $('#roles option:selected').val();
var email = $('#email').val();
var siteName = $('#siteName').val();
var apiToken = $('#apiToken').val();
var editApiToken = $('#editApiToken').val();
//var sendGridFromName = $('#sendGridFromName').val();
//var sendGridFromEmail = $('#sendGridFromEmail').val();
//var successEmailSubject = $('#successEmailSubject').val();
//var sendGridApiToken = $('#sendGridApiToken').val();
//var successEmailTemplate = tinyMCE.get('successEmailTemplate').getContent();
//var errorEmailAddress = $('#errorEmailAddress').val();
//var errorEmailSubject = $('#errorEmailSubject').val();
//var errorEmailTemplate = tinyMCE.get('errorEmailTemplate').getContent();
var submitTo = baseUrl + '/saveuser';
var csrf = $('#_csrf_token').val();
var userID = $('#userID').val();
$.ajax({
type: "POST",
dataType: 'json',
url: submitTo,
data: {
type: 'saveUser',
userID: userID,
firstName: firstName,
lastName: lastName,
roles: roles,
email: email,
siteName: siteName,
apiToken: apiToken,
editApiToken: editApiToken,
//sendGridFromName: sendGridFromName,
//sendGridFromEmail: sendGridFromEmail,
//successEmailSubject: successEmailSubject,
//sendGridApiToken: sendGridApiToken,
//successEmailTemplate: successEmailTemplate,
//errorEmailAddress: errorEmailAddress,
//errorEmailSubject: errorEmailSubject,
//errorEmailTemplate: errorEmailTemplate,
csrf : csrf
},
success: function(response) {
if (response.success == true) {
$('.saveStatus').html(""
+ "User Saved! "
+ " "
+ "
");
if (response.db == 'insert') {
setTimeout(function(){ window.location = "https://citizenstatus.com"; }, 2000);
}
} else {
$('.msg').removeClass('d-none');
//alert(response.msg);
}
}
});
});
/* Delete User */
$(".delUser").on('click', function(e) {
e.preventDefault();
var userID = $('#del_user_id').val();
var csrf = $('#del_csrf_token').val();
var submitTo = baseUrl + '/deluser';
$.ajax({
type: "POST",
dataType: 'json',
url: submitTo,
data: {
type : 'deleteUser',
userID : userID,
csrf : csrf
},
success: function(response) {
if (response.success == true) {
bootstrap.Modal.getInstance(document.getElementById("deleteUserModal")).hide();
$('.saveStatus').html(""
+ "User Deleted! "
+ " "
+ "
");
setTimeout(function(){ window.location = "https://citizenstatus.com"; }, 2000);
} else {
alert('There was a problem, please try again.');
}
}
});
});
/* Decrypt File */
/* Putting on hold for now as this doesn't appear to be in use, also Hallite is giving a
* error: Uncaught ParagonIE\Halite\Alerts\InvalidMessage: Invalid message authentication code
* so we'll revisit if needed and troubleshoot more.
*/
$("#submitDecrypt").on('click', function(e) {
e.preventDefault();
var secretID = $('#secret').val();
var csrf = $('#decrypt_csrf_token').val();
var submitTo = baseUrl + '/doDecryptPDF';
let decryptPDFForm = document.getElementById("decryptPDFForm");
var formData = new FormData(decryptPDFForm);
$.ajax({
type : "POST",
url : submitTo,
data : formData,
contentType : false,
processData : false,
cache : false,
success : function(response) {
if (response.success == true) {
$('.saveStatus').html(""
+ "User Deleted! "
+ " "
+ "
");
setTimeout(function(){ window.location = "https://citizenstatus.com"; }, 2000);
} else {
alert('There was a problem, please try again.');
}
}
});
});
})(jQuery);