test: add a delete user form to the test client

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2021-05-14 12:01:29 -04:00
parent 2ba85533c2
commit e73f9b7bf5
2 changed files with 50 additions and 14 deletions

View File

@ -108,6 +108,26 @@ Progress: <progress id="progressbar" value="0" max="100"></progress>
</div>
</div>
<a id="do_deleteuser" rel="leanModal" name="deleteuser" href="#deleteuser" hidden>Hidden Delete</a>
<div id="deleteuser" class="user">
<div id="login-ct">
<div id="deleteuser-header" class="user-header">
<h2>Delete User</h2>
<button id="deleteuser_close" class="modal_close"></a>
</div>
<form id="deleteuser_form" class="user-form">
<div class="text-field">
<label for="deleteuser_username">Username</label>
<input id="deleteuser_username" class="good_input" name="deleteuser_username" type="text" />
</div>
<div class="button-field">
<button type="submit" class="user-button">Submit</button>
</div>
</form>
</div>
</div>
<a id="do_signup" rel="leanModal" name="signup" href="#signup" hidden>Hidden Signup</a>
<div id="signup" class="user">
<div id="signup-ct">

View File

@ -1370,20 +1370,17 @@ function logout_jwt_user() {
});
}
function delete_jwt_user(pass) {
if (!pass) {
alert("Invalid Password, Cannot Delete User");
return;
}
if (auth_token == null) {
console.log("No User Logged In")
function delete_jwt_user(user) {
if (!user) {
alert("Invalid username or password, Cannot Delete User");
return;
}
let settings = {
method: 'DELETE',
url: origin + api.user.url,
contentType: "application/json",
data: JSON.stringify({password: pass}),
data: JSON.stringify({username: user}),
dataType: 'json',
headers: {
"Authorization": `Bearer ${auth_token}`
@ -1392,16 +1389,15 @@ function delete_jwt_user(pass) {
let res = resp.result;
console.log("Delete User Response:");
console.log(res);
auth_token = null;
refresh_token = null;
window.localStorage.removeItem('refresh_token');
$('.req-login').prop('disabled', true);
$("#deleteuser_close").click()
}
}
$.ajax(settings)
.fail(() => {
console.log("Delete User Failed");
$("#deleteuser_close").click()
window.alert("Unable to delete user!")
});
}
@ -1973,8 +1969,7 @@ window.onload = () => {
});
$('#btndeluser').click(() => {
let password = window.prompt("Verify your password:")
delete_jwt_user(password);
$("#do_deleteuser").click()
});
$('#btnchangepass').click(() => {
@ -2011,6 +2006,13 @@ window.onload = () => {
closeButton: "#changepass_close"
});
$("#do_deleteuser").leanModal({
top : 200,
overlay : 0.4,
closeButton: "#deleteuser_close"
});
$("#login_close").click(() => {
//$("#login_username").val("");
$("#login_password").val("");
@ -2031,6 +2033,11 @@ window.onload = () => {
$("#nav_home").click();
});
$("#deleteuser_close").click(() => {
$("#deleteuser_username").val("");
$("#nav_home").click();
});
$("#login_form").submit((evt)=> {
let user = $("#login_username").val()
let pass = $("#login_password").val()
@ -2063,5 +2070,14 @@ window.onload = () => {
return false;
});
$("#deleteuser_form").submit((evt)=> {
let user = $("#deleteuser_username").val()
if (user != "")
delete_jwt_user(user);
else
alert("Invalid username/password");
return false;
});
check_authorization();
};