forked from mirror/MCSManager
Refactor: login router internationalized
This commit is contained in:
parent
3115a1732b
commit
f9e3c5d012
@ -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")
|
||||
|
@ -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"));
|
||||
}
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user