项目仓库初始化

This commit is contained in:
Stev_Wang
2025-12-25 18:20:37 +08:00
commit b975165f18
12 changed files with 405 additions and 0 deletions

36
auth/login.js Normal file
View File

@@ -0,0 +1,36 @@
// @ts-ignore 运营后台登录
export async function execute(http_message) {
// {"username":"123123","password":"123123","autoLogin":true,"code":"login","type":"account"}
let body = http_message["body"];
if (body["username"] === undefined) {
return HttpResUtils.err_msg("账号不能为空");
}
if (body["password"] === undefined) {
return HttpResUtils.err_msg("密码不能为空");
}
// 查询游戏账号
let accounts = await G.Accounts.query_accounts_db(body["username"]);
if (accounts.length > 0) {
let accounts_json = JSON.parse(accounts);
// 确保accounts_json是数组且有数据
if (Array.isArray(accounts_json) && accounts_json.length > 0) {
let account = accounts_json[0];
if (body["password"] !== account["password"]) {
return HttpResUtils.err_msg("密码错误")
}
// 删除之前缓存的token
if(_AdminUserTokenCache.has(account["username"])){
_AdminTokenUserCache.delete(_AdminUserTokenCache.get(account["username"]));
}
// 缓存新的token
let token = _jwt_.gen(account["username"], `${account["id"]}`);
_AdminTokenUserCache.set(token, account["username"]);
_AdminUserTokenCache.set(account["username"], token);
return HttpResUtils.ok(token);
} else {
return HttpResUtils.err_msg("账号不存在");
}
} else {
return HttpResUtils.err_msg("账号不存在");
}
}

9
auth/out_login.js Normal file
View File

@@ -0,0 +1,9 @@
// @ts-ignore 退出登录
export async function execute(http_message) {
let username = HttpReQUtils.check_auth(http_message);
if (username.length > 0) {
_AdminUserTokenCache.delete(HttpReQUtils.get_token(http_message));
_AdminTokenUserCache.delete(username);
}
return HttpResUtils.all(null,402,null,true);
}