const pathWithToken = location.pathname; const [,,,accessToken] = pathWithToken.split('/'); // TODO handle missing token const resetPassURL = `${location.origin}/api/patients/reset_user_password`; jQuery(document).ready(function($) { $('.change-password form').on('submit', function(e) { $('.change-password .password-err-message').hide(); e.preventDefault(); const passInputs = $('.change-password form input[type=password]'); //console.log(passInputs) const pass1 = '' + $(passInputs[0]).val(); const pass2 = '' + $(passInputs[1]).val(); //console.log(pass1, pass2); // TODO validation (min length 8, max length 64, both fields must match) if (pass1.length 64) { // console.log('bad length'); $('.change-password .password-err-message').text('Password must be at least 8 and no more than 64 characters in length').show(); return; } else if (pass1 !== pass2) { // console.log('no match'); $('.change-password .password-err-message').text('Passwords do not match. Please confirm that both are the same and try again.').show(); return; } $.ajax({ url: resetPassURL, type: 'POST', headers: { 'Authorization': accessToken }, data: { password: pass1, accessToken }, success: function(response) { window.location.replace(`${location.origin}/patient/patient-password-updated`); }, error: function(data) { // console.log('FAIL', data); $('.change-password .password-err-message').text('An unknown error has occurred, please try again. If problem persists, contact support@careconvene.com.').show(); } }); }); });