ref #356 resign, transfer

indiachan-spamvector
Thomas Lynch 3 years ago
parent 28761f1934
commit 6ceacdf3ff
  1. 26
      controllers/forms/resign.js
  2. 20
      controllers/forms/transfer.js

@ -16,25 +16,15 @@ module.exports = {
controller: async (req, res, next) => {
const errors = [];
if (!req.body.confirm) {
errors.push('Missing confirmation');
}
if (!req.body.board || req.body.board.length === 0) {
errors.push('You did not select a board');
} else if (alphaNumericRegex.test(req.body.board) !== true) {
errors.push('URI must contain a-z 0-9 only');
} else {
try {
const errors = checkSchema([
{ result: existsBody(req.body.confirm), expected: true, error: 'Missing confirmation' },
{ result: lengthBody(req.body.board, 1), expected: true, error: 'You did not select a board' },
{ result: alphaNumericRegex.test(req.body.board), expected: true, error: 'URI must contain a-z 0-9 only' },
{ result: async () => {
res.locals.board = await Boards.findOne(req.body.board);
} catch (err) {
return next(err);
}
if (!res.locals.board) {
errors.push(`Board /${req.body.board}/ does not exist`);
}
}
return res.locals.board != null;
}, expected: true, error: `Board /${req.body.board}/ does not exist` },
]);
if (errors.length > 0) {
return dynamicResponse(req, res, 400, 'message', {

@ -15,20 +15,12 @@ module.exports = {
controller: async (req, res, next) => {
const errors = [];
if (!req.body.username || req.body.username.length === 0) {
errors.push('Missing transfer username');
}
if (req.body.username && req.body.username.length > 50) {
errors.push('Transfer username must be 50 characters or less');
}
if (req.body.username === res.locals.board.owner) {
errors.push('New owner username must not be same as old owner');
}
if (alphaNumericRegex.test(req.body.username) !== true) {
errors.push('Username must contain a-z 0-9 only');
}
const errors = checkSchema([
{ result: existsBody(req.body.username), expected: true, error: 'Missing new owner username' },
{ result: lengthBody(req.body.username, 1, 50), expected: true, error: 'New owner username must be 50 characters or less' },
{ result: (req.body.username === res.locals.board.owner), expected: false, error: 'New owner must be different from current owner' },
{ result: alphaNumericRegex.test(req.body.username), expected: true, error: 'New owner username must contain a-z 0-9 only' },
]);
if (errors.length > 0) {
return dynamicResponse(req, res, 400, 'message', {

Loading…
Cancel
Save