From 9700416355547e886a479aa61ebf1e8dc2481ef7 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 23 Mar 2025 13:49:29 +0100 Subject: [PATCH] update config when admin changes their name --- src/controllers/custom/renameAccountController.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/controllers/custom/renameAccountController.ts b/src/controllers/custom/renameAccountController.ts index c5b733e8..d30b44ae 100644 --- a/src/controllers/custom/renameAccountController.ts +++ b/src/controllers/custom/renameAccountController.ts @@ -1,5 +1,6 @@ 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) => { const account = await getAccountForRequest(req); @@ -7,8 +8,18 @@ export const renameAccountController: RequestHandler = async (req, res) => { if (await isNameTaken(req.query.newname)) { res.status(409).json("Name already in use"); } 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; await account.save(); + res.end(); } } else {