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

@ -15,20 +15,12 @@ module.exports = {
controller: async (req, res, next) => { controller: async (req, res, next) => {
const errors = []; const errors = checkSchema([
{ result: existsBody(req.body.username), expected: true, error: 'Missing new owner username' },
if (!req.body.username || req.body.username.length === 0) { { result: lengthBody(req.body.username, 1, 50), expected: true, error: 'New owner username must be 50 characters or less' },
errors.push('Missing transfer username'); { 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 (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');
}
if (errors.length > 0) { if (errors.length > 0) {
return dynamicResponse(req, res, 400, 'message', { return dynamicResponse(req, res, 400, 'message', {

Loading…
Cancel
Save