Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
}).catch((err) => {
console.log("Post Category error:", err);
});
});
/**********************************************
/
/ Add a new Post
/
/ Second parameter an array of validations
/
/*********************************************/
app.post('/posts/new', [
check('postTitle', 'Title must not be empty').isLength({ min: 1 }),
check('postContent', "Don't you want to include some content?").isLength({ min: 1 })
], (req, res) => {
// Check user redirect if not logged in
const currentUser = req.user;
let loggedin = "";
if (currentUser === null) {
return res.redirect('/login');
} else {
loggedin = "loggedin";
}
// Validate this request
const errors = validationResult(req); // Validate the req obj
// Check for errors
if (!errors.isEmpty()) {
const user = await User.findById(req.user.id).select('-password');
res.json(user);
} catch (err) {
console.error(err.message);
res.status(500).send('Server Error');
}
});
// @route POST api/auth
// @desc Authenticate user & get token
// @access Public
router.post(
'/',
[
check('email', 'Please include a valid email').isEmail(),
check('password', 'Password is required').exists()
],
async (req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
const { email, password } = req.body;
try {
let user = await User.findOne({ email });
if (!user) {
return res
.status(400)
.json({ errors: [{ msg: 'Invalid Credentials' }] });
// Register Action
app.post(
'/api/users/register',
[
check('login')
.isInt()
.exists()
.isLength({ max: 20 }),
check('password')
.exists()
.isLength({ max: 255 }),
check('name')
.exists()
.isString()
.isLength({ max: 255 }),
check('surname')
.exists()
.isString()
.isLength({ max: 255 }),
check('email')
.exists()
.isEmail()
.isLength({ max: 255 }),
],
users.register,
);
// Login Action
app.post(
'/api/users/login',
[
check('login')
title: 'Add new user',
profile: {},
page: 'users',
admin: admin,
csrfToken: req.csrfToken()
});
} else {
req.flash('error', 'Only administrators can add new users');
res.render('blank');
}
}
});
// Register or update an user
protected.post('/profile/:id(' + conf.usernameRegex + ')?', csrfProtection, [
check('name')
.trim()
.isLength({
min: 2,
max: undefined
})
.withMessage('Name too short')
.isLength({
min: 0,
max: 64
})
.withMessage('Name too long'),
check('emoji')
.trim()
.isLength({
min: 0,
max: 8
transactions.getSenderdata,
);
// Return Sender's Authorization Key Actions
app.post(
'/api/transactions/authorizationKey',
checkAuth,
checkToken,
[
check('id_sender')
.exists()
.isInt(),
check('recipient_id')
.exists()
.isInt(),
check('amount_money')
.isNumeric()
.exists(),
check('transfer_title')
.exists()
.isString()
.isLength({ max: 35 }),
],
transactions.getAuthorizationKey,
);
};
const jwt = require('jsonwebtoken');
const config = require('config');
const { check, validationResult } = require('express-validator/check');
const User = require('../../models/User');
// @route POST api/users
// @desc Register user
// @access Public
router.post(
'/',
[
check('name', 'Name is required')
.not()
.isEmpty(),
check('email', 'Please include a valid email').isEmail(),
check(
'password',
'Please enter a password with 6 or more characters'
).isLength({ min: 6 })
],
async (req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
const { name, email, password } = req.body;
try {
let user = await User.findOne({ email });
/* GET Login/Registration page. */
router.get("/", function (req, res) {
res.render("signIn", { user : req.user });
});
router.get("/register", function(req, res) {
res.render("register", { });
});
/* Registers a user with the information received from a POST request.*/
router.post("/register", [
check("username").not().isEmpty().withMessage("cannot be empty"),
check("password").not().isEmpty().withMessage("cannot be empty"),
check("email").not().isEmpty().withMessage("cannot be empty"),
check("confirmpassword").not().isEmpty().withMessage("cannot be empty"),
check("email").isEmail().withMessage("must be a valid email address"),
check("password", "passwords must be at least 5 characters long and contain one number")
.isLength({ min: 5 })
.matches(/\d/),
check("confirmpassword").custom((value, { req }) => value === req.body.password).withMessage("must match the password field")
],function(req, res) {
const errors = validationResult(req);
if (!errors.isEmpty()) {
const errs = errors.array()[0];
output = errs.param + " " + errs.msg;
return res.render("signIn", { reg:output });
}
let user = new User({
username: req.body.username,
email: req.body.email,
const router = express.Router()
const { check } = require('express-validator/check')
const Chiccocoin = require('../middleware/chiccocoin')
const responseMiddleware = (req, res, next) => {
return res.json(req.responseValue)
}
/* GET home page. */
router.get('/', function (req, res, next) {
res.render('index', { title: 'Chicco Coin' })
})
router.post('/transactions/new', [
check('sender', 'Sender must be a String').exists(),
check('recipient', 'Sender must be a String').exists(),
check('amount', 'Sender must be a Int Value').isInt().exists()
], Chiccocoin.newTransaction, responseMiddleware)
router.get('/mine', Chiccocoin.mine, responseMiddleware)
router.get('/chain', Chiccocoin.getChain, responseMiddleware)
router.post('/node/register', [
check('node', 'Node must be a String').exists()
], Chiccocoin.addNode, responseMiddleware)
module.exports = router
.withMessage('Accepts only true or false'),
],
updateMeal: [
check('mealId')
.isUUID(4)
.withMessage('Invalid ID'),
check('title')
.trim()
.customSanitizer(value => value.replace(/ +/g, ' ').trim())
.optional()
.custom(value => notEmpty(value, 'If provided, meal title field cannot be left blank'))
.isLength({ min: 1, max: 50 })
.withMessage('Meal title must be between 1 and 50 characters')
.matches(/^[a-z (),.'-]+$/i)
.withMessage('Meal title can only contain letters and the characters (,.\'-)'),
check('description')
.trim()
.optional({ checkFalsy: true })
.isLength({ max: 100 })
.withMessage('Text must not be more than 100 characters')
.matches(/^[a-z 0-9 (),.'-]+$/i)
.withMessage('Text can only contain letters and the characters (,.\'-)'),
check('price')
.trim()
.optional()
.custom(value => notEmpty(value, 'If provided, price field cannot be left blank'))
.isDecimal()
.withMessage('Price must be a number or decimal')
.custom(value => parseFloat(value).toFixed(2) > 0)
.withMessage('Price must be greater than 0'),
check('imageUrl')
.trim()
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var validator = require("express-validator/check");
var errors_1 = require("../constants/errors");
exports.default = [
validator.check('email', errors_1.EMAIL_IS_REQUIRED).exists(),
validator.check('email', errors_1.EMAIL_IS_INVALID).isEmail().trim().normalizeEmail(),
validator.check('password', errors_1.PASSWORD_IS_REQUIRED).exists()
];
//# sourceMappingURL=validateLogin.js.map