// 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, }) } })
user_pass = await User.getWhat('password', id) req.checkBody('old', 'Old password is empty!!').notEmpty() req.checkBody('new_', 'New password field is empty!!').notEmpty() req.checkBody('new_a', 'New password field is empty!!').notEmpty() if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg)) res.json({ mssg: array }) } else {
db.c_validator('surname', req) req.checkBody('email', 'Email is empty!!').notEmpty() req.checkBody('email', 'Invalid email!!').isEmail() req.checkBody('password', 'Password field is empty').notEmpty() if (!errors.isEmpty()) { let array = [] errors.array().forEach(e => array.push(e.msg)) res.json({ mssg: array }) } else {
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}` ); }
provideDefaultValidator() { return expressValidator({ errorFormatter: ValidationManager.errorFormatter }) }
// use for field validation and customizing the messages app.use(expressValidator({ errorFormatter: function(param, msg, value) { return { message: msg }; } }));
sanitizeParam('address').customSanitizer( (value, {req}) => { return req.params.address .replace(/[^A-Za-z0-9_.+@-]/g, '') // Remove special characters .toLowerCase() } )
const handleValidationErrors = (req, res, next) => { const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(422).json({ errors: errors.array() }); } next(); }