XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

chore: remove toLoginRequest (#651)

25c8179a
Sainan <sainan@calamity.inc>
提交于

代码差异

2 个文件 +2 -41
Modified src/controllers/api/loginController.ts +2 -6
@@ -1,20 +1,16 @@
1 /* eslint-disable @typescript-eslint/no-unused-vars */
2 1 import { RequestHandler } from "express";
3 2
4 3 import { config } from "@/src/services/configService";
5 4 import buildConfig from "@/static/data/buildConfig.json";
6 5
7 import { toLoginRequest } from "@/src/helpers/loginHelpers";
8 6 import { Account } from "@/src/models/loginModel";
9 7 import { createAccount, isCorrectPassword, isNameTaken } from "@/src/services/loginService";
10 import { IDatabaseAccountJson, ILoginResponse } from "@/src/types/loginTypes";
8 import { IDatabaseAccountJson, ILoginRequest, ILoginResponse } from "@/src/types/loginTypes";
11 9 import { DTLS, groups, HUB, platformCDNs } from "@/static/fixed_responses/login_static";
12 10 import { logger } from "@/src/utils/logger";
13 11
14 12 export const loginController: RequestHandler = async (request, response) => {
15 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument
16 const body = JSON.parse(request.body); // parse octet stream of json data to json object
17 const loginRequest = toLoginRequest(body);
13 const loginRequest = JSON.parse(String(request.body)) as ILoginRequest; // parse octet stream of json data to json object
18 14
19 15 const account = await Account.findOne({ email: loginRequest.email }); //{ _id: 0, __v: 0 }
20 16 const nonce = Math.round(Math.random() * Number.MAX_SAFE_INTEGER);
Deleted src/helpers/loginHelpers.ts +0 -35
@@ -1,35 +0,0 @@
1 import { ILoginRequest } from "@/src/types/loginTypes";
2 import { parseEmail, parseNumber, parseString } from "./general";
3
4 const toLoginRequest = (loginRequest: unknown): ILoginRequest => {
5 if (!loginRequest || typeof loginRequest !== "object") {
6 throw new Error("incorrect or missing login request data");
7 }
8
9 // TODO: function that checks whether every field of interface is in object
10 if (
11 "email" in loginRequest &&
12 "password" in loginRequest &&
13 "time" in loginRequest &&
14 "s" in loginRequest &&
15 "lang" in loginRequest &&
16 "date" in loginRequest &&
17 "ClientType" in loginRequest &&
18 "PS" in loginRequest
19 ) {
20 return {
21 email: parseEmail(loginRequest.email),
22 password: parseString(loginRequest.password),
23 time: parseNumber(loginRequest.time),
24 s: parseString(loginRequest.s),
25 lang: parseString(loginRequest.lang),
26 date: parseNumber(loginRequest.date),
27 ClientType: parseString(loginRequest.ClientType),
28 PS: parseString(loginRequest.PS)
29 };
30 }
31
32 throw new Error("incorrect login request");
33 };
34
35 export { toLoginRequest };