返回提交历史
Modified
src/controllers/api/loginController.ts
+24
-29
XFEstudio/XFESpaceNinjaServer
chore: improve handling when no email was provided for login (#3647)
Closes #3646 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3647 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
54f621de
代码差异
1 个文件
+24
-29
@@ -29,11 +29,7 @@ export const loginController: RequestHandler = async (request, response) => {
29
29
if (isAndroid) {
30
30
try {
31
31
const { userId, email } = await getGoogleAccountData(loginRequest.GoogleTokenId);
32
if (email === undefined || email === "") {
33
response.status(400).json({ error: "incorrect login data" });
34
return;
35
}
36
loginRequest.email = email;
32
loginRequest.email = email ?? "";
37
33
loginRequest.GoogleTokenId = userId;
38
34
} catch (error: unknown) {
39
35
response.status(400).json({ error: "incorrect login data" });
@@ -42,6 +38,11 @@ export const loginController: RequestHandler = async (request, response) => {
42
38
loginRequest.password = "android"; // edit in mongodb if you want to access it via webui
43
39
}
44
40
41
if (!loginRequest.email) {
42
response.status(400).json({ error: "incorrect login data" });
43
return;
44
}
45
45
46
if (config.tunables?.useLoginToken) {
46
47
if (request.query.token !== getTokenForClient((request.socket.address() as AddressInfo).address)) {
47
48
response.status(400).json({ error: "missing or incorrect token" });
@@ -61,31 +62,25 @@ export const loginController: RequestHandler = async (request, response) => {
61
62
((config.autoCreateAccount && loginRequest.ClientType != "webui") ||
62
63
loginRequest.ClientType == "webui-register")
63
64
) {
64
try {
65
const name = await getUsernameFromEmail(loginRequest.email);
66
const newAccount = await createAccount({
67
email: loginRequest.email,
68
password: loginRequest.password,
69
DisplayName: name,
70
CountryCode: loginRequest.lang?.toUpperCase() ?? "EN",
71
ClientType: loginRequest.ClientType,
72
GoogleTokenId: loginRequest.GoogleTokenId,
73
Nonce: createNonce(),
74
BuildLabel: buildLabel,
75
LastLogin: new Date()
76
});
77
logger.debug("created new account");
78
if (isAndroid) {
79
response.status(400).json({ error: `noAndroidAccount;countryCode=US` });
80
} else {
81
response.send(createLoginResponse(request, newAccount, buildLabel)).end();
82
}
83
return;
84
} catch (error: unknown) {
85
if (error instanceof Error) {
86
throw new Error(`error creating account ${error.message}`);
87
}
65
const name = await getUsernameFromEmail(loginRequest.email);
66
const newAccount = await createAccount({
67
email: loginRequest.email,
68
password: loginRequest.password,
69
DisplayName: name,
70
CountryCode: loginRequest.lang?.toUpperCase() ?? "EN",
71
ClientType: loginRequest.ClientType,
72
GoogleTokenId: loginRequest.GoogleTokenId,
73
Nonce: createNonce(),
74
BuildLabel: buildLabel,
75
LastLogin: new Date()
76
});
77
logger.debug("created new account");
78
if (isAndroid) {
79
response.status(400).json({ error: `noAndroidAccount;countryCode=US` });
80
} else {
81
response.send(createLoginResponse(request, newAccount, buildLabel)).end();
88
82
}
83
return;
89
84
}
90
85
91
86
if (!account) {