add get user/group,
invert return value for CookieFetcher
This commit is contained in:
parent
783bc37c94
commit
c059b528fa
@ -110,6 +110,7 @@ export default class LocalDB extends DB_BACKEND {
|
|||||||
getAllGroups (params) {
|
getAllGroups (params) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
setGroup (group, attributes, params) {}
|
setGroup (group, attributes, params) {}
|
||||||
delGroup (group, params) {}
|
delGroup (group, params) {}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ export const router = Router({ mergeParams: true }); ;
|
|||||||
|
|
||||||
const checkAuth = global.utils.checkAuth;
|
const checkAuth = global.utils.checkAuth;
|
||||||
|
|
||||||
global.utils.recursiveImportRoutes(router, "/access", "access", import.meta.url);
|
global.utils.recursiveImportRoutes(router, "", "access", import.meta.url);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET - check authentication
|
* GET - check authentication
|
||||||
@ -30,7 +30,7 @@ class CookieFetcher {
|
|||||||
if (this.#fetchedBackends.indexOf(backend) === -1) {
|
if (this.#fetchedBackends.indexOf(backend) === -1) {
|
||||||
const response = await global.backends[backend].openSession(user, password);
|
const response = await global.backends[backend].openSession(user, password);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return false;
|
return response.message;
|
||||||
}
|
}
|
||||||
this.#cookies = this.#cookies.concat(response.cookies);
|
this.#cookies = this.#cookies.concat(response.cookies);
|
||||||
this.#fetchedBackends.push(backend);
|
this.#fetchedBackends.push(backend);
|
||||||
@ -39,7 +39,7 @@ class CookieFetcher {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
exportCookies () {
|
exportCookies () {
|
||||||
@ -67,9 +67,9 @@ router.post("/ticket", async (req, res) => {
|
|||||||
let backends = global.userManager.getBackendsByUser(userObj);
|
let backends = global.userManager.getBackendsByUser(userObj);
|
||||||
backends = backends.concat(["pve"]);
|
backends = backends.concat(["pve"]);
|
||||||
const cm = new CookieFetcher();
|
const cm = new CookieFetcher();
|
||||||
const success = await cm.fetchBackends(backends, userObj, params.password);
|
const error = await cm.fetchBackends(backends, userObj, params.password);
|
||||||
if (!success) {
|
if (error) {
|
||||||
res.status(401).send({ auth: false });
|
res.status(401).send({ auth: false, error });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const cookies = cm.exportCookies();
|
const cookies = cm.exportCookies();
|
||||||
|
@ -6,8 +6,8 @@ const checkAuth = global.utils.checkAuth;
|
|||||||
/**
|
/**
|
||||||
* GET - get all groups
|
* GET - get all groups
|
||||||
* responses:
|
* responses:
|
||||||
* - 200: {auth:true, groups: Array}
|
* - 200: {auth: true, groups: Array}
|
||||||
* - 201: {auth: false}
|
* - 401: {auth: false}
|
||||||
*/
|
*/
|
||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req, res) => {
|
||||||
// check auth
|
// check auth
|
||||||
@ -15,5 +15,27 @@ router.get("/", async (req, res) => {
|
|||||||
if (!auth) {
|
if (!auth) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.status(200).send(global.userManager.getAllGroups());
|
const groups = await global.userManager.getAllGroups(req.cookies);
|
||||||
|
res.status(200).send({ groups });
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET - get specific group
|
||||||
|
* request:
|
||||||
|
* - groupname: name of group to get
|
||||||
|
* responses:
|
||||||
|
* - 200: {auth: true, group: Object}
|
||||||
|
* - 401: {auth: false}
|
||||||
|
*/
|
||||||
|
router.get("/:groupname", async (req, res) => {
|
||||||
|
const params = {
|
||||||
|
groupname: req.params.groupname
|
||||||
|
};
|
||||||
|
// check auth
|
||||||
|
const auth = await checkAuth(req.cookies, res);
|
||||||
|
if (!auth) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const group = await global.userManager.getGroup(params.groupname, req.cookies);
|
||||||
|
res.status(200).send({ group });
|
||||||
});
|
});
|
||||||
|
@ -7,7 +7,7 @@ const checkAuth = global.utils.checkAuth;
|
|||||||
* GET - get all users
|
* GET - get all users
|
||||||
* responses:
|
* responses:
|
||||||
* - 200: {auth:true, users: Array}
|
* - 200: {auth:true, users: Array}
|
||||||
* - 201: {auth: false}
|
* - 401: {auth: false}
|
||||||
*/
|
*/
|
||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req, res) => {
|
||||||
// check auth
|
// check auth
|
||||||
@ -15,5 +15,28 @@ router.get("/", async (req, res) => {
|
|||||||
if (!auth) {
|
if (!auth) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.status(200).send(global.userManager.getAllUsers());
|
const users = await global.userManager.getAllUsers(req.cookies);
|
||||||
|
res.status(200).send({ users });
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET - get specific user
|
||||||
|
* request:
|
||||||
|
* - username: username (id@realm) of user to get
|
||||||
|
* responses:
|
||||||
|
* - 200: {auth: true, user: Object}
|
||||||
|
* - 401: {auth: false}
|
||||||
|
*/
|
||||||
|
router.get("/:username", async (req, res) => {
|
||||||
|
const params = {
|
||||||
|
username: req.params.username
|
||||||
|
};
|
||||||
|
// check auth
|
||||||
|
const auth = await checkAuth(req.cookies, res);
|
||||||
|
if (!auth) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const userObj = global.utils.getUserObjFromUsername(params.username);
|
||||||
|
const user = await global.userManager.getUser(userObj, req.cookies);
|
||||||
|
res.status(200).send({ user });
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user