feat: add administrators
This commit is contained in:
parent
e3bac09e21
commit
6b9fd766e0
@ -8,6 +8,7 @@
|
|||||||
"myAddress": "localhost",
|
"myAddress": "localhost",
|
||||||
"httpPort": 80,
|
"httpPort": 80,
|
||||||
"httpsPort": 443,
|
"httpsPort": 443,
|
||||||
|
"administratorNames": [],
|
||||||
"autoCreateAccount": true,
|
"autoCreateAccount": true,
|
||||||
"skipStoryModeChoice": true,
|
"skipStoryModeChoice": true,
|
||||||
"skipTutorial": true,
|
"skipTutorial": true,
|
||||||
|
@ -25,6 +25,7 @@ interface IConfig {
|
|||||||
httpPort?: number;
|
httpPort?: number;
|
||||||
httpsPort?: number;
|
httpsPort?: number;
|
||||||
myIrcAddresses?: string[];
|
myIrcAddresses?: string[];
|
||||||
|
administratorNames?: string[];
|
||||||
autoCreateAccount?: boolean;
|
autoCreateAccount?: boolean;
|
||||||
skipStoryModeChoice?: boolean;
|
skipStoryModeChoice?: boolean;
|
||||||
skipTutorial?: boolean;
|
skipTutorial?: boolean;
|
||||||
|
@ -2,11 +2,12 @@ import { Account } from "@/src/models/loginModel";
|
|||||||
import { createInventory } from "@/src/services/inventoryService";
|
import { createInventory } from "@/src/services/inventoryService";
|
||||||
import { IDatabaseAccount, IDatabaseAccountJson } from "@/src/types/loginTypes";
|
import { IDatabaseAccount, IDatabaseAccountJson } from "@/src/types/loginTypes";
|
||||||
import { createShip } from "./shipService";
|
import { createShip } from "./shipService";
|
||||||
import { Types } from "mongoose";
|
import { Document, Types } from "mongoose";
|
||||||
import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
|
import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
|
||||||
import { PersonalRooms } from "@/src/models/personalRoomsModel";
|
import { PersonalRooms } from "@/src/models/personalRoomsModel";
|
||||||
import new_personal_rooms from "@/static/fixed_responses/personalRooms.json";
|
import new_personal_rooms from "@/static/fixed_responses/personalRooms.json";
|
||||||
import { Request } from "express";
|
import { Request } from "express";
|
||||||
|
import { config } from "@/src/services/configService";
|
||||||
|
|
||||||
export const isCorrectPassword = (requestPassword: string, databasePassword: string): boolean => {
|
export const isCorrectPassword = (requestPassword: string, databasePassword: string): boolean => {
|
||||||
return requestPassword === databasePassword;
|
return requestPassword === databasePassword;
|
||||||
@ -48,20 +49,21 @@ export const createPersonalRooms = async (accountId: Types.ObjectId, shipId: Typ
|
|||||||
await personalRooms.save();
|
await personalRooms.save();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAccountForRequest = async (req: Request) => {
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
|
type TAccountDocument = Document<unknown, {}, IDatabaseAccountJson> &
|
||||||
|
IDatabaseAccountJson & { _id: Types.ObjectId; __v: number };
|
||||||
|
|
||||||
|
export const getAccountForRequest = async (req: Request): Promise<TAccountDocument> => {
|
||||||
if (!req.query.accountId) {
|
if (!req.query.accountId) {
|
||||||
throw new Error("Request is missing accountId parameter");
|
throw new Error("Request is missing accountId parameter");
|
||||||
}
|
}
|
||||||
if (!req.query.nonce || parseInt(req.query.nonce as string) === 0) {
|
if (!req.query.nonce || parseInt(req.query.nonce as string) === 0) {
|
||||||
throw new Error("Request is missing nonce parameter");
|
throw new Error("Request is missing nonce parameter");
|
||||||
}
|
}
|
||||||
const account = await Account.findOne(
|
const account = await Account.findOne({
|
||||||
{
|
|
||||||
_id: req.query.accountId,
|
_id: req.query.accountId,
|
||||||
Nonce: req.query.nonce
|
Nonce: req.query.nonce
|
||||||
},
|
});
|
||||||
"_id"
|
|
||||||
);
|
|
||||||
if (!account) {
|
if (!account) {
|
||||||
throw new Error("Invalid accountId-nonce pair");
|
throw new Error("Invalid accountId-nonce pair");
|
||||||
}
|
}
|
||||||
@ -71,3 +73,7 @@ export const getAccountForRequest = async (req: Request) => {
|
|||||||
export const getAccountIdForRequest = async (req: Request): Promise<string> => {
|
export const getAccountIdForRequest = async (req: Request): Promise<string> => {
|
||||||
return (await getAccountForRequest(req))._id.toString();
|
return (await getAccountForRequest(req))._id.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isAdministrator = (account: TAccountDocument): boolean => {
|
||||||
|
return !!config.administratorNames?.find(x => x == account.DisplayName);
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user