add admin page,
move requestTicket and deleteAllCookies to login.js, update to new auth paths
This commit is contained in:
@@ -131,7 +131,7 @@ function handlePasswordChangeForm () {
|
||||
`;
|
||||
const d = dialog("Change Password", body, async (result, form) => {
|
||||
if (result === "confirm") {
|
||||
const result = await requestAPI("/auth/password", "POST", { password: form.get("new-password") });
|
||||
const result = await requestAPI("/access/password", "POST", { password: form.get("new-password") });
|
||||
if (result.status !== 200) {
|
||||
alert(result.error);
|
||||
}
|
||||
|
8
scripts/admin.js
Normal file
8
scripts/admin.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import { setTitleAndHeader, setAppearance } from "./utils.js";
|
||||
|
||||
window.addEventListener("DOMContentLoaded", init);
|
||||
|
||||
function init () {
|
||||
setAppearance();
|
||||
setTitleAndHeader();
|
||||
}
|
@@ -1,12 +1,12 @@
|
||||
import { requestTicket, goToPage, deleteAllCookies, requestPVE, setTitleAndHeader, setAppearance } from "./utils.js";
|
||||
import { goToPage, requestPVE, setTitleAndHeader, setAppearance, requestAPI } from "./utils.js";
|
||||
import { alert } from "./dialog.js";
|
||||
|
||||
window.addEventListener("DOMContentLoaded", init);
|
||||
|
||||
async function init () {
|
||||
await deleteAllCookies();
|
||||
setAppearance();
|
||||
setTitleAndHeader();
|
||||
await deleteAllCookies();
|
||||
const formSubmitButton = document.querySelector("#submit");
|
||||
const realms = await requestPVE("/access/domains", "GET");
|
||||
const realmSelect = document.querySelector("#realm");
|
||||
@@ -42,3 +42,12 @@ async function init () {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function requestTicket (username, password, realm) {
|
||||
const response = await requestAPI("/access/ticket", "POST", { username: `${username}@${realm}`, password }, false);
|
||||
return response;
|
||||
}
|
||||
|
||||
async function deleteAllCookies () {
|
||||
await requestAPI("/access/ticket", "DELETE");
|
||||
}
|
||||
|
@@ -161,11 +161,6 @@ export function getCookie (cname) {
|
||||
return "";
|
||||
}
|
||||
|
||||
export async function requestTicket (username, password, realm) {
|
||||
const response = await requestAPI("/auth/ticket", "POST", { username: `${username}@${realm}`, password }, false);
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function requestPVE (path, method, body = null) {
|
||||
const prms = new URLSearchParams(body);
|
||||
const content = {
|
||||
@@ -259,13 +254,18 @@ export function getURIData () {
|
||||
return Object.fromEntries(url.searchParams);
|
||||
}
|
||||
|
||||
export async function deleteAllCookies () {
|
||||
await requestAPI("/auth/ticket", "DELETE");
|
||||
}
|
||||
|
||||
export function setTitleAndHeader () {
|
||||
export async function setTitleAndHeader () {
|
||||
document.title = `${organization} - dashboard`;
|
||||
document.querySelector("h1").innerText = organization;
|
||||
if (getCookie("auth") === "1") {
|
||||
const userIsAdmin = (await requestAPI("/user/config/cluster")).admin;
|
||||
if (userIsAdmin) {
|
||||
const adminNavLink = document.querySelector("#navigation #admin-link");
|
||||
adminNavLink.href = "admin.html";
|
||||
adminNavLink.classList.remove("none");
|
||||
adminNavLink.ariaDisabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const settingsDefault = {
|
||||
|
Reference in New Issue
Block a user