// =============== // Change Password // =============== $(document).ready(function () { var $application = $("#APPLICATION_MNEMONIC").val(), $sessionStorage = JSON.parse(sessionStorage.getItem($application) || "{}"); // ----------- // Save Button // ----------- $(".btnSave").on("click", function (e) { e.preventDefault(); $("#changePassword").submit(); }); // -------------- // Cancel Button. // -------------- $(".btnCancel").on("click", function () { formSubmit({action: $sessionStorage.addUser}); }); // --------------- // Validate Inputs // --------------- $("#changePassword").submit(function (e) { var user_new_password = $("#user_new_password"), user_verify_password = $("#user_verify_password"); clearInputErrors(); if (isBlank(user_new_password)) { createInputError(user_new_password, "New password is required"); return false; } if (isBlank(user_verify_password)) { createInputError(user_verify_password, "Type password again"); return false; } if (user_new_password.val() !== user_verify_password.val()) { createInputError(user_verify_password, "Password do not match."); return false; } e.preventDefault(); $.post("main.php", $(this).serialize()) .done(function () { window.location.assign('main.php'); }) .fail(function (response) { createInputError(user_verify_password, response.status === 422 ? 'Enter a nonempty password and matching confirmation.' : 'Unable to change your password. Reload the page and try again.'); }); }); });