web-server 注册、登录、获取服务器列表;game-server token 校验

This commit is contained in:
liangtongchuan
2020-08-19 14:40:11 +08:00
parent 0458817b51
commit 940879016f
32 changed files with 1144 additions and 38 deletions

View File

@@ -0,0 +1,19 @@
import { STATUS_TOKEN_ERR, STATUS_WRONG_PARMS } from './../../../shared/statusCode';
import { UserModel } from './../db/User';
import { Context } from 'egg';
module.exports = () => {
return async function tokenParser(ctx: Context, next) {
if (!ctx.request.body || !ctx.request.body.token) {
ctx.body = ctx.service.utils.exceptionResult(STATUS_WRONG_PARMS);
return;
}
const user = await UserModel.findUserByToken(ctx.request.body.token);
if (!user) {
console.log('token invalid');
ctx.body = ctx.service.utils.exceptionResult(STATUS_TOKEN_ERR);
return;
}
await next();
}
}