mirror of
https://github.com/YMFE/yapi.git
synced 2025-03-07 14:16:52 +08:00
feat: params trim
This commit is contained in:
parent
2b8eb63fbf
commit
be42920b36
@ -23,6 +23,10 @@ class groupController extends baseController{
|
||||
*/
|
||||
async add(ctx) {
|
||||
let params = ctx.request.body;
|
||||
params = yapi.commons.handleParams(params, {
|
||||
group_name: 'string',
|
||||
group_desc: 'string'
|
||||
})
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
|
||||
}
|
||||
@ -38,7 +42,7 @@ class groupController extends baseController{
|
||||
let data = {
|
||||
group_name: params.group_name,
|
||||
group_desc: params.group_desc,
|
||||
uid: '0',
|
||||
uid: this.getUid(),
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
}
|
||||
@ -124,6 +128,12 @@ class groupController extends baseController{
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
|
||||
}
|
||||
try{
|
||||
|
||||
ctx.request.body = yapi.commons.handleParams(ctx.request.body, {
|
||||
id: 'number',
|
||||
group_name: 'string',
|
||||
group_desc: 'string'
|
||||
})
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
let id = ctx.request.body.id;
|
||||
let data = {};
|
||||
|
@ -37,6 +37,12 @@ class interfaceController extends baseController{
|
||||
*/
|
||||
async add(ctx){
|
||||
let params = ctx.request.body;
|
||||
params = yapi.commons.handleParams(params, {
|
||||
title: 'string',
|
||||
path: 'string',
|
||||
method: 'string',
|
||||
desc: 'string'
|
||||
})
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase()
|
||||
params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json';
|
||||
@ -159,6 +165,12 @@ class interfaceController extends baseController{
|
||||
|
||||
async up(ctx){
|
||||
let params = ctx.request.body;
|
||||
params = yapi.commons.handleParams(params, {
|
||||
title: 'string',
|
||||
path: 'string',
|
||||
method: 'string',
|
||||
desc: 'string'
|
||||
})
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase()
|
||||
let id = ctx.request.body.id;
|
||||
|
@ -49,7 +49,14 @@ class projectController extends baseController {
|
||||
*/
|
||||
async add(ctx) {
|
||||
let params = ctx.request.body;
|
||||
|
||||
params = yapi.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
basepath: 'string',
|
||||
prd_host: 'string',
|
||||
protocol: 'string',
|
||||
group_id: 'number',
|
||||
desc: 'string'
|
||||
})
|
||||
if(!params.group_id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
|
||||
}
|
||||
@ -322,6 +329,14 @@ class projectController extends baseController {
|
||||
try{
|
||||
let id = ctx.request.body.id;
|
||||
let params = ctx.request.body;
|
||||
params = yapi.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
basepath: 'string',
|
||||
prd_host: 'string',
|
||||
protocol: 'string',
|
||||
group_id: 'number',
|
||||
desc: 'string'
|
||||
})
|
||||
if(!id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
|
||||
}
|
||||
|
@ -241,6 +241,13 @@ class userController extends baseController {
|
||||
async reg(ctx) { //注册
|
||||
var userInst = yapi.getInst(userModel);
|
||||
let params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码
|
||||
|
||||
params = yapi.commons.handleParams(params, {
|
||||
username: 'string',
|
||||
password: 'string',
|
||||
email: 'string'
|
||||
})
|
||||
|
||||
if (!params.email) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '邮箱不能为空');
|
||||
}
|
||||
@ -395,6 +402,10 @@ class userController extends baseController {
|
||||
async update(ctx){ //更新用户信息
|
||||
try{
|
||||
let params = ctx.request.body;
|
||||
params = yapi.commons.handleParams(params, {
|
||||
username: 'string',
|
||||
email: 'string'
|
||||
})
|
||||
if(this.getRole() !== 'admin' && params.uid != this.getUid()){
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
|
||||
}
|
||||
|
@ -107,14 +107,14 @@ exports.sendMail = (options, cb) => {
|
||||
}
|
||||
|
||||
}
|
||||
try{
|
||||
try {
|
||||
yapi.mail.sendMail({
|
||||
from: yapi.WEBCONFIG.mail.auth.user,
|
||||
to: options.to,
|
||||
subject: 'yapi平台',
|
||||
html: options.contents
|
||||
from: yapi.WEBCONFIG.mail.auth.user,
|
||||
to: options.to,
|
||||
subject: 'yapi平台',
|
||||
html: options.contents
|
||||
}, cb)
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.error(e.message)
|
||||
}
|
||||
}
|
||||
@ -150,4 +150,41 @@ exports.verifyPath = (path) => {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function trim(str) {
|
||||
if (!str) return str;
|
||||
str = str + '';
|
||||
return str.replace(/(^\s*)|(\s*$)/g, "");
|
||||
}
|
||||
|
||||
function ltrim(str) {
|
||||
if (!str) return str;
|
||||
str = str + '';
|
||||
return str.replace(/(^\s*)/g, "");
|
||||
}
|
||||
|
||||
function rtrim(str) {
|
||||
if (!str) return str;
|
||||
str = str + '';
|
||||
return str.replace(/(\s*$)/g, "");
|
||||
}
|
||||
|
||||
exports.trim = trim;
|
||||
exports.ltrim = ltrim;
|
||||
exports.rtrim = rtrim;
|
||||
|
||||
exports.handleParams = (params, keys) => {
|
||||
if (!params || typeof params !== 'object' || !keys || typeof keys !== 'object') return false;
|
||||
for (var key in keys) {
|
||||
var filter = keys[key];
|
||||
if (params[key]) {
|
||||
switch (filter) {
|
||||
case 'string': params[key] = trim(params[key] + ''); break;
|
||||
case 'number': params[key] = parseInt(params[key], 10); break;
|
||||
default: params[key] = trim(params + '');
|
||||
}
|
||||
}
|
||||
}
|
||||
return params;
|
||||
}
|
@ -83,68 +83,73 @@ var groupController = function (_baseController) {
|
||||
case 0:
|
||||
params = ctx.request.body;
|
||||
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
group_name: 'string',
|
||||
group_desc: 'string'
|
||||
});
|
||||
|
||||
if (!(this.getRole() !== 'admin')) {
|
||||
_context.next = 3;
|
||||
_context.next = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
|
||||
|
||||
case 3:
|
||||
case 4:
|
||||
if (params.group_name) {
|
||||
_context.next = 5;
|
||||
_context.next = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组名不能为空'));
|
||||
|
||||
case 5:
|
||||
case 6:
|
||||
groupInst = _yapi2.default.getInst(_group2.default);
|
||||
_context.next = 8;
|
||||
_context.next = 9;
|
||||
return groupInst.checkRepeat(params.group_name);
|
||||
|
||||
case 8:
|
||||
case 9:
|
||||
checkRepeat = _context.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context.next = 11;
|
||||
_context.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '项目分组名已存在'));
|
||||
|
||||
case 11:
|
||||
case 12:
|
||||
data = {
|
||||
group_name: params.group_name,
|
||||
group_desc: params.group_desc,
|
||||
uid: '0',
|
||||
uid: this.getUid(),
|
||||
add_time: _yapi2.default.commons.time(),
|
||||
up_time: _yapi2.default.commons.time()
|
||||
};
|
||||
_context.prev = 12;
|
||||
_context.next = 15;
|
||||
_context.prev = 13;
|
||||
_context.next = 16;
|
||||
return groupInst.save(data);
|
||||
|
||||
case 15:
|
||||
case 16:
|
||||
result = _context.sent;
|
||||
|
||||
result = _yapi2.default.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid']);
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context.next = 23;
|
||||
_context.next = 24;
|
||||
break;
|
||||
|
||||
case 20:
|
||||
_context.prev = 20;
|
||||
_context.t0 = _context['catch'](12);
|
||||
case 21:
|
||||
_context.prev = 21;
|
||||
_context.t0 = _context['catch'](13);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
|
||||
|
||||
case 23:
|
||||
case 24:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, this, [[12, 20]]);
|
||||
}, _callee, this, [[13, 21]]);
|
||||
}));
|
||||
|
||||
function add(_x) {
|
||||
@ -323,6 +328,13 @@ var groupController = function (_baseController) {
|
||||
|
||||
case 2:
|
||||
_context4.prev = 2;
|
||||
|
||||
|
||||
ctx.request.body = _yapi2.default.commons.handleParams(ctx.request.body, {
|
||||
id: 'number',
|
||||
group_name: 'string',
|
||||
group_desc: 'string'
|
||||
});
|
||||
groupInst = _yapi2.default.getInst(_group2.default);
|
||||
id = ctx.request.body.id;
|
||||
data = {};
|
||||
@ -332,28 +344,28 @@ var groupController = function (_baseController) {
|
||||
if ((0, _keys2.default)(data).length === 0) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 404, '分组名和分组描述不能为空');
|
||||
}
|
||||
_context4.next = 11;
|
||||
_context4.next = 12;
|
||||
return groupInst.up(id, data);
|
||||
|
||||
case 11:
|
||||
case 12:
|
||||
result = _context4.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context4.next = 18;
|
||||
_context4.next = 19;
|
||||
break;
|
||||
|
||||
case 15:
|
||||
_context4.prev = 15;
|
||||
case 16:
|
||||
_context4.prev = 16;
|
||||
_context4.t0 = _context4['catch'](2);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
|
||||
|
||||
case 18:
|
||||
case 19:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this, [[2, 15]]);
|
||||
}, _callee4, this, [[2, 16]]);
|
||||
}));
|
||||
|
||||
function up(_x4) {
|
||||
|
@ -94,49 +94,55 @@ var interfaceController = function (_baseController) {
|
||||
case 0:
|
||||
params = ctx.request.body;
|
||||
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
title: 'string',
|
||||
path: 'string',
|
||||
method: 'string',
|
||||
desc: 'string'
|
||||
});
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase();
|
||||
params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json';
|
||||
|
||||
if (params.project_id) {
|
||||
_context.next = 6;
|
||||
_context.next = 7;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
|
||||
|
||||
case 6:
|
||||
case 7:
|
||||
if (params.path) {
|
||||
_context.next = 8;
|
||||
_context.next = 9;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口请求路径不能为空'));
|
||||
|
||||
case 8:
|
||||
case 9:
|
||||
if (_yapi2.default.commons.verifyPath(params.path)) {
|
||||
_context.next = 10;
|
||||
_context.next = 11;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/'));
|
||||
|
||||
case 10:
|
||||
_context.next = 12;
|
||||
case 11:
|
||||
_context.next = 13;
|
||||
return this.Model.checkRepeat(params.path, params.method);
|
||||
|
||||
case 12:
|
||||
case 13:
|
||||
checkRepeat = _context.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context.next = 15;
|
||||
_context.next = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']'));
|
||||
|
||||
case 15:
|
||||
_context.prev = 15;
|
||||
case 16:
|
||||
_context.prev = 16;
|
||||
data = {
|
||||
project_id: params.project_id,
|
||||
title: params.title,
|
||||
@ -156,28 +162,28 @@ var interfaceController = function (_baseController) {
|
||||
if (params.req_params_form) data.req_params_form = params.req_params_form;
|
||||
if (params.req_params_other) data.req_params_other = params.req_params_other;
|
||||
|
||||
_context.next = 21;
|
||||
_context.next = 22;
|
||||
return this.Model.save(data);
|
||||
|
||||
case 21:
|
||||
case 22:
|
||||
result = _context.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context.next = 28;
|
||||
_context.next = 29;
|
||||
break;
|
||||
|
||||
case 25:
|
||||
_context.prev = 25;
|
||||
_context.t0 = _context['catch'](15);
|
||||
case 26:
|
||||
_context.prev = 26;
|
||||
_context.t0 = _context['catch'](16);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
|
||||
|
||||
case 28:
|
||||
case 29:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, this, [[15, 25]]);
|
||||
}, _callee, this, [[16, 26]]);
|
||||
}));
|
||||
|
||||
function add(_x) {
|
||||
@ -349,51 +355,57 @@ var interfaceController = function (_baseController) {
|
||||
case 0:
|
||||
params = ctx.request.body;
|
||||
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
title: 'string',
|
||||
path: 'string',
|
||||
method: 'string',
|
||||
desc: 'string'
|
||||
});
|
||||
params.method = params.method || 'GET';
|
||||
params.method = params.method.toUpperCase();
|
||||
id = ctx.request.body.id;
|
||||
|
||||
if (id) {
|
||||
_context4.next = 6;
|
||||
_context4.next = 7;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口id不能为空'));
|
||||
|
||||
case 6:
|
||||
_context4.next = 8;
|
||||
case 7:
|
||||
_context4.next = 9;
|
||||
return this.Model.get(id);
|
||||
|
||||
case 8:
|
||||
case 9:
|
||||
interfaceData = _context4.sent;
|
||||
|
||||
if (!(params.path && !_yapi2.default.commons.verifyPath(params.path))) {
|
||||
_context4.next = 11;
|
||||
_context4.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/'));
|
||||
|
||||
case 11:
|
||||
case 12:
|
||||
if (!(params.path && params.path !== interfaceData.path && params.method !== interfaceData.method)) {
|
||||
_context4.next = 17;
|
||||
_context4.next = 18;
|
||||
break;
|
||||
}
|
||||
|
||||
_context4.next = 14;
|
||||
_context4.next = 15;
|
||||
return this.Model.checkRepeat(params.path, params.method);
|
||||
|
||||
case 14:
|
||||
case 15:
|
||||
checkRepeat = _context4.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context4.next = 17;
|
||||
_context4.next = 18;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']'));
|
||||
|
||||
case 17:
|
||||
case 18:
|
||||
data = {
|
||||
up_time: _yapi2.default.commons.time()
|
||||
};
|
||||
@ -412,29 +424,29 @@ var interfaceController = function (_baseController) {
|
||||
if (params.res_body_type) data.res_body_type = params.res_body_type;
|
||||
if (params.res_body) data.res_body = params.res_body;
|
||||
|
||||
_context4.prev = 27;
|
||||
_context4.next = 30;
|
||||
_context4.prev = 28;
|
||||
_context4.next = 31;
|
||||
return this.Model.up(id, data);
|
||||
|
||||
case 30:
|
||||
case 31:
|
||||
result = _context4.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context4.next = 37;
|
||||
_context4.next = 38;
|
||||
break;
|
||||
|
||||
case 34:
|
||||
_context4.prev = 34;
|
||||
_context4.t0 = _context4['catch'](27);
|
||||
case 35:
|
||||
_context4.prev = 35;
|
||||
_context4.t0 = _context4['catch'](28);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
|
||||
|
||||
case 37:
|
||||
case 38:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this, [[27, 34]]);
|
||||
}, _callee4, this, [[28, 35]]);
|
||||
}));
|
||||
|
||||
function up(_x4) {
|
||||
|
@ -119,82 +119,91 @@ var projectController = function (_baseController) {
|
||||
case 0:
|
||||
params = ctx.request.body;
|
||||
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
basepath: 'string',
|
||||
prd_host: 'string',
|
||||
protocol: 'string',
|
||||
group_id: 'number',
|
||||
desc: 'string'
|
||||
});
|
||||
|
||||
if (params.group_id) {
|
||||
_context.next = 3;
|
||||
_context.next = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
|
||||
|
||||
case 3:
|
||||
case 4:
|
||||
if (params.name) {
|
||||
_context.next = 5;
|
||||
_context.next = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目名不能为空'));
|
||||
|
||||
case 5:
|
||||
_context.next = 7;
|
||||
case 6:
|
||||
_context.next = 8;
|
||||
return this.Model.checkNameRepeat(params.name);
|
||||
|
||||
case 7:
|
||||
case 8:
|
||||
checkRepeat = _context.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context.next = 10;
|
||||
_context.next = 11;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
||||
|
||||
case 10:
|
||||
case 11:
|
||||
if (params.basepath) {
|
||||
_context.next = 12;
|
||||
_context.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目basepath不能为空'));
|
||||
|
||||
case 12:
|
||||
case 13:
|
||||
if (params.prd_host) {
|
||||
_context.next = 14;
|
||||
_context.next = 15;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目domain不能为空'));
|
||||
|
||||
case 14:
|
||||
case 15:
|
||||
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
|
||||
_context.next = 16;
|
||||
_context.next = 17;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
|
||||
|
||||
case 16:
|
||||
case 17:
|
||||
if (this.verifyDomain(params.prd_host)) {
|
||||
_context.next = 18;
|
||||
_context.next = 19;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误'));
|
||||
|
||||
case 18:
|
||||
_context.next = 20;
|
||||
case 19:
|
||||
_context.next = 21;
|
||||
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
||||
|
||||
case 20:
|
||||
case 21:
|
||||
checkRepeatDomain = _context.sent;
|
||||
|
||||
if (!(checkRepeatDomain > 0)) {
|
||||
_context.next = 23;
|
||||
_context.next = 24;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
|
||||
|
||||
case 23:
|
||||
case 24:
|
||||
data = {
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
@ -207,29 +216,29 @@ var projectController = function (_baseController) {
|
||||
add_time: _yapi2.default.commons.time(),
|
||||
up_time: _yapi2.default.commons.time()
|
||||
};
|
||||
_context.prev = 24;
|
||||
_context.next = 27;
|
||||
_context.prev = 25;
|
||||
_context.next = 28;
|
||||
return this.Model.save(data);
|
||||
|
||||
case 27:
|
||||
case 28:
|
||||
result = _context.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context.next = 34;
|
||||
_context.next = 35;
|
||||
break;
|
||||
|
||||
case 31:
|
||||
_context.prev = 31;
|
||||
_context.t0 = _context['catch'](24);
|
||||
case 32:
|
||||
_context.prev = 32;
|
||||
_context.t0 = _context['catch'](25);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
|
||||
|
||||
case 34:
|
||||
case 35:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, this, [[24, 31]]);
|
||||
}, _callee, this, [[25, 32]]);
|
||||
}));
|
||||
|
||||
function add(_x) {
|
||||
@ -750,50 +759,59 @@ var projectController = function (_baseController) {
|
||||
id = ctx.request.body.id;
|
||||
params = ctx.request.body;
|
||||
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
basepath: 'string',
|
||||
prd_host: 'string',
|
||||
protocol: 'string',
|
||||
group_id: 'number',
|
||||
desc: 'string'
|
||||
});
|
||||
|
||||
if (id) {
|
||||
_context8.next = 5;
|
||||
_context8.next = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空'));
|
||||
|
||||
case 5:
|
||||
_context8.next = 7;
|
||||
case 6:
|
||||
_context8.next = 8;
|
||||
return this.jungeMemberAuth(id, this.getUid());
|
||||
|
||||
case 7:
|
||||
case 8:
|
||||
_context8.t0 = _context8.sent;
|
||||
|
||||
if (!(_context8.t0 !== true)) {
|
||||
_context8.next = 10;
|
||||
_context8.next = 11;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
|
||||
|
||||
case 10:
|
||||
_context8.next = 12;
|
||||
case 11:
|
||||
_context8.next = 13;
|
||||
return this.Model.get(id);
|
||||
|
||||
case 12:
|
||||
case 13:
|
||||
projectData = _context8.sent;
|
||||
|
||||
if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) {
|
||||
_context8.next = 15;
|
||||
_context8.next = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误'));
|
||||
|
||||
case 15:
|
||||
case 16:
|
||||
if (this.verifyDomain(params.prd_host)) {
|
||||
_context8.next = 17;
|
||||
_context8.next = 18;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误'));
|
||||
|
||||
case 17:
|
||||
case 18:
|
||||
|
||||
if (projectData.name === params.name) {
|
||||
delete params.name;
|
||||
@ -804,43 +822,43 @@ var projectController = function (_baseController) {
|
||||
}
|
||||
|
||||
if (!params.name) {
|
||||
_context8.next = 25;
|
||||
_context8.next = 26;
|
||||
break;
|
||||
}
|
||||
|
||||
_context8.next = 22;
|
||||
_context8.next = 23;
|
||||
return this.Model.checkNameRepeat(params.name);
|
||||
|
||||
case 22:
|
||||
case 23:
|
||||
checkRepeat = _context8.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context8.next = 25;
|
||||
_context8.next = 26;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
|
||||
|
||||
case 25:
|
||||
case 26:
|
||||
if (!(params.basepath && params.prd_host)) {
|
||||
_context8.next = 31;
|
||||
_context8.next = 32;
|
||||
break;
|
||||
}
|
||||
|
||||
_context8.next = 28;
|
||||
_context8.next = 29;
|
||||
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
||||
|
||||
case 28:
|
||||
case 29:
|
||||
checkRepeatDomain = _context8.sent;
|
||||
|
||||
if (!(checkRepeatDomain > 0)) {
|
||||
_context8.next = 31;
|
||||
_context8.next = 32;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
|
||||
|
||||
case 31:
|
||||
case 32:
|
||||
data = {
|
||||
uid: this.getUid(),
|
||||
up_time: _yapi2.default.commons.time()
|
||||
@ -856,28 +874,28 @@ var projectController = function (_baseController) {
|
||||
if (params.protocol) data.protocol = params.protocol;
|
||||
if (params.env) data.env = params.env;
|
||||
|
||||
_context8.next = 39;
|
||||
_context8.next = 40;
|
||||
return this.Model.up(id, data);
|
||||
|
||||
case 39:
|
||||
case 40:
|
||||
result = _context8.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context8.next = 46;
|
||||
_context8.next = 47;
|
||||
break;
|
||||
|
||||
case 43:
|
||||
_context8.prev = 43;
|
||||
case 44:
|
||||
_context8.prev = 44;
|
||||
_context8.t1 = _context8['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t1.message);
|
||||
|
||||
case 46:
|
||||
case 47:
|
||||
case 'end':
|
||||
return _context8.stop();
|
||||
}
|
||||
}
|
||||
}, _callee8, this, [[0, 43]]);
|
||||
}, _callee8, this, [[0, 44]]);
|
||||
}));
|
||||
|
||||
function up(_x8) {
|
||||
|
@ -547,36 +547,42 @@ var userController = function (_baseController) {
|
||||
userInst = _yapi2.default.getInst(_user2.default);
|
||||
params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码
|
||||
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
username: 'string',
|
||||
password: 'string',
|
||||
email: 'string'
|
||||
});
|
||||
|
||||
if (params.email) {
|
||||
_context8.next = 4;
|
||||
_context8.next = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '邮箱不能为空'));
|
||||
|
||||
case 4:
|
||||
case 5:
|
||||
if (params.password) {
|
||||
_context8.next = 6;
|
||||
_context8.next = 7;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '密码不能为空'));
|
||||
|
||||
case 6:
|
||||
_context8.next = 8;
|
||||
case 7:
|
||||
_context8.next = 9;
|
||||
return userInst.checkRepeat(params.email);
|
||||
|
||||
case 8:
|
||||
case 9:
|
||||
checkRepeat = _context8.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context8.next = 11;
|
||||
_context8.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '该email已经注册'));
|
||||
|
||||
case 11:
|
||||
case 12:
|
||||
passsalt = _yapi2.default.commons.randStr();
|
||||
data = {
|
||||
username: params.username,
|
||||
@ -591,11 +597,11 @@ var userController = function (_baseController) {
|
||||
if (!data.username) {
|
||||
data.username = data.email.substr(0, data.email.indexOf('@'));
|
||||
}
|
||||
_context8.prev = 14;
|
||||
_context8.next = 17;
|
||||
_context8.prev = 15;
|
||||
_context8.next = 18;
|
||||
return userInst.save(data);
|
||||
|
||||
case 17:
|
||||
case 18:
|
||||
user = _context8.sent;
|
||||
|
||||
this.setLoginCookie(user._id, user.passsalt);
|
||||
@ -612,21 +618,21 @@ var userController = function (_baseController) {
|
||||
to: user.email,
|
||||
contents: '<h3>\u4EB2\u7231\u7684\u7528\u6237\uFF1A</h3><p>\u60A8\u597D\uFF0C\u611F\u8C22\u4F7F\u7528YApi,\u60A8\u7684\u8D26\u53F7 ' + params.email + ' \u5DF2\u7ECF\u6CE8\u518C\u6210\u529F</p>'
|
||||
});
|
||||
_context8.next = 26;
|
||||
_context8.next = 27;
|
||||
break;
|
||||
|
||||
case 23:
|
||||
_context8.prev = 23;
|
||||
_context8.t0 = _context8['catch'](14);
|
||||
case 24:
|
||||
_context8.prev = 24;
|
||||
_context8.t0 = _context8['catch'](15);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 401, _context8.t0.message);
|
||||
|
||||
case 26:
|
||||
case 27:
|
||||
case 'end':
|
||||
return _context8.stop();
|
||||
}
|
||||
}
|
||||
}, _callee8, this, [[14, 23]]);
|
||||
}, _callee8, this, [[15, 24]]);
|
||||
}));
|
||||
|
||||
function reg(_x9) {
|
||||
@ -868,25 +874,30 @@ var userController = function (_baseController) {
|
||||
_context12.prev = 0;
|
||||
params = ctx.request.body;
|
||||
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
username: 'string',
|
||||
email: 'string'
|
||||
});
|
||||
|
||||
if (!(this.getRole() !== 'admin' && params.uid != this.getUid())) {
|
||||
_context12.next = 4;
|
||||
_context12.next = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
|
||||
|
||||
case 4:
|
||||
case 5:
|
||||
userInst = _yapi2.default.getInst(_user2.default);
|
||||
id = params.uid;
|
||||
|
||||
if (id) {
|
||||
_context12.next = 8;
|
||||
_context12.next = 9;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, 'uid不能为空'));
|
||||
|
||||
case 8:
|
||||
case 9:
|
||||
data = {
|
||||
|
||||
up_time: _yapi2.default.commons.time()
|
||||
@ -899,46 +910,46 @@ var userController = function (_baseController) {
|
||||
params.email && (data.email = params.email);
|
||||
|
||||
if (!data.email) {
|
||||
_context12.next = 18;
|
||||
_context12.next = 19;
|
||||
break;
|
||||
}
|
||||
|
||||
_context12.next = 15;
|
||||
_context12.next = 16;
|
||||
return userInst.checkRepeat(data.email);
|
||||
|
||||
case 15:
|
||||
case 16:
|
||||
checkRepeat = _context12.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context12.next = 18;
|
||||
_context12.next = 19;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '该email已经注册'));
|
||||
|
||||
case 18:
|
||||
_context12.next = 20;
|
||||
case 19:
|
||||
_context12.next = 21;
|
||||
return userInst.update(id, data);
|
||||
|
||||
case 20:
|
||||
case 21:
|
||||
result = _context12.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context12.next = 27;
|
||||
_context12.next = 28;
|
||||
break;
|
||||
|
||||
case 24:
|
||||
_context12.prev = 24;
|
||||
case 25:
|
||||
_context12.prev = 25;
|
||||
_context12.t0 = _context12['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context12.t0.message);
|
||||
|
||||
case 27:
|
||||
case 28:
|
||||
case 'end':
|
||||
return _context12.stop();
|
||||
}
|
||||
}
|
||||
}, _callee12, this, [[0, 24]]);
|
||||
}, _callee12, this, [[0, 25]]);
|
||||
}));
|
||||
|
||||
function update(_x13) {
|
||||
|
@ -171,4 +171,44 @@ exports.verifyPath = function (path) {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
function trim(str) {
|
||||
if (!str) return str;
|
||||
str = str + '';
|
||||
return str.replace(/(^\s*)|(\s*$)/g, "");
|
||||
}
|
||||
|
||||
function ltrim(str) {
|
||||
if (!str) return str;
|
||||
str = str + '';
|
||||
return str.replace(/(^\s*)/g, "");
|
||||
}
|
||||
|
||||
function rtrim(str) {
|
||||
if (!str) return str;
|
||||
str = str + '';
|
||||
return str.replace(/(\s*$)/g, "");
|
||||
}
|
||||
|
||||
exports.trim = trim;
|
||||
exports.ltrim = ltrim;
|
||||
exports.rtrim = rtrim;
|
||||
|
||||
exports.handleParams = function (params, keys) {
|
||||
if (!params || (typeof params === 'undefined' ? 'undefined' : (0, _typeof3.default)(params)) !== 'object' || !keys || (typeof keys === 'undefined' ? 'undefined' : (0, _typeof3.default)(keys)) !== 'object') return false;
|
||||
for (var key in keys) {
|
||||
var filter = keys[key];
|
||||
if (params[key]) {
|
||||
switch (filter) {
|
||||
case 'string':
|
||||
params[key] = trim(params[key] + '');break;
|
||||
case 'number':
|
||||
params[key] = parseInt(params[key], 10);break;
|
||||
default:
|
||||
params[key] = trim(params + '');
|
||||
}
|
||||
}
|
||||
}
|
||||
return params;
|
||||
};
|
Loading…
Reference in New Issue
Block a user