Validate submit button in view (not in validation function)

This is so the validation function can also be used in other
places, such as while processing an already saved pledge.
This commit is contained in:
Hippo 2022-01-05 19:36:13 +05:30
parent 1bf1e3a55e
commit 5a4d97b1bd

View file

@ -123,11 +123,6 @@ function validatePledge(body, PledgeModel = Pledge) {
// errors get saved here
let errors = []
let submit = body.submit
if (submit != 'Save Pledge') {
errors.push("This request seems to have been tampered with. Are you sure it wasn't you doing the tampering?")
}
let robo = body.robo
if(robo != 'no') {
errors.push('Only humans are allowed to donate money. Robots are too digital 🙁')
@ -194,6 +189,12 @@ function validatePledge(body, PledgeModel = Pledge) {
router.post('/pledge', async (req, res) => {
if (DEBUG) console.debug('New pledge:', req.body)
// check that the right submit button was pressed
let submit = req.body.submit
if (submit != 'Save Pledge') {
errors.push("This request seems to have been tampered with. Are you sure it wasn't you doing the tampering?")
}
// process the pledge with our handy function
let {pledge, errors} = validatePledge(req.body, UnverifiedPledge)