mirror of
https://github.com/donl/gPanel.git
synced 2026-05-25 22:06:55 -06:00
add/remove/update users for account panel works
This commit is contained in:
parent
1037177cec
commit
02bdff7bb6
6 changed files with 406 additions and 0 deletions
33
account/assets/js/panelHandlers/users/delete.js
Normal file
33
account/assets/js/panelHandlers/users/delete.js
Normal file
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
86
account/assets/js/panelHandlers/users/new.js
Normal file
86
account/assets/js/panelHandlers/users/new.js
Normal file
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
107
account/assets/js/panelHandlers/users/new_password.js
Normal file
107
account/assets/js/panelHandlers/users/new_password.js
Normal file
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
50
account/assets/js/panelHandlers/users/open.js
Normal file
50
account/assets/js/panelHandlers/users/open.js
Normal file
|
|
@ -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('<div class="row mt-2"><div class="col-6 d-flex align-items-center"><p class="mb-0">'+v+'</p></div><div class="col-6 d-flex justify-content-end"><div class="btn-group" role="group"><button class="btn btn-outline-primary _js_user-management-new-password" data="'+v+'">New Password</button><button class="btn btn-outline-danger _js_user-management-delete" data="'+v+'">Delete</button></div></div></div>');
|
||||
});
|
||||
}
|
||||
else {
|
||||
display.html('<p>An error has occurred, please refresh. If problem persists please contact your administrator.</p>');
|
||||
}
|
||||
}
|
||||
else if(xhr.status == 204) {
|
||||
if(xhr.response != undefined && xhr.response.length != 0) {
|
||||
display.html('<p>There are no users in the server. This is a problem, this shouldn\'t be like this.</p>');
|
||||
}
|
||||
else {
|
||||
display.html('<p>An error has occurred, please refresh. If problem persists please contact your administrator.</p>');
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(xhr.response != undefined && xhr.response.length != 0) {
|
||||
display.html('<p>Error: ' + xhr.response + '</p>');
|
||||
}
|
||||
else {
|
||||
display.html('<p>An error has occurred, please refresh. If problem persists please contact your administrator.</p>');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -80,6 +80,111 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<!-- User Management Modal -->
|
||||
<div class="modal fade user-management-modal" tabindex="-1" role="dialog" aria-labelledby="user-management-modal" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Manage Server Users</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<h4>Add User</h4>
|
||||
<form class="_js_add-user-form" action="api/user/register" method="POST">
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="addUserUsername">Username</label>
|
||||
<div class="input-group mb-2">
|
||||
<div class="input-group-addon"><i class="fa fa-user" aria-hidden="true"></i></div>
|
||||
<input name="user" type="text" class="form-control" id="addUserUsername" placeholder="Username">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="addUserPassword">Password</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon"><i class="fa fa-key" aria-hidden="true"></i></div>
|
||||
<input name="pass" type="password" class="form-control" id="addUserPassword" placeholder="Password">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="addUserPasswordRetype">Re-type Password</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon"><i class="fa fa-key" aria-hidden="true"></i></div>
|
||||
<input name="pass" type="password" class="form-control" id="addUserPasswordRetype" placeholder="Re-type Password">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<label class="form-check-label">
|
||||
<input type="checkbox" class="form-check-input _js_user-management-show-password">
|
||||
Show Password
|
||||
</label>
|
||||
</div>
|
||||
<div class="btn-group" role="group">
|
||||
<button type="submit" class="btn btn-primary">Add User</button>
|
||||
<button type="button" class="btn btn-success _js_add-user-generate-password">Generate Strong Password</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h4 class="mt-3 mb-0">Current Users</h4>
|
||||
<div class="container-full _js_current-users">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- New Pass Modal -->
|
||||
<div class="modal fade new-pass-modal" tabindex="-1" role="dialog" aria-labelledby="new-pass-modal" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="_js_update-password-form" action="api/user/update_password" method="UPDATE">
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="updatePassword">New Password</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon"><i class="fa fa-key" aria-hidden="true"></i></div>
|
||||
<input name="pass" type="password" class="form-control" id="updatePassword" placeholder="Password">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="updatePasswordRetype">Re-type New Password</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon"><i class="fa fa-key" aria-hidden="true"></i></div>
|
||||
<input name="pass" type="password" class="form-control" id="updatePasswordRetype" placeholder="Re-type Password">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<label class="form-check-label">
|
||||
<input type="checkbox" class="form-check-input _js_update-password-show-password">
|
||||
Show Password
|
||||
</label>
|
||||
</div>
|
||||
<div class="btn-group" role="group">
|
||||
<button type="submit" class="btn btn-primary">Update Password</button>
|
||||
<button type="button" class="btn btn-success _js_update-password-generate-password">Generate Strong Password</button>
|
||||
</div>
|
||||
<input type="hidden" value="" id="updatePasswordUsername">
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
<button type="button" class="btn btn-warning _js_back-to-user-management">Back to User Mangement</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
|
|
@ -154,6 +259,20 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-5">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">Account Users</h4>
|
||||
<h6 class="card-subtitle mb-4 text-muted">View, edit, update, and remove users that can access this gPanel Account</h6>
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn btn-outline-primary _js_manage-users">Manage Users</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="sticky-footer">
|
||||
|
|
@ -189,6 +308,11 @@
|
|||
<script type="text/javascript" src="assets/js/panelHandlers/security/ip_list.js"></script>
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/security/filter_ip.js"></script>
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/security/unfilter_ip.js"></script>
|
||||
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/users/open.js"></script>
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/users/new.js"></script>
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/users/delete.js"></script>
|
||||
<script type="text/javascript" src="assets/js/panelHandlers/users/new_password.js"></script>
|
||||
<!-- KEEP AT BOTTOM OF BODY TAGS -->
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -29,6 +29,12 @@ func (con *Controller) apiHandler(res http.ResponseWriter, req *http.Request) (b
|
|||
return true, user.Register(res, req, con.APILogger, con.Directory)
|
||||
case "/user/logout":
|
||||
return true, user.Logout(res, req, con.APILogger, con.Directory)
|
||||
case "/user/list":
|
||||
return true, user.List(res, req, con.APILogger, con.Directory)
|
||||
case "/user/delete":
|
||||
return true, user.Delete(res, req, con.APILogger, con.Directory)
|
||||
case "/user/update_password":
|
||||
return true, user.UpdatePassword(res, req, con.APILogger, con.Directory)
|
||||
case "/server/status":
|
||||
return true, server.Status(res, req, con.APILogger, con.Public)
|
||||
case "/server/start":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue