Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports.add = function* add (next) {
let body = yield parse.form(this);
// create a new user
let username = body.username;
let password = body.password;
let penName = body.penName;
let groupName = body.groupName;
let avatar = body.avatar;
let introduce = body.introduce;
if (!username || !password || !penName || !groupName) {
this.status = 400;
this.body = {
statusCode: 400,
reasonPhrase: "Bad Request",
description: "username, password, penName, groupName is required, and must be not void",
errorCode: 2000
return async function parseFormBody(ctx, next) {
if (!ctx.request.is('urlencoded')) {
return ctx.throw(400, 'expected x-www-form-urlencoded');
}
// eslint-disable-next-line require-atomic-updates
ctx.request.body = ctx.request.body || await parse.form(ctx, opts);
await next();
};
}
module.exports.add = function* add (next) {
let body = yield parse.form(this);
let groupName = body.groupName;
let description = body.description;
if (!groupName) {
// groupName can not be void
this.status = 400;
this.body = {
statusCode: 400,
reasonPhrase: "Bad Request",
description: "groupName can not be void",
errorCode: 5000
};
return ;
}
module.exports.update = function* update (next) {
// get user from checkUser
let user = this.user;
let body = yield parse.form(this);
// check which field need to update
let username = "";
let password = "";
let penName = "";
let introduce = "";
let updater = {};
if ("username" in body) {
username = body.username;
if (!username) {
this.status = 400;
this.body = {
statusCode: 400,
* _parse (request) {
let formBody = {
fields: {},
files: {},
raw: null
}
if (request.is(contentTypes.json)) {
formBody.fields = yield coBody.json(request.request, this.formOptions)
} else if (request.is(contentTypes.form)) {
formBody.fields = yield coBody.form(request.request, this.formOptions)
} else if (request.is(contentTypes.text)) {
formBody.raw = yield coBody.text(request.request, this.formOptions)
} else if (request.is(contentTypes.multipart)) {
formBody = yield this._multipart(request, this.uploadOptions)
}
return formBody
}
return next()
}
const { files, fields } = await processMultipart(request['multipart'], multipartConfig)
request.setInitialBody(fields)
request['_files'] = files
return next()
}
/**
* Handle url-encoded form data
*/
const formConfig = this._getConfigFor('form')
if (this._isType(request, formConfig.types)) {
try {
const { parsed, raw } = await coBody.form(request.request, formConfig)
request.setInitialBody(parsed)
request.updateRawBody(raw)
return next()
} catch (error) {
throw this._getExceptionFor(error)
}
}
/**
* Handle content with JSON types
*/
const jsonConfig = this._getConfigFor('json')
if (this._isType(request, jsonConfig.types)) {
try {
const { parsed, raw } = await coBody.json(request.request, jsonConfig)
request.setInitialBody(parsed)
export async function parseBody(request: any) {
let body: any = {};
if (request.is('json')) {
body.fields = await buddy.json(request.req);
} else if (request.is('urlencoded')) {
body.fields = await buddy.form(request.req);
} else if (request.is('text')) {
body.fields = await buddy.text(request.req);
} else if (request.is('multipart')) {
body = await parseForm(request.req);
}
return body;
};
return yield new Promise((resolve, reject) => {
parse.form(koaContext).then(resolve).catch(reject);
});
}
function* (next) {
let body = yield parse.form(this);
let tagName = body.tagName;
if (!tagName) {
this.status = 400;
this.body = {
statusCode: 400,
reasonPhrase: "Bad Request",
description: "tag's name can not be void",
errorCode: 4001
};
return ;
}
let transaction = yield sequelize.transaction();
try {
async function parseBody(ctx) {
if (enableJson && ((detectJSON && detectJSON(ctx)) || ctx.request.is(jsonTypes))) {
return await parse.json(ctx, jsonOpts);
}
if (enableForm && ctx.request.is(formTypes)) {
return await parse.form(ctx, formOpts);
}
if (enableText && ctx.request.is(textTypes)) {
return await parse.text(ctx, textOpts) || '';
}
return {};
}
};