项目仓库初始化
This commit is contained in:
36
auth/login.js
Normal file
36
auth/login.js
Normal 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
9
auth/out_login.js
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user