From 75053ef01a4ba04008ae36fe5c7d5343ba28ba0f Mon Sep 17 00:00:00 2001 From: Maria Rice Date: Tue, 9 Jan 2018 12:24:32 -0600 Subject: [PATCH] successful check on number of characters in password added --- .../js/panelHandlers/users/new_password.js | 51 ++++++++++--------- .../js/panelHandlers/users/new_password.js | 44 +++++++++------- 2 files changed, 53 insertions(+), 42 deletions(-) diff --git a/account/assets/js/panelHandlers/users/new_password.js b/account/assets/js/panelHandlers/users/new_password.js index 391c545..fc49e45 100644 --- a/account/assets/js/panelHandlers/users/new_password.js +++ b/account/assets/js/panelHandlers/users/new_password.js @@ -33,42 +33,47 @@ jQuery('._js_back-to-user-management').on('click', function(e){ jQuery('._js_update-password-form').on('submit', function(e){ e.preventDefault(); - if((newPassword && newPassword.val()) && (newPasswordRetype && newPasswordRetype.val()) && (newPasswordUsername && newPasswordUsername.val())) { - if(newPassword.val() == newPasswordRetype.val()) { - var ensure = confirm("Are you sure you want to change the password of user \"" + newPasswordUsername.val() + "\"?"); - if(ensure) { - var requestData = {}; - requestData["user"] = newPasswordUsername.val(); - requestData["pass"] = newPassword.val(); + if(newPassword.length >= 8) { + if((newPassword && newPassword.val()) && (newPasswordRetype && newPasswordRetype.val()) && (newPasswordUsername && newPasswordUsername.val())) { + if(newPassword.val() == newPasswordRetype.val()) { + var ensure = confirm("Are you sure you want to change the password of user \"" + newPasswordUsername.val() + "\"?"); + if(ensure) { + var requestData = {}; + requestData["user"] = newPasswordUsername.val(); + requestData["pass"] = newPassword.val(); - var xhr = new XMLHttpRequest(); - xhr.open(jQuery(this).attr('method'), jQuery(this).attr('action'), true); - xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); - xhr.send(JSON.stringify(requestData)); + var xhr = new XMLHttpRequest(); + xhr.open(jQuery(this).attr('method'), jQuery(this).attr('action'), true); + xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); + xhr.send(JSON.stringify(requestData)); - xhr.onloadend = function() { - if(xhr.status == 204) { - alert("Password successfully updated."); - newPassModal.modal('hide'); - userModal.modal('show'); - } - else { - if(xhr.response != undefined && xhr.response.length != 0) { - alert('Error: ' + xhr.response); + xhr.onloadend = function() { + if(xhr.status == 204) { + alert("Password successfully updated."); + newPassModal.modal('hide'); + userModal.modal('show'); } else { - alert('An error has occurred, refresh and try again. If problem persists please contact your administrator.'); + if(xhr.response != undefined && xhr.response.length != 0) { + alert('Error: ' + xhr.response); + } + else { + alert('An error has occurred, refresh and try again. If problem persists please contact your administrator.'); + } } } } } + else { + alert("Passwords must match."); + } } else { - alert("Passwords must match."); + alert("All fields need to be filled out"); } } else { - alert("All fields need to be filled out"); + alert("Password must be at least 8 characters"); } }); diff --git a/server/document_root/assets/js/panelHandlers/users/new_password.js b/server/document_root/assets/js/panelHandlers/users/new_password.js index 391c545..af8e909 100644 --- a/server/document_root/assets/js/panelHandlers/users/new_password.js +++ b/server/document_root/assets/js/panelHandlers/users/new_password.js @@ -35,32 +35,38 @@ jQuery('._js_update-password-form').on('submit', function(e){ if((newPassword && newPassword.val()) && (newPasswordRetype && newPasswordRetype.val()) && (newPasswordUsername && newPasswordUsername.val())) { if(newPassword.val() == newPasswordRetype.val()) { - var ensure = confirm("Are you sure you want to change the password of user \"" + newPasswordUsername.val() + "\"?"); - if(ensure) { - var requestData = {}; - requestData["user"] = newPasswordUsername.val(); - requestData["pass"] = newPassword.val(); + if (newPassword.val().length >= 8) { + var ensure = confirm("Are you sure you want to change the password of user \"" + newPasswordUsername.val() + "\"?"); + if(ensure) { + var requestData = {}; + requestData["user"] = newPasswordUsername.val(); + requestData["pass"] = newPassword.val(); - var xhr = new XMLHttpRequest(); - xhr.open(jQuery(this).attr('method'), jQuery(this).attr('action'), true); - xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); - xhr.send(JSON.stringify(requestData)); + var xhr = new XMLHttpRequest(); + xhr.open(jQuery(this).attr('method'), jQuery(this).attr('action'), true); + xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); + xhr.send(JSON.stringify(requestData)); - xhr.onloadend = function() { - if(xhr.status == 204) { - alert("Password successfully updated."); - newPassModal.modal('hide'); - userModal.modal('show'); - } - else { - if(xhr.response != undefined && xhr.response.length != 0) { - alert('Error: ' + xhr.response); + xhr.onloadend = function() { + if(xhr.status == 204) { + alert("Password successfully updated."); + newPassModal.modal('hide'); + userModal.modal('show'); } else { - alert('An error has occurred, refresh and try again. If problem persists please contact your administrator.'); + if(xhr.response != undefined && xhr.response.length != 0) { + alert('Error: ' + xhr.response); + } + else { + alert('An error has occurred, refresh and try again. If problem persists please contact your administrator.'); + } } } } + } + else { + console.log(newPassword.val()); + alert("Password must be at least 8 characters"); } } else {