+save user minigame *logger
This commit is contained in:
parent
ab5fc549b3
commit
42048177b1
@ -21,7 +21,7 @@ exports.platforms = [
|
||||
{
|
||||
_id: ObjectId('5ceb909ef204f241e886378f'),
|
||||
name: 'QQ 玩一玩',
|
||||
name_en: 'qq',
|
||||
name_en: 'sq',
|
||||
platform_id: '6002',
|
||||
comment: ''
|
||||
},
|
||||
|
@ -14,6 +14,7 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^0.18.0",
|
||||
"biguint-format": "^1.0.1",
|
||||
"bluebird": "^3.5.4",
|
||||
"body-parser": "^1.19.0",
|
||||
@ -46,6 +47,7 @@
|
||||
"redis": "^2.8.0",
|
||||
"request": "^2.88.0",
|
||||
"serve-favicon": "^2.5.0",
|
||||
"ssha": "^1.0.1",
|
||||
"yargs": "^13.2.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -1,15 +1,47 @@
|
||||
import { Router } from 'express';
|
||||
import GameInfo from '../../models/admin/GameInfo';
|
||||
|
||||
const router = new Router();
|
||||
// 获取平台列表
|
||||
// 接收ftp账号
|
||||
router.post('/minigame', async (req, res, next) => {
|
||||
const body = req.body;
|
||||
try {
|
||||
console.log(body);
|
||||
res.send({
|
||||
errcode: 0,
|
||||
body
|
||||
});
|
||||
if (body.type === 'minigame_ftp') {
|
||||
const search = await GameInfo.findOne({ game_id: body.game_id, deleted: false });
|
||||
if (search) {
|
||||
// 已有账号 存储相应平台ftp信息
|
||||
const platforms = search.platforms;
|
||||
for (let i = 0; i < platforms.length; i++) {
|
||||
if (platforms[i].platform.name_en === body.platform) {
|
||||
platforms[i].ftp = {}
|
||||
platforms[i].ftp.ftp_user = body.ftp_user;
|
||||
platforms[i].ftp.ftp_pass = body.ftp_pass;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const result = await GameInfo.updateOne(
|
||||
{ game_id: body.game_id, deleted: false },
|
||||
{
|
||||
platforms
|
||||
}
|
||||
);
|
||||
|
||||
res.send({
|
||||
errcode: 0
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
errmsg: '游戏不存在!'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
msg: '信息有误!'
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
import GameInfo from '../../models/admin/GameInfo';
|
||||
import { Router } from 'express';
|
||||
import { userInfo } from 'os';
|
||||
import axios from 'axios';
|
||||
import config from '../../../config/config';
|
||||
|
||||
const router = new Router();
|
||||
|
||||
@ -143,8 +145,7 @@ const router = new Router();
|
||||
// 获取游戏列表
|
||||
router.get('/list', async (req, res, next) => {
|
||||
const query = req.query || {};
|
||||
const userPerms = req.user.permissions
|
||||
console.log(req.query)
|
||||
const userPerms = req.user.permissions;
|
||||
|
||||
try {
|
||||
let search = [];
|
||||
@ -152,19 +153,18 @@ router.get('/list', async (req, res, next) => {
|
||||
if (query.type === 'all') {
|
||||
// 返回所有游戏信息(仅包含游戏_id与游戏名)
|
||||
result = await GameInfo.find({ deleted: false });
|
||||
|
||||
|
||||
} else {
|
||||
// TODO: 只返回有权限查阅的游戏
|
||||
search = await GameInfo.find({ deleted: false });
|
||||
result = search.filter(game => {
|
||||
const uid = game._id
|
||||
return userPerms.includes(`${uid}-readable`) || userPerms.includes(`${uid}-edit`) || userPerms.includes(`${uid}-publish`)
|
||||
})
|
||||
const uid = game._id;
|
||||
return (
|
||||
userPerms.includes(`${uid}-readable`) ||
|
||||
userPerms.includes(`${uid}-edit`) ||
|
||||
userPerms.includes(`${uid}-publish`)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
console.log(result)
|
||||
|
||||
|
||||
res.send({
|
||||
errcode: 0,
|
||||
@ -195,7 +195,6 @@ router.post('/save', async (req, res, next) => {
|
||||
} else {
|
||||
const newGameInfo = new GameInfo(body);
|
||||
const result = await newGameInfo.save();
|
||||
console.log(result);
|
||||
res.send({
|
||||
errcode: 0,
|
||||
gameInfo: result
|
||||
@ -240,7 +239,7 @@ router.post('/update', async (req, res, next) => {
|
||||
deleted: false
|
||||
});
|
||||
if (search) {
|
||||
const result = await GameInfo.update(
|
||||
const result = await GameInfo.updateOne(
|
||||
{
|
||||
_id: body._id,
|
||||
deleted: false
|
||||
@ -291,4 +290,142 @@ router.post('/del', async (req, res, next) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 创建新平台,获取ftp账号
|
||||
router.post('/create-ftp', async (req, res, next) => {
|
||||
const body = req.body;
|
||||
try {
|
||||
const search = await GameInfo.findOne({
|
||||
game_id: body.game_id,
|
||||
deleted: false
|
||||
});
|
||||
if (!search) {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
errmsg: '游戏已删除或不存在!'
|
||||
});
|
||||
}
|
||||
const save = await GameInfo.updateOne(
|
||||
{
|
||||
game_id: body.game_id,
|
||||
deleted: false
|
||||
},
|
||||
{
|
||||
$push: { platforms: body.platformInfo }
|
||||
}
|
||||
);
|
||||
let token = '';
|
||||
const loginRes = await axios({
|
||||
url: config.minigame.api + 'gettoken/',
|
||||
method: 'post',
|
||||
data: {
|
||||
username: config.minigame.username,
|
||||
password: config.minigame.password
|
||||
}
|
||||
});
|
||||
const loginData = loginRes.data;
|
||||
const loginStatus = loginRes.status;
|
||||
if (loginStatus === 200) {
|
||||
token = loginData.token;
|
||||
} else {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
errmsg: '创建ftp账号时发生错误'
|
||||
});
|
||||
return;
|
||||
}
|
||||
const ftpRes = await axios({
|
||||
url: config.minigame.api + 'minigame/',
|
||||
method: 'post',
|
||||
data: {
|
||||
action: 'game_deploy',
|
||||
data: {
|
||||
game_name: body.game_name_en,
|
||||
game_id: body.game_id,
|
||||
platform: body.platformInfo.platform.name_en,
|
||||
platform_id: body.platformInfo.platform.platform_id
|
||||
}
|
||||
},
|
||||
headers: {
|
||||
authorization: 'Bearer ' + token
|
||||
}
|
||||
});
|
||||
const ftpData = ftpRes.data;
|
||||
const ftpStatus = ftpRes.status;
|
||||
if (ftpStatus === 200) {
|
||||
// 通知用户刷新页面等待ftp账号
|
||||
res.send({
|
||||
errcode: 0,
|
||||
msg: '正在创建ftp账号,请等待一段时间后刷新页面!'
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
errmsg: '创建ftp账号时发生错误'
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
// 更新 ftp 信息
|
||||
router.post('/update-ftp', async (req, res, next) => {
|
||||
const body = req.body;
|
||||
try {
|
||||
let token = '';
|
||||
const loginRes = await axios({
|
||||
url: config.minigame.api + 'gettoken/',
|
||||
method: 'post',
|
||||
data: {
|
||||
username: config.minigame.username,
|
||||
password: config.minigame.password
|
||||
}
|
||||
});
|
||||
|
||||
const loginData = loginRes.data;
|
||||
const loginStatus = loginRes.status;
|
||||
if (loginStatus === 200) {
|
||||
token = loginData.token;
|
||||
} else {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
errmsg: '发布配置时发生错误!'
|
||||
});
|
||||
}
|
||||
|
||||
const ftpRes = await axios({
|
||||
url: config.minigame.api + 'minigame/',
|
||||
method: 'post',
|
||||
data: {
|
||||
action: 'config_deploy',
|
||||
data: {
|
||||
config: {
|
||||
app_id: body.app_id,
|
||||
app_secret: body.app_secret
|
||||
},
|
||||
game_id: body.game_id,
|
||||
platform: body.platform
|
||||
}
|
||||
},
|
||||
headers: {
|
||||
authorization: 'Bearer ' + token
|
||||
}
|
||||
});
|
||||
const ftpData = ftpRes.data
|
||||
const ftpStatus = ftpRes.status
|
||||
if (ftpStatus === 200) {
|
||||
res.send({
|
||||
errcode: 0
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
errmsg: 'ftp账号更新发生错误!'
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@ -1,11 +1,14 @@
|
||||
import ldap from 'ldapjs';
|
||||
import ssha from 'ssha';
|
||||
import config from '../../../config/config';
|
||||
import { User, LdapUser } from '../../models/admin/User';
|
||||
import { combPer, combRole } from '../../utils/comb-permissions';
|
||||
import { Router } from 'express';
|
||||
import logger from '../../utils/logger';
|
||||
const router = new Router();
|
||||
|
||||
router.get('/list', async function userListCtrl(req, res, next) {
|
||||
logger.db(req, '系统管理', '用户列表', '获取用户列表');
|
||||
const client = ldap.createClient({
|
||||
url: config.ldap.url
|
||||
});
|
||||
@ -112,7 +115,9 @@ router.post('/edit', async function userEditCtrl(req, res, next) {
|
||||
|
||||
router.post('/save', async (req, res, next) => {
|
||||
const body = req.body;
|
||||
console.log(body);
|
||||
const dn = `cn=${body.fullname},ou=people,dc=kingsome,dc=cn`;
|
||||
const uidNumber = randomUid();
|
||||
const entry = {
|
||||
cn: body.fullname,
|
||||
sn: body.fullname,
|
||||
@ -122,7 +127,12 @@ router.post('/save', async (req, res, next) => {
|
||||
'organizationalPerson',
|
||||
'person'
|
||||
],
|
||||
uid: body.username
|
||||
uidNumber: uidNumber,
|
||||
gidNumber: 10014,
|
||||
uid: body.username,
|
||||
homeDirectory: `/home/${body.username}`,
|
||||
userPassword: ssha.create(`${body.username}`),
|
||||
o: 'gmplatform'
|
||||
};
|
||||
const client = ldap.createClient({
|
||||
url: config.ldap.url
|
||||
@ -131,15 +141,26 @@ router.post('/save', async (req, res, next) => {
|
||||
try {
|
||||
client.bind(config.ldap.user, config.ldap.password, function(err, bindRes) {
|
||||
if (err) next(err);
|
||||
client.add(dn, entry, function(err) {
|
||||
if (err) console.log(err);
|
||||
// res.send({
|
||||
// errcode: 0
|
||||
// })
|
||||
|
||||
|
||||
|
||||
|
||||
client.add(dn, entry, async function(err) {
|
||||
if (err) {
|
||||
if (err.message === 'Entry Already Exists') {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
errmsg: 'uidNumber 已存在,请重试!'
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
next(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
client.unbind();
|
||||
body._id = uidNumber;
|
||||
const newUser = new User(body);
|
||||
const result = await newUser.save();
|
||||
res.send({
|
||||
errcode: 0
|
||||
});
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
@ -147,4 +168,8 @@ router.post('/save', async (req, res, next) => {
|
||||
}
|
||||
});
|
||||
|
||||
function randomUid() {
|
||||
return Math.ceil(Math.random() * 20000) + 10000;
|
||||
}
|
||||
|
||||
export default router;
|
||||
|
@ -8,7 +8,7 @@ const ObjectId = Schema.Types.ObjectId;
|
||||
*/
|
||||
const OpLog = new mongoose.Schema({
|
||||
// 游戏id
|
||||
admin: {type: ObjectId, ref: 'Admin'},
|
||||
fullname: {type: String},
|
||||
username: {type: String},
|
||||
method: {type: String},
|
||||
show_name: {type: String},
|
||||
@ -18,10 +18,13 @@ const OpLog = new mongoose.Schema({
|
||||
referer: {type: String},
|
||||
// 请求的param
|
||||
params: {type: Schema.Types.Mixed},
|
||||
// 补充信息
|
||||
info: {type: Schema.Types.Mixed},
|
||||
// ip
|
||||
ip: {type: String},
|
||||
// 备注
|
||||
comment: {type: String},
|
||||
type: {type: String},
|
||||
sub_type: {type: String},
|
||||
content: {type: String}
|
||||
}, {
|
||||
collection: 'op_logs',
|
||||
timestamps: true,
|
||||
|
@ -3,7 +3,7 @@ import fs from 'fs-extra';
|
||||
import FileStreamRotator from 'file-stream-rotator';
|
||||
import bunyan from 'bunyan';
|
||||
import config from '../../config/config';
|
||||
import AdminLog from '../models/admin/AdminLog';
|
||||
import OpLog from '../models/admin/OpLog';
|
||||
|
||||
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
@ -98,22 +98,24 @@ export default {
|
||||
logger.fatal(obj);
|
||||
}
|
||||
},
|
||||
db(req, logObj, name) {
|
||||
db(req, type, subType, content, info) {
|
||||
const user = req.user;
|
||||
const ip = req.headers['x-forwarded-for'];
|
||||
const path = req.baseUrl + req.path;
|
||||
const params = req.method === 'GET' ? req.query : req.body;
|
||||
const dataObj = JSON.stringify(logObj) === '{}' ? params : logObj;
|
||||
const obj = new AdminLog({
|
||||
admin: user.id,
|
||||
const obj = new OpLog({
|
||||
fullname: user.fullname,
|
||||
username: user.username,
|
||||
path: path,
|
||||
method: req.method,
|
||||
params: dataObj,
|
||||
params: params,
|
||||
referer: req.headers['referer'],
|
||||
user_agent: req.headers['user-agent'],
|
||||
ip: ip,
|
||||
show_name: name,
|
||||
type: type,
|
||||
sub_type: subType,
|
||||
content: content,
|
||||
info: info || {},
|
||||
});
|
||||
obj.save().then(()=>{}).catch((err)=> {
|
||||
logger.error(err);
|
||||
|
Loading…
x
Reference in New Issue
Block a user