// USER DEACTIVATE ACCOUNT app.post('/user/deactivate-account', async (req, res) => { let { id } = req.session, userPassword = await User.getWhat('password', id), { password } = req.body, samePassword = await User.comparePassword(password, userPassword) req.checkBody('password', 'Password is empty!!').notEmpty() let errors = await req.getValidationResult() if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg)) res.json({ mssg: array }) } else if (!samePassword) { res.json({ mssg: 'Wrong password!!' }) } else { await User.deactivate(id, req, res) res.json({ mssg: 'Deactivated your account successfully!!', success: true, }) } })
if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg))
if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg))
if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg))
if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg))
if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg))
if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg))
const passwordResetVerify = async (req, res) => { const errors = validationResult(req); const appURL = process.env.FRONTEND_URL; if (!errors.isEmpty()) { return handleRedirect(res, 302, `${appURL}/password-reset-request?messageKey=passwordResetValidationError`); } return handleRedirect( res, 302, `${appURL}/password-reset?messageKey=passwordResetTokenConfirmed&key=${req.query.key}` ); }
const handleValidationErrors = (req, res, next) => { const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(422).json({ errors: errors.array() }); } next(); }
// can be reused by many routes const validate = (validations) => { return async (req, res, next) => { await Promise.all(validations.map((validation) => validation.run(req))); const errors = validationResult(req); if (errors.isEmpty()) { return next(); } res.status(422).json({ errors: errors.array() }); }; }
const handleValidationError = (req, res) => { const errors = validationResult(req); if (!errors.isEmpty()) { const errorArray = errors.array(); return emitValidationResponse(res, errorArray); } return null; }
const handleValidationErrors = (req, res, next) => { const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(422).json({ errors: errors.array() }); } next(); }