Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async (req, res, next) => {
const { login, password } = req.body;
// check request params
const errors = validationResult(req);
if (!errors.isEmpty()) {
req.flash('errors', errors.array());
res.redirect('/manage/registration');
return;
}
// check if login already taken
const loginAlreadyUsed = await User.findOne({ login }).exec();
if (loginAlreadyUsed) {
req.flash('errors', ['This login already taken']);
res.redirect('/manage/registration');
return;
}
// if no users was created, first user will be admin
const numberOfUsers = await User.count().exec();
(req, res, next) => {
try {
if (validationResult(req).isEmpty()) {
next();
} else {
return res.redirect(redirect);
}
} catch (errorWhileProcessingError) {
next(errorWhileProcessingError);
}
};
errorMsg: (req, res, next) => {
const valRes = validationResult(req)
if (!valRes.isEmpty()) {
let msg = ""
valRes.errors.forEach(v => {
msg += `${v.param},`
})
msg = msg.slice(0, -1)
msg += " 参数有问题,请检查"
return res.status(400).send({
msg
})
}
next()
}
}
], (req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.render('config/github', {errors: errors.mapped()});
}
publisher('github').setAll(req.body);
res.redirect(req.query.referrer || '/config/publication');
});
exports.validationResult = (req, res, next) => {
try {
validationResult(req).throw()
if (req.body.email) {
req.body.email = req.body.email.toLowerCase()
}
return next()
} catch (err) {
return this.handleError(res, this.buildErrObject(422, err.array()))
}
}
function expectValidationError(fieldName, expectedMessage) {
expect(validationResult(request).mapped()[fieldName].msg).toEqual(expectedMessage);
}
function expectValidationError(fieldName, expectedMessage) {
expect(validationResult(request).mapped()[fieldName].msg).toEqual(expectedMessage);
}
export const createPost = async (req: Request, res: Response) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
//@ts-ignore
req.flash("error", errors.array().map(err => err.msg));
res.render("create", {
title: "Create Post",
body: req.body,
flashes: req.flash(),
});
} else {
//@ts-ignore
req.body.author = req.user._id;
await new Post(req.body).save();
req.flash("success", "Your Post has been created!");
res.redirect("/posts");
}
async (req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
const { email, password } = req.body;
try {
//See if user exist
let user = await User.findOne({ email });
if (!user) {
return res
.status(400)
.json({ errors: [{ msg: "Invalid Credentials" }] });
}
const isMatch = await bcrypt.compare(password, user.password);