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:
parent
1bf1e3a55e
commit
5a4d97b1bd
1 changed files with 6 additions and 5 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue