feat: login conflict (#1127)

Closes #1076

Reviewed-on: OpenWF/SpaceNinjaServer#1127
This commit is contained in:
Sainan 2025-03-09 07:40:37 -07:00
parent 3da02385f9
commit f6513420be
6 changed files with 31 additions and 17 deletions

View File

@ -61,10 +61,19 @@ export const loginController: RequestHandler = async (request, response) => {
return;
}
if (account.Nonce == 0 || loginRequest.ClientType != "webui") {
if (loginRequest.ClientType == "webui") {
if (!account.Nonce) {
account.ClientType = "webui";
account.Nonce = nonce;
}
} else {
if (account.Nonce && account.ClientType != "webui" && !account.Dropped && !loginRequest.kick) {
response.status(400).json({ error: "nonce still set" });
return;
}
account.ClientType = loginRequest.ClientType;
account.Nonce = nonce;
}
if (loginRequest.ClientType != "webui") {
account.CountryCode = loginRequest.lang.toUpperCase();
}
await account.save();

View File

@ -0,0 +1,9 @@
import { getAccountForRequest } from "@/src/services/loginService";
import { RequestHandler } from "express";
export const ircDroppedController: RequestHandler = async (req, res) => {
const account = await getAccountForRequest(req);
account.Dropped = true;
await account.save();
res.end();
};

View File

@ -20,6 +20,7 @@ const databaseAccountSchema = new Schema<IDatabaseAccountJson>(
ConsentNeeded: { type: Boolean, required: true },
TrackedSettings: { type: [String], default: [] },
Nonce: { type: Number, default: 0 },
Dropped: Boolean,
LastLoginDay: { type: Number },
LatestEventMessageDate: { type: Date, default: 0 }
},

View File

@ -7,6 +7,7 @@ import { popArchonCrystalUpgradeController } from "@/src/controllers/custom/popA
import { deleteAccountController } from "@/src/controllers/custom/deleteAccountController";
import { getNameController } from "@/src/controllers/custom/getNameController";
import { renameAccountController } from "@/src/controllers/custom/renameAccountController";
import { ircDroppedController } from "@/src/controllers/custom/ircDroppedController";
import { createAccountController } from "@/src/controllers/custom/createAccountController";
import { createMessageController } from "@/src/controllers/custom/createMessageController";
@ -28,6 +29,7 @@ customRouter.get("/popArchonCrystalUpgrade", popArchonCrystalUpgradeController);
customRouter.get("/deleteAccount", deleteAccountController);
customRouter.get("/getName", getNameController);
customRouter.get("/renameAccount", renameAccountController);
customRouter.get("/ircDropped", ircDroppedController);
customRouter.post("/createAccount", createAccountController);
customRouter.post("/createMessage", createMessageController);

View File

@ -82,21 +82,12 @@ export const getAccountForRequest = async (req: Request): Promise<TAccountDocume
};
export const getAccountIdForRequest = async (req: Request): Promise<string> => {
if (!req.query.accountId) {
throw new Error("Request is missing accountId parameter");
const account = await getAccountForRequest(req);
if (account.Dropped && req.query.ct) {
account.Dropped = undefined;
await account.save();
}
if (!req.query.nonce || parseInt(req.query.nonce as string) === 0) {
throw new Error("Request is missing nonce parameter");
}
if (
!(await Account.exists({
_id: req.query.accountId,
Nonce: req.query.nonce
}))
) {
throw new Error("Invalid accountId-nonce pair");
}
return req.query.accountId as string;
return account._id.toString();
};
export const isAdministrator = (account: TAccountDocument): boolean => {

View File

@ -14,6 +14,7 @@ export interface IAccountAndLoginResponseCommons {
export interface IDatabaseAccount extends IAccountAndLoginResponseCommons {
email: string;
password: string;
Dropped?: boolean;
LastLoginDay?: number;
LatestEventMessageDate: Date;
}
@ -32,6 +33,7 @@ export interface ILoginRequest {
date: number;
ClientType: string;
PS: string;
kick?: boolean;
}
export interface ILoginResponse extends IAccountAndLoginResponseCommons {