+save user minigame *logger
This commit is contained in:
parent
ab5fc549b3
commit
42048177b1
@ -21,7 +21,7 @@ exports.platforms = [
|
|||||||
{
|
{
|
||||||
_id: ObjectId('5ceb909ef204f241e886378f'),
|
_id: ObjectId('5ceb909ef204f241e886378f'),
|
||||||
name: 'QQ 玩一玩',
|
name: 'QQ 玩一玩',
|
||||||
name_en: 'qq',
|
name_en: 'sq',
|
||||||
platform_id: '6002',
|
platform_id: '6002',
|
||||||
comment: ''
|
comment: ''
|
||||||
},
|
},
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^0.18.0",
|
||||||
"biguint-format": "^1.0.1",
|
"biguint-format": "^1.0.1",
|
||||||
"bluebird": "^3.5.4",
|
"bluebird": "^3.5.4",
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
@ -46,6 +47,7 @@
|
|||||||
"redis": "^2.8.0",
|
"redis": "^2.8.0",
|
||||||
"request": "^2.88.0",
|
"request": "^2.88.0",
|
||||||
"serve-favicon": "^2.5.0",
|
"serve-favicon": "^2.5.0",
|
||||||
|
"ssha": "^1.0.1",
|
||||||
"yargs": "^13.2.4"
|
"yargs": "^13.2.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -1,15 +1,47 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
|
import GameInfo from '../../models/admin/GameInfo';
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
// 获取平台列表
|
// 接收ftp账号
|
||||||
router.post('/minigame', async (req, res, next) => {
|
router.post('/minigame', async (req, res, next) => {
|
||||||
const body = req.body;
|
const body = req.body;
|
||||||
try {
|
try {
|
||||||
console.log(body);
|
if (body.type === 'minigame_ftp') {
|
||||||
res.send({
|
const search = await GameInfo.findOne({ game_id: body.game_id, deleted: false });
|
||||||
errcode: 0,
|
if (search) {
|
||||||
body
|
// 已有账号 存储相应平台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) {
|
} catch (err) {
|
||||||
next(err);
|
next(err);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
import GameInfo from '../../models/admin/GameInfo';
|
import GameInfo from '../../models/admin/GameInfo';
|
||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import { userInfo } from 'os';
|
import { userInfo } from 'os';
|
||||||
|
import axios from 'axios';
|
||||||
|
import config from '../../../config/config';
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
@ -143,8 +145,7 @@ const router = new Router();
|
|||||||
// 获取游戏列表
|
// 获取游戏列表
|
||||||
router.get('/list', async (req, res, next) => {
|
router.get('/list', async (req, res, next) => {
|
||||||
const query = req.query || {};
|
const query = req.query || {};
|
||||||
const userPerms = req.user.permissions
|
const userPerms = req.user.permissions;
|
||||||
console.log(req.query)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let search = [];
|
let search = [];
|
||||||
@ -152,19 +153,18 @@ router.get('/list', async (req, res, next) => {
|
|||||||
if (query.type === 'all') {
|
if (query.type === 'all') {
|
||||||
// 返回所有游戏信息(仅包含游戏_id与游戏名)
|
// 返回所有游戏信息(仅包含游戏_id与游戏名)
|
||||||
result = await GameInfo.find({ deleted: false });
|
result = await GameInfo.find({ deleted: false });
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// TODO: 只返回有权限查阅的游戏
|
// TODO: 只返回有权限查阅的游戏
|
||||||
search = await GameInfo.find({ deleted: false });
|
search = await GameInfo.find({ deleted: false });
|
||||||
result = search.filter(game => {
|
result = search.filter(game => {
|
||||||
const uid = game._id
|
const uid = game._id;
|
||||||
return userPerms.includes(`${uid}-readable`) || userPerms.includes(`${uid}-edit`) || userPerms.includes(`${uid}-publish`)
|
return (
|
||||||
})
|
userPerms.includes(`${uid}-readable`) ||
|
||||||
|
userPerms.includes(`${uid}-edit`) ||
|
||||||
|
userPerms.includes(`${uid}-publish`)
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(result)
|
|
||||||
|
|
||||||
|
|
||||||
res.send({
|
res.send({
|
||||||
errcode: 0,
|
errcode: 0,
|
||||||
@ -195,7 +195,6 @@ router.post('/save', async (req, res, next) => {
|
|||||||
} else {
|
} else {
|
||||||
const newGameInfo = new GameInfo(body);
|
const newGameInfo = new GameInfo(body);
|
||||||
const result = await newGameInfo.save();
|
const result = await newGameInfo.save();
|
||||||
console.log(result);
|
|
||||||
res.send({
|
res.send({
|
||||||
errcode: 0,
|
errcode: 0,
|
||||||
gameInfo: result
|
gameInfo: result
|
||||||
@ -240,7 +239,7 @@ router.post('/update', async (req, res, next) => {
|
|||||||
deleted: false
|
deleted: false
|
||||||
});
|
});
|
||||||
if (search) {
|
if (search) {
|
||||||
const result = await GameInfo.update(
|
const result = await GameInfo.updateOne(
|
||||||
{
|
{
|
||||||
_id: body._id,
|
_id: body._id,
|
||||||
deleted: false
|
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;
|
export default router;
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import ldap from 'ldapjs';
|
import ldap from 'ldapjs';
|
||||||
|
import ssha from 'ssha';
|
||||||
import config from '../../../config/config';
|
import config from '../../../config/config';
|
||||||
import { User, LdapUser } from '../../models/admin/User';
|
import { User, LdapUser } from '../../models/admin/User';
|
||||||
import { combPer, combRole } from '../../utils/comb-permissions';
|
import { combPer, combRole } from '../../utils/comb-permissions';
|
||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
|
import logger from '../../utils/logger';
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
router.get('/list', async function userListCtrl(req, res, next) {
|
router.get('/list', async function userListCtrl(req, res, next) {
|
||||||
|
logger.db(req, '系统管理', '用户列表', '获取用户列表');
|
||||||
const client = ldap.createClient({
|
const client = ldap.createClient({
|
||||||
url: config.ldap.url
|
url: config.ldap.url
|
||||||
});
|
});
|
||||||
@ -112,7 +115,9 @@ router.post('/edit', async function userEditCtrl(req, res, next) {
|
|||||||
|
|
||||||
router.post('/save', async (req, res, next) => {
|
router.post('/save', async (req, res, next) => {
|
||||||
const body = req.body;
|
const body = req.body;
|
||||||
|
console.log(body);
|
||||||
const dn = `cn=${body.fullname},ou=people,dc=kingsome,dc=cn`;
|
const dn = `cn=${body.fullname},ou=people,dc=kingsome,dc=cn`;
|
||||||
|
const uidNumber = randomUid();
|
||||||
const entry = {
|
const entry = {
|
||||||
cn: body.fullname,
|
cn: body.fullname,
|
||||||
sn: body.fullname,
|
sn: body.fullname,
|
||||||
@ -122,7 +127,12 @@ router.post('/save', async (req, res, next) => {
|
|||||||
'organizationalPerson',
|
'organizationalPerson',
|
||||||
'person'
|
'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({
|
const client = ldap.createClient({
|
||||||
url: config.ldap.url
|
url: config.ldap.url
|
||||||
@ -131,15 +141,26 @@ router.post('/save', async (req, res, next) => {
|
|||||||
try {
|
try {
|
||||||
client.bind(config.ldap.user, config.ldap.password, function(err, bindRes) {
|
client.bind(config.ldap.user, config.ldap.password, function(err, bindRes) {
|
||||||
if (err) next(err);
|
if (err) next(err);
|
||||||
client.add(dn, entry, function(err) {
|
client.add(dn, entry, async function(err) {
|
||||||
if (err) console.log(err);
|
if (err) {
|
||||||
// res.send({
|
if (err.message === 'Entry Already Exists') {
|
||||||
// errcode: 0
|
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) {
|
} 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;
|
export default router;
|
||||||
|
@ -8,7 +8,7 @@ const ObjectId = Schema.Types.ObjectId;
|
|||||||
*/
|
*/
|
||||||
const OpLog = new mongoose.Schema({
|
const OpLog = new mongoose.Schema({
|
||||||
// 游戏id
|
// 游戏id
|
||||||
admin: {type: ObjectId, ref: 'Admin'},
|
fullname: {type: String},
|
||||||
username: {type: String},
|
username: {type: String},
|
||||||
method: {type: String},
|
method: {type: String},
|
||||||
show_name: {type: String},
|
show_name: {type: String},
|
||||||
@ -18,10 +18,13 @@ const OpLog = new mongoose.Schema({
|
|||||||
referer: {type: String},
|
referer: {type: String},
|
||||||
// 请求的param
|
// 请求的param
|
||||||
params: {type: Schema.Types.Mixed},
|
params: {type: Schema.Types.Mixed},
|
||||||
|
// 补充信息
|
||||||
|
info: {type: Schema.Types.Mixed},
|
||||||
// ip
|
// ip
|
||||||
ip: {type: String},
|
ip: {type: String},
|
||||||
// 备注
|
type: {type: String},
|
||||||
comment: {type: String},
|
sub_type: {type: String},
|
||||||
|
content: {type: String}
|
||||||
}, {
|
}, {
|
||||||
collection: 'op_logs',
|
collection: 'op_logs',
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
|
@ -3,7 +3,7 @@ import fs from 'fs-extra';
|
|||||||
import FileStreamRotator from 'file-stream-rotator';
|
import FileStreamRotator from 'file-stream-rotator';
|
||||||
import bunyan from 'bunyan';
|
import bunyan from 'bunyan';
|
||||||
import config from '../../config/config';
|
import config from '../../config/config';
|
||||||
import AdminLog from '../models/admin/AdminLog';
|
import OpLog from '../models/admin/OpLog';
|
||||||
|
|
||||||
|
|
||||||
const env = process.env.NODE_ENV || 'development';
|
const env = process.env.NODE_ENV || 'development';
|
||||||
@ -98,22 +98,24 @@ export default {
|
|||||||
logger.fatal(obj);
|
logger.fatal(obj);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
db(req, logObj, name) {
|
db(req, type, subType, content, info) {
|
||||||
const user = req.user;
|
const user = req.user;
|
||||||
const ip = req.headers['x-forwarded-for'];
|
const ip = req.headers['x-forwarded-for'];
|
||||||
const path = req.baseUrl + req.path;
|
const path = req.baseUrl + req.path;
|
||||||
const params = req.method === 'GET' ? req.query : req.body;
|
const params = req.method === 'GET' ? req.query : req.body;
|
||||||
const dataObj = JSON.stringify(logObj) === '{}' ? params : logObj;
|
const obj = new OpLog({
|
||||||
const obj = new AdminLog({
|
fullname: user.fullname,
|
||||||
admin: user.id,
|
|
||||||
username: user.username,
|
username: user.username,
|
||||||
path: path,
|
path: path,
|
||||||
method: req.method,
|
method: req.method,
|
||||||
params: dataObj,
|
params: params,
|
||||||
referer: req.headers['referer'],
|
referer: req.headers['referer'],
|
||||||
user_agent: req.headers['user-agent'],
|
user_agent: req.headers['user-agent'],
|
||||||
ip: ip,
|
ip: ip,
|
||||||
show_name: name,
|
type: type,
|
||||||
|
sub_type: subType,
|
||||||
|
content: content,
|
||||||
|
info: info || {},
|
||||||
});
|
});
|
||||||
obj.save().then(()=>{}).catch((err)=> {
|
obj.save().then(()=>{}).catch((err)=> {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user