test: add a delete user form to the test client
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
2ba85533c2
commit
e73f9b7bf5
|
@ -108,6 +108,26 @@ Progress: <progress id="progressbar" value="0" max="100"></progress>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
<a id="do_signup" rel="leanModal" name="signup" href="#signup" hidden>Hidden Signup</a>
|
||||||
<div id="signup" class="user">
|
<div id="signup" class="user">
|
||||||
<div id="signup-ct">
|
<div id="signup-ct">
|
||||||
|
|
|
@ -1370,20 +1370,17 @@ function logout_jwt_user() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_jwt_user(pass) {
|
function delete_jwt_user(user) {
|
||||||
if (!pass) {
|
if (!user) {
|
||||||
alert("Invalid Password, Cannot Delete User");
|
alert("Invalid username or password, Cannot Delete User");
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (auth_token == null) {
|
|
||||||
console.log("No User Logged In")
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let settings = {
|
let settings = {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
url: origin + api.user.url,
|
url: origin + api.user.url,
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
data: JSON.stringify({password: pass}),
|
data: JSON.stringify({username: user}),
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": `Bearer ${auth_token}`
|
"Authorization": `Bearer ${auth_token}`
|
||||||
|
@ -1392,16 +1389,15 @@ function delete_jwt_user(pass) {
|
||||||
let res = resp.result;
|
let res = resp.result;
|
||||||
console.log("Delete User Response:");
|
console.log("Delete User Response:");
|
||||||
console.log(res);
|
console.log(res);
|
||||||
auth_token = null;
|
$("#deleteuser_close").click()
|
||||||
refresh_token = null;
|
|
||||||
window.localStorage.removeItem('refresh_token');
|
|
||||||
$('.req-login').prop('disabled', true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax(settings)
|
$.ajax(settings)
|
||||||
.fail(() => {
|
.fail(() => {
|
||||||
console.log("Delete User Failed");
|
console.log("Delete User Failed");
|
||||||
|
$("#deleteuser_close").click()
|
||||||
|
window.alert("Unable to delete user!")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1973,8 +1969,7 @@ window.onload = () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#btndeluser').click(() => {
|
$('#btndeluser').click(() => {
|
||||||
let password = window.prompt("Verify your password:")
|
$("#do_deleteuser").click()
|
||||||
delete_jwt_user(password);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#btnchangepass').click(() => {
|
$('#btnchangepass').click(() => {
|
||||||
|
@ -2011,6 +2006,13 @@ window.onload = () => {
|
||||||
closeButton: "#changepass_close"
|
closeButton: "#changepass_close"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#do_deleteuser").leanModal({
|
||||||
|
top : 200,
|
||||||
|
overlay : 0.4,
|
||||||
|
closeButton: "#deleteuser_close"
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$("#login_close").click(() => {
|
$("#login_close").click(() => {
|
||||||
//$("#login_username").val("");
|
//$("#login_username").val("");
|
||||||
$("#login_password").val("");
|
$("#login_password").val("");
|
||||||
|
@ -2031,6 +2033,11 @@ window.onload = () => {
|
||||||
$("#nav_home").click();
|
$("#nav_home").click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#deleteuser_close").click(() => {
|
||||||
|
$("#deleteuser_username").val("");
|
||||||
|
$("#nav_home").click();
|
||||||
|
});
|
||||||
|
|
||||||
$("#login_form").submit((evt)=> {
|
$("#login_form").submit((evt)=> {
|
||||||
let user = $("#login_username").val()
|
let user = $("#login_username").val()
|
||||||
let pass = $("#login_password").val()
|
let pass = $("#login_password").val()
|
||||||
|
@ -2063,5 +2070,14 @@ window.onload = () => {
|
||||||
return false;
|
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();
|
check_authorization();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue