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

feat: name length limit (#3097)

Closes #3095 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3097 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

b7503448
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

10 个文件 +21 -7
Modified src/controllers/custom/renameAccountController.ts +6 -3
@@ -2,12 +2,15 @@ import type { RequestHandler } from "express";
2 2 import { getAccountForRequest, isAdministrator, isNameTaken } from "../../services/loginService.ts";
3 3 import { config } from "../../services/configService.ts";
4 4 import { saveConfig } from "../../services/configWriterService.ts";
5 import { MAX_NAME_LENGTH } from "../../models/loginModel.ts";
5 6
6 7 export const renameAccountController: RequestHandler = async (req, res) => {
7 8 const account = await getAccountForRequest(req);
8 9 if (typeof req.query.newname == "string") {
9 if (await isNameTaken(req.query.newname)) {
10 res.status(409).json("Name already in use");
10 if (req.query.newname.length > MAX_NAME_LENGTH) {
11 res.status(400).send("Name too long").end();
12 } else if (await isNameTaken(req.query.newname)) {
13 res.status(409).send("Name already in use").end();
11 14 } else {
12 15 if (isAdministrator(account)) {
13 16 for (let i = 0; i != config.administratorNames!.length; ++i) {
@@ -24,6 +27,6 @@ export const renameAccountController: RequestHandler = async (req, res) => {
24 27 res.end();
25 28 }
26 29 } else {
27 res.status(400).end();
30 res.sendStatus(400).end();
28 31 }
29 32 };
Modified src/models/loginModel.ts +3 -1
@@ -7,11 +7,13 @@ const opts = {
7 7 toObject: { virtuals: true }
8 8 } satisfies SchemaOptions;
9 9
10 export const MAX_NAME_LENGTH = 24;
11
10 12 const databaseAccountSchema = new Schema<IDatabaseAccountJson>(
11 13 {
12 14 email: { type: String, required: true, unique: true },
13 15 password: { type: String, required: true },
14 DisplayName: { type: String, required: true, unique: true },
16 DisplayName: { type: String, required: true, unique: true, maxLength: MAX_NAME_LENGTH },
15 17 CountryCode: { type: String, default: "" },
16 18 ClientType: { type: String },
17 19 CrossPlatformAllowed: { type: Boolean, default: true },
Modified static/webui/script.js +5 -3
@@ -171,12 +171,14 @@ function renameAccount(taken_name) {
171 171 if (newname) {
172 172 revalidateAuthz().then(() => {
173 173 fetch("/custom/renameAccount?" + window.authz + "&newname=" + encodeURIComponent(newname)).then(res => {
174 if (res.status == 409) {
175 renameAccount(newname);
176 } else {
174 if (res.status == 200) {
177 175 $(".displayname").text(newname);
178 176 updateLocElements();
179 177 toast(loc("code_succRelog"));
178 } else if (res.status == 409) {
179 renameAccount(newname);
180 } else {
181 toast(loc("code_genFail"));
180 182 }
181 183 });
182 184 });
Modified static/webui/translations/de.js +1 -0
@@ -10,6 +10,7 @@ dict = {
10 10
11 11 code_loginFail: `Anmeldung fehlgeschlagen. Bitte überprüfe deine Angaben.`,
12 12 code_regFail: `Registrierung fehlgeschlagen. Account existiert bereits?`,
13 code_genFail: `[UNTRANSLATED] I'm sorry Dave, I'm afraid I can't do that.`,
13 14 code_changeNameConfirm: `In welchen Namen möchtest du deinen Account umbenennen?`,
14 15 code_changeNameRetry: `|NAME| ist bereits vergeben.`,
15 16 code_deleteAccountConfirm: `Bist du sicher, dass du deinen Account |DISPLAYNAME| (|EMAIL|) löschen möchtest? Diese Aktion kann nicht rückgängig gemacht werden.`,
Modified static/webui/translations/en.js +1 -0
@@ -9,6 +9,7 @@ dict = {
9 9
10 10 code_loginFail: `Login failed. Double-check the email and password.`,
11 11 code_regFail: `Registration failed. Account already exists?`,
12 code_genFail: `I'm sorry Dave, I'm afraid I can't do that.`,
12 13 code_changeNameConfirm: `What would you like to change your account name to?`,
13 14 code_changeNameRetry: `|NAME| is already taken.`,
14 15 code_deleteAccountConfirm: `Are you sure you want to delete your account |DISPLAYNAME| (|EMAIL|)? This action cannot be undone.`,
Modified static/webui/translations/es.js +1 -0
@@ -10,6 +10,7 @@ dict = {
10 10
11 11 code_loginFail: `Error al iniciar sesión. Verifica el correo electrónico y la contraseña.`,
12 12 code_regFail: `Error al registrar la cuenta. ¿Ya existe una cuenta con este correo?`,
13 code_genFail: `[UNTRANSLATED] I'm sorry Dave, I'm afraid I can't do that.`,
13 14 code_changeNameConfirm: `¿Qué nombre te gustaría ponerle a tu cuenta?`,
14 15 code_changeNameRetry: `|NAME| Ya está en uso.`,
15 16 code_deleteAccountConfirm: `¿Estás seguro de que deseas eliminar tu cuenta |DISPLAYNAME| (|EMAIL|)? Esta acción es permanente.`,
Modified static/webui/translations/fr.js +1 -0
@@ -10,6 +10,7 @@ dict = {
10 10
11 11 code_loginFail: `Connexion échouée. Vérifiez le mot de passe.`,
12 12 code_regFail: `Enregistrement impossible. Compte existant?`,
13 code_genFail: `[UNTRANSLATED] I'm sorry Dave, I'm afraid I can't do that.`,
13 14 code_changeNameConfirm: `Nouveau nom du compte :`,
14 15 code_changeNameRetry: `|NAME| est déjà pris.`,
15 16 code_deleteAccountConfirm: `Supprimer |DISPLAYNAME| (|EMAIL|) ? Cette action est irreversible.`,
Modified static/webui/translations/ru.js +1 -0
@@ -10,6 +10,7 @@ dict = {
10 10
11 11 code_loginFail: `Не удалось войти. Проверьте адрес электронной почты и пароль.`,
12 12 code_regFail: `Не удалось зарегистрироваться. Учетная запись уже существует?`,
13 code_genFail: `[UNTRANSLATED] I'm sorry Dave, I'm afraid I can't do that.`,
13 14 code_changeNameConfirm: `Какое имя вы хотите установить для своей учетной записи?`,
14 15 code_changeNameRetry: `|NAME| уже занято.`,
15 16 code_deleteAccountConfirm: `Вы уверены, что хотите удалить аккаунт |DISPLAYNAME| (|EMAIL|)? Это действие нельзя отменить.`,
Modified static/webui/translations/uk.js +1 -0
@@ -10,6 +10,7 @@ dict = {
10 10
11 11 code_loginFail: `Не вдалося увійти. Перевірте адресу електронної пошти та пароль.`,
12 12 code_regFail: `Не вдалося зареєструватися. Обліковий запис вже існує?`,
13 code_genFail: `[UNTRANSLATED] I'm sorry Dave, I'm afraid I can't do that.`,
13 14 code_changeNameConfirm: `Яке ім'я ви хочете встановити для свого облікового запису?`,
14 15 code_changeNameRetry: `|NAME| вже зайнято.`,
15 16 code_deleteAccountConfirm: `Ви впевнені, що хочете видалити обліковий запис |DISPLAYNAME| (|EMAIL|)? Цю дію не можна скасувати.`,
Modified static/webui/translations/zh.js +1 -0
@@ -10,6 +10,7 @@ dict = {
10 10
11 11 code_loginFail: `登录失败.请检查邮箱和密码.`,
12 12 code_regFail: `注册失败.账号是否已存在?`,
13 code_genFail: `[UNTRANSLATED] I'm sorry Dave, I'm afraid I can't do that.`,
13 14 code_changeNameConfirm: `您想将账户名称更改为?`,
14 15 code_changeNameRetry: `|NAME| 已存在相同昵称.`,
15 16 code_deleteAccountConfirm: `确定要删除您的账户 |DISPLAYNAME|(|EMAIL|) 吗?此操作不可撤销.`,