update config when admin changes their name
All checks were successful
Build / build (18) (push) Successful in 45s
Build / build (22) (push) Successful in 1m11s
Build / build (20) (push) Successful in 1m23s
Build / build (18) (pull_request) Successful in 43s
Build / build (20) (pull_request) Successful in 1m12s
Build / build (22) (pull_request) Successful in 1m18s
All checks were successful
Build / build (18) (push) Successful in 45s
Build / build (22) (push) Successful in 1m11s
Build / build (20) (push) Successful in 1m23s
Build / build (18) (pull_request) Successful in 43s
Build / build (20) (pull_request) Successful in 1m12s
Build / build (22) (pull_request) Successful in 1m18s
This commit is contained in:
parent
dc5ec24a1a
commit
9700416355
@ -1,5 +1,6 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { getAccountForRequest, isNameTaken } from "@/src/services/loginService";
|
import { getAccountForRequest, isAdministrator, isNameTaken } from "@/src/services/loginService";
|
||||||
|
import { config, saveConfig } from "@/src/services/configService";
|
||||||
|
|
||||||
export const renameAccountController: RequestHandler = async (req, res) => {
|
export const renameAccountController: RequestHandler = async (req, res) => {
|
||||||
const account = await getAccountForRequest(req);
|
const account = await getAccountForRequest(req);
|
||||||
@ -7,8 +8,18 @@ export const renameAccountController: RequestHandler = async (req, res) => {
|
|||||||
if (await isNameTaken(req.query.newname)) {
|
if (await isNameTaken(req.query.newname)) {
|
||||||
res.status(409).json("Name already in use");
|
res.status(409).json("Name already in use");
|
||||||
} else {
|
} else {
|
||||||
|
if (isAdministrator(account)) {
|
||||||
|
for (let i = 0; i != config.administratorNames!.length; ++i) {
|
||||||
|
if (config.administratorNames![i] == account.DisplayName) {
|
||||||
|
config.administratorNames![i] = req.query.newname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
account.DisplayName = req.query.newname;
|
account.DisplayName = req.query.newname;
|
||||||
await account.save();
|
await account.save();
|
||||||
|
|
||||||
res.end();
|
res.end();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user