mirror of https://gitgud.io/fatchan/jschan.git
Tags (#51)
* board tags, and limits to tags, moderators and filters * increase max filters * change page to match * add board ownership transfers (#50)merge-requests/208/head
parent
ab27114f71
commit
f0795a959f
9 changed files with 105 additions and 17 deletions
@ -0,0 +1,37 @@ |
||||
'use strict'; |
||||
|
||||
const transferBoard = require(__dirname+'/../../models/forms/transferboard.js') |
||||
, alphaNumericRegex = require(__dirname+'/../../helpers/checks/alphanumregex.js'); |
||||
|
||||
module.exports = 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 at less than 50 characters'); |
||||
} |
||||
if (req.body.username === res.locals.board.owner) { |
||||
errors.push('You are already board owner...'); |
||||
} |
||||
if (alphaNumericRegex.test(req.body.username) !== true) { |
||||
errors.push('URI must contain a-z 0-9 only'); |
||||
} |
||||
|
||||
if (errors.length > 0) { |
||||
return res.status(400).render('message', { |
||||
'title': 'Bad request', |
||||
'errors': errors, |
||||
'redirect': `/${req.params.board}/manage.html` |
||||
}) |
||||
} |
||||
|
||||
try { |
||||
await transferBoard(req, res, next); |
||||
} catch (err) { |
||||
return next(err); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,27 @@ |
||||
'use strict'; |
||||
|
||||
const { Boards, Accounts } = require(__dirname+'/../../db/'); |
||||
|
||||
module.exports = async (req, res, next) => { |
||||
|
||||
const newOwner = await Accounts.findOne(req.body.username); |
||||
|
||||
if (!newOwner) { |
||||
return res.status(400).render('message', { |
||||
'title': 'Bad request', |
||||
'message': 'Cannot transfer to account that does not exist', |
||||
'redirect': redirect |
||||
}); |
||||
} |
||||
|
||||
//set owner in memory and in db
|
||||
res.locals.board.owner = newOwner._id; |
||||
await Boards.setOwner(req.params.board, res.locals.board.owner); |
||||
|
||||
return res.render('message', { |
||||
'title': 'Success', |
||||
'message': 'Transferred ownership', |
||||
'redirect': `/${req.params.board}/index.html` |
||||
}); |
||||
|
||||
} |
Loading…
Reference in new issue