167 lines
6.5 KiB
HTML
167 lines
6.5 KiB
HTML
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>Video2Document API key management system</title>
|
|
<script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=" crossorigin="anonymous"></script>
|
|
</head>
|
|
<body>
|
|
<div id="login-form">
|
|
<table>
|
|
<th></th>
|
|
<tr>
|
|
<td>
|
|
<label>Password <input id="input-password" type="password" value="SleepDeprivationIsFunUwU"></label>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<button id="btn-login">Login</button>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
|
|
<div id="admin-interface" style="display:none;">
|
|
<button id="btn-add-user">Add User</button>
|
|
<table id="tbl-users">
|
|
<th></th>
|
|
</table>
|
|
<button id="btn-add-api-key">Add API key</button>
|
|
<table id="tbl-api-keys">
|
|
<th></th>
|
|
</table>
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
|
$(document).ready(()=>{
|
|
deleteUser = function(){
|
|
let identifier = event.target.id
|
|
|
|
$.ajax({
|
|
url: "./v1/user",
|
|
type: "delete",
|
|
headers: {"key": adminAuth},
|
|
data: JSON.stringify({username:identifier}),
|
|
success: function(resp) {
|
|
alert("User deleted")
|
|
loadTables()
|
|
},
|
|
error: function(resp){
|
|
alert(JSON.parse(resp.responseText).response)
|
|
}
|
|
});
|
|
}
|
|
deleteApiKey = function(){
|
|
let identifier = event.target.id
|
|
|
|
$.ajax({
|
|
url: "./v1/api-key",
|
|
type: "delete",
|
|
headers: {"key": adminAuth},
|
|
data: JSON.stringify({field:identifier}),
|
|
success: function(resp) {
|
|
alert("API Key deleted")
|
|
loadTables()
|
|
},
|
|
error: function(resp){
|
|
alert(JSON.parse(resp.responseText).response)
|
|
}
|
|
});
|
|
}
|
|
let adminAuth
|
|
$("#btn-login").on("click", e => {
|
|
let password = $("#input-password").val()
|
|
// $.get("./v1/admin-auth")
|
|
$.ajax({
|
|
url: "./v1/admin-auth",
|
|
headers: {"password": password},
|
|
success: function(resp) {
|
|
adminAuth = resp.auth
|
|
$("#login-form").hide()
|
|
$("#admin-interface").show()
|
|
loadTables()
|
|
},
|
|
error: function(resp){
|
|
alert(JSON.parse(resp.responseText).response)
|
|
}
|
|
});
|
|
})
|
|
|
|
function loadTables(){
|
|
$("#tbl-api-keys").html("")
|
|
$("#tbl-users").html("")
|
|
$.ajax({
|
|
url: "./v1/api-key",
|
|
headers: {"key": adminAuth},
|
|
success: function(resp) {
|
|
Object.keys(resp).forEach(el => {
|
|
console.log(el);
|
|
|
|
$("#tbl-api-keys").append(`<tr><td>${el}</td><td>${resp[el]}</td><td><button onclick="deleteApiKey()" id="${el}">Delete API key</button></td></tr>`)
|
|
})
|
|
},
|
|
error: function(resp){
|
|
alert(JSON.parse(resp.responseText).response)
|
|
}
|
|
});
|
|
$.ajax({
|
|
url: "./v1/user",
|
|
headers: {"key": adminAuth},
|
|
success: function(resp) {
|
|
Object.keys(resp).forEach(el => {
|
|
console.log(el);
|
|
|
|
$("#tbl-users").append(`<tr><td>${el}</td><td><button onclick="deleteUser()" id="${el}">Delete user</button></td></tr>`)
|
|
})
|
|
},
|
|
error: function(resp){
|
|
alert(JSON.parse(resp.responseText).response)
|
|
}
|
|
});
|
|
|
|
|
|
$("#btn-add-user").on("click", e => {
|
|
let username = prompt("Username")
|
|
let password = prompt("password")
|
|
$.ajax({
|
|
url: "./v1/user",
|
|
type: "put",
|
|
headers: {"key": adminAuth},
|
|
data: JSON.stringify({username:username, password:password}),
|
|
success: function(resp) {
|
|
alert("User Created")
|
|
loadTables()
|
|
},
|
|
error: function(resp){
|
|
alert(JSON.parse(resp.responseText).response)
|
|
}
|
|
});
|
|
})
|
|
$("#btn-add-api-key").on("click", e => {
|
|
let field = prompt("API Key name")
|
|
let value = prompt("API Key value")
|
|
$.ajax({
|
|
url: "./v1/api-key",
|
|
type: "put",
|
|
headers: {"key": adminAuth},
|
|
data: JSON.stringify({field:field, value:value}),
|
|
success: function(resp) {
|
|
alert("API Key Created")
|
|
loadTables()
|
|
},
|
|
error: function(resp){
|
|
alert(JSON.parse(resp.responseText).response)
|
|
}
|
|
});
|
|
})
|
|
|
|
|
|
}
|
|
})
|
|
</script>
|
|
|
|
</body>
|
|
</html> |