'use strict'; const changePassword = require(__dirname+'/../../models/forms/changepassword.js'); module.exports = async (req, res, next) => { const errors = []; //check exist if (!req.body.username || req.body.username.length <= 0) { errors.push('Missing username'); } if (!req.body.password || req.body.password.length <= 0) { errors.push('Missing password'); } if (!req.body.newpassword || req.body.newpassword.length <= 0) { errors.push('Missing new password'); } if (!req.body.newpasswordconfirm || req.body.newpasswordconfirm.length <= 0) { errors.push('Missing new password confirmation'); } //check too long if (req.body.username && req.body.username.length > 50) { errors.push('Username must be 50 characters or less'); } if (req.body.password && req.body.password.length > 100) { errors.push('Password must be 100 characters or less'); } if (req.body.newpassword && req.body.newpassword.length > 100) { errors.push('Password must be 100 characters or less'); } if (req.body.newpasswordconfirm && req.body.newpasswordconfirm.length > 100) { errors.push('Password confirmation must be 100 characters or less'); } if (req.body.newpassword != req.body.newpasswordconfirm) { errors.push('New password and password confirmation must match'); } if (errors.length > 0) { return res.status(400).render('message', { 'title': 'Bad request', 'errors': errors, 'redirect': '/changepassword.html' }) } try { await changePassword(req, res, next); } catch (err) { return next(err); } }