diff --git a/account/assets/js/panelHandlers/users/delete.js b/account/assets/js/panelHandlers/users/delete.js new file mode 100644 index 0000000..e7f9c47 --- /dev/null +++ b/account/assets/js/panelHandlers/users/delete.js @@ -0,0 +1,33 @@ +jQuery(document).on('click', '._js_user-management-delete', function(e){ + e.preventDefault(); + + if(!jQuery(this).attr('data') || jQuery(this).attr('data') == "") { + alert("An error has occurred, please refresh and try again. If problem persists please contact your administrator."); + return; + } + + var ensure = confirm('Are you sure you want to delete the user "' + jQuery(this).attr('data') + '"?'); + if(ensure) { + var requestData = {}; + requestData["user"] = jQuery(this).attr('data'); + + var xhr = new XMLHttpRequest(); + xhr.open('UPDATE', 'api/user/delete', true); + xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); + xhr.send(JSON.stringify(requestData)); + + xhr.onloadend = function() { + if(xhr.status == 204) { + listCurrentUsers(); + } + else { + if(xhr.response != undefined && xhr.response.length != 0) { + alert('Error: ' + xhr.response); + } + else { + alert("An error has occurred, please refresh and try again. If problem persists please contact your administrator."); + } + } + } + } +}); diff --git a/account/assets/js/panelHandlers/users/new.js b/account/assets/js/panelHandlers/users/new.js new file mode 100644 index 0000000..0ff0580 --- /dev/null +++ b/account/assets/js/panelHandlers/users/new.js @@ -0,0 +1,86 @@ +var userModal = jQuery('.user-management-modal'); + +var usernameInput = jQuery('#addUserUsername'); +var passwordInput = jQuery('#addUserPassword'); +var passwordInputRetype = jQuery('#addUserPasswordRetype'); + +jQuery('._js_add-user-form').on('submit', function(e){ + e.preventDefault(); + + if((usernameInput && usernameInput.val()) && (passwordInput && passwordInput.val()) && (passwordInputRetype && passwordInputRetype.val())) { + if(passwordInput.val() == passwordInputRetype.val()) { + var requestData = {}; + requestData["user"] = usernameInput.val(); + requestData["pass"] = passwordInput.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)); + + xhr.onloadend = function() { + if(xhr.status == 204) { + listCurrentUsers(); + } + else { + 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('Password fields do not match.'); + } + } + else { + alert('All fields must contain values.'); + } +}); + +jQuery('._js_add-user-generate-password').on('click', function(e){ + e.preventDefault(); + + var genpass = generatePassword(); + + toggleShowPassword(true); + passwordInput.prop('value', genpass); + passwordInputRetype.prop('value', genpass); +}); + +function generatePassword() { + var gen = ""; + var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-[]:;<>?"; + + for (var i = 0; i < 32; i++) { + gen += chars.charAt(Math.floor(Math.random() * chars.length)); + } + return gen +} + +jQuery('._js_user-management-show-password').on('change', function(e){ + e.preventDefault(); + + if(this.checked) { + toggleShowPassword(true); + } + else { + toggleShowPassword(false); + } +}); + +function toggleShowPassword(show) { + if(show) { + jQuery('._js_user-management-show-password').prop('checked', true); + passwordInput.attr('type', 'text'); + passwordInputRetype.attr('type', 'text'); + } + else { + jQuery('._js_user-management-show-password').prop('checked', false); + passwordInput.attr('type', 'password'); + passwordInputRetype.attr('type', 'password'); + } +} diff --git a/account/assets/js/panelHandlers/users/new_password.js b/account/assets/js/panelHandlers/users/new_password.js new file mode 100644 index 0000000..391c545 --- /dev/null +++ b/account/assets/js/panelHandlers/users/new_password.js @@ -0,0 +1,107 @@ +var userModal = jQuery('.user-management-modal'); +var newPassModal = jQuery('.new-pass-modal'); + +var newPassword = jQuery('#updatePassword'); +var newPasswordRetype = jQuery('#updatePasswordRetype'); +var newPasswordUsername = jQuery('#updatePasswordUsername'); + +jQuery(document).on('click', '._js_user-management-new-password', function(e){ + e.preventDefault(); + + if(!jQuery(this).attr('data') || jQuery(this).attr('data') == "") { + alert("An error has occurred, please refresh and try again. If problem persists please contact your administrator."); + return; + } + + var username = jQuery(this).attr('data'); + newPasswordUsername.attr('value', username); + + newPassModal.find('.modal-title').html('Changing password for "'+username+'"'); + toggleShowPasswordNewPassword(false); + + userModal.modal('hide'); + newPassModal.modal('show'); +}); + +jQuery('._js_back-to-user-management').on('click', function(e){ + e.preventDefault(); + + newPassModal.modal('hide'); + userModal.modal('show'); +}); + +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(); + + 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); + } + else { + alert('An error has occurred, refresh and try again. If problem persists please contact your administrator.'); + } + } + } + } + } + else { + alert("Passwords must match."); + } + } + else { + alert("All fields need to be filled out"); + } +}); + +jQuery('._js_update-password-show-password').on('change', function(e){ + e.preventDefault(); + + if(this.checked) { + toggleShowPasswordNewPassword(true); + } + else { + toggleShowPasswordNewPassword(false); + } +}); + +jQuery('._js_update-password-generate-password').on('click', function(e){ + e.preventDefault(); + + var genpass = generatePassword(); + + toggleShowPasswordNewPassword(true); + newPassword.prop('value', genpass); + newPasswordRetype.prop('value', genpass); +}); + +function toggleShowPasswordNewPassword(show) { + if(show) { + jQuery('._js_update-password-show-password').prop('checked', true); + newPassword.attr('type', 'text'); + newPasswordRetype.attr('type', 'text'); + } + else { + jQuery('._js_update-password-show-password').prop('checked', false); + newPassword.attr('type', 'password'); + newPasswordRetype.attr('type', 'password'); + } +} diff --git a/account/assets/js/panelHandlers/users/open.js b/account/assets/js/panelHandlers/users/open.js new file mode 100644 index 0000000..df75bc4 --- /dev/null +++ b/account/assets/js/panelHandlers/users/open.js @@ -0,0 +1,50 @@ +var userModal = jQuery('.user-management-modal'); + +jQuery('._js_manage-users').on('click', function(e){ + e.preventDefault(); + + jQuery('._js_user-management-show-password').prop('checked', false); + + listCurrentUsers(); + userModal.modal('show'); +}); + +function listCurrentUsers() { + var display = jQuery('._js_current-users'); + display.html(''); + var requestData = {}; + + var xhr = new XMLHttpRequest(); + xhr.open('GET', 'api/user/list', true); + xhr.send(); + + xhr.onloadend = function() { + if(xhr.status == 200) { + if(xhr.response != undefined && xhr.response.length != 0) { + jsonResponse = JSON.parse(xhr.response) + jQuery.each(jsonResponse, function(k, v) { + display.append('

'+v+'

'); + }); + } + else { + display.html('

An error has occurred, please refresh. If problem persists please contact your administrator.

'); + } + } + else if(xhr.status == 204) { + if(xhr.response != undefined && xhr.response.length != 0) { + display.html('

There are no users in the server. This is a problem, this shouldn\'t be like this.

'); + } + else { + display.html('

An error has occurred, please refresh. If problem persists please contact your administrator.

'); + } + } + else { + if(xhr.response != undefined && xhr.response.length != 0) { + display.html('

Error: ' + xhr.response + '

'); + } + else { + display.html('

An error has occurred, please refresh. If problem persists please contact your administrator.

'); + } + } + } +} diff --git a/account/gPanel.html b/account/gPanel.html index b01afff..58c21ca 100644 --- a/account/gPanel.html +++ b/account/gPanel.html @@ -80,6 +80,111 @@ + + + + + +
@@ -154,6 +259,20 @@
+ +
+
+
+
+

Account Users

+
View, edit, update, and remove users that can access this gPanel Account
+
+ +
+
+
+
+