From f9e3c5d0120253fc26223508bd0193f3d8871832 Mon Sep 17 00:00:00 2001 From: Suwings Date: Tue, 26 Jul 2022 11:29:18 +0800 Subject: [PATCH] Refactor: login router internationalized --- src/app/i18n/language/zh_cn.ts | 8 ++++++++ src/app/routers/public/login_router.ts | 13 ++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/app/i18n/language/zh_cn.ts b/src/app/i18n/language/zh_cn.ts index a9ce54e..feece4b 100644 --- a/src/app/i18n/language/zh_cn.ts +++ b/src/app/i18n/language/zh_cn.ts @@ -48,7 +48,15 @@ export default { }, schedule: { invaildName: "非法的计划任务名" + }, + login: { + ban: "身份验证次数过多,您的 IP 地址已被锁定 10 分钟", + nameOrPassError: "账号或密码错误", + init: "[安装面板] 正在初始化面板管理员账号: {{userName}}", + installed: "面板已安装,无法重新安装,请备份并删除 data 文件夹以实现全新安装" } } }; // import { $t } from "../../i18n"; +// $t("permission.forbiddenInstance");] +// $t("router.login.ban") diff --git a/src/app/routers/public/login_router.ts b/src/app/routers/public/login_router.ts index e4586c6..7468c98 100644 --- a/src/app/routers/public/login_router.ts +++ b/src/app/routers/public/login_router.ts @@ -27,7 +27,7 @@ import { check, login, logout, checkBanIp } from "../../service/passport_service import { systemConfig } from "../../setting"; import userSystem from "../../service/system_user"; import { logger } from "../../service/log"; - +import { $t } from "../../i18n"; const router = new Router({ prefix: "/auth" }); // [Public Permission] @@ -39,13 +39,13 @@ router.post( async (ctx: Koa.ParameterizedContext) => { const userName = String(ctx.request.body.username); const passWord = String(ctx.request.body.password); - if (!checkBanIp(ctx)) throw new Error("身份验证次数过多,您的 IP 地址已被锁定 10 分钟"); + if (!checkBanIp(ctx)) throw new Error($t("router.login.ban")); if (check(ctx)) return (ctx.body = "Logined"); let token = login(ctx, userName, passWord); if (token) { ctx.body = true; } else { - throw new Error("账号或密码错误"); + throw new Error($t("router.login.nameOrPassError")); } } ); @@ -99,9 +99,8 @@ router.all( const userName = ctx.request.body.username; const passWord = ctx.request.body.password; if (userSystem.objects.size === 0) { - if (!userSystem.validatePassword(passWord)) - throw new Error("密码不规范,必须为拥有大小写字母,数字,长度在9到36之间"); - logger.info(`[安装面板] 正在初始化面板管理员账号: ${userName}`); + if (!userSystem.validatePassword(passWord)) throw new Error($t("router.user.passwordCheck")); + logger.info($t("router.login.init", { userName })); userSystem.create({ userName, passWord, @@ -110,7 +109,7 @@ router.all( login(ctx, userName, passWord); return (ctx.body = true); } - throw new Error("Panel installed"); + throw new Error($t("router.user.installed")); } );