How to use the express-validator.body function in express-validator

To help you get started, we’ve selected a few express-validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudfoundry / overview-broker / service_broker_interface.js View on Github external
createServiceInstance() {
        return [
            param('instance_id', 'Missing instance_id').exists(),
            body('service_id', 'Missing service_id').exists(),
            body('plan_id', 'Missing plan_id').exists(),
            body('organization_guid', 'Missing organization_guid').exists(),
            body('space_guid', 'Missing space_guid').exists(),
            (request, response) => {
                const errors = validationResult(request);
                if (!errors.isEmpty()) {
                    this.sendJSONResponse(response, 400, { error: JSON.stringify(errors) });
                    return;
                }

                var serviceInstanceId = request.params.instance_id;
                let dashboardUrl = `${this.serviceBroker.getDashboardUrl()}?time=${new Date().toISOString()}`;
                let data = {
                    dashboard_url: dashboardUrl
                };

                // Check if we only support asynchronous operations
github WagonOfDoubt / kotoba.js / app / src / routes / auth.js View on Github external
// successRedirect
        const redirectTo = req.session.redirectTo || '/manage';
        const redirectHash = req.body.redirectHash || '';
        delete req.session.redirectTo;
        return res.redirect(redirectTo + redirectHash);
      });
    })(req, res, next);
  });


router.post('/manage/registration', [
    body('login', 'Login is required')
      .exists(),
    body('password', 'Password is required')
      .exists(),
    body('login', 'Login must be between 6 and 25 characters long')
      .exists()
      .isLength({ min: 6, max: 25 }),
    body('login', 'Login must contain only letters and numbers')
      .isAlphanumeric(),
    body('password', 'Password must be between 6 and 72 characters long and contain one number')
      .exists()
      .isLength({ min: 6, max: 72 })
      .matches(/\d/),
    body('repeat', 'Passwords does not match')
      .exists()
      .custom((value, { req }) => value === req.body.password)
  ],
  async (req, res, next) => {
    const { login, password } = req.body;

    // check request params
github hackmcgill / hackerAPI / middlewares / validators / validator.helper.js View on Github external
fieldName,
    errorString
) {
    /**
     * check: ValidationChainBuilder;
     * body: ValidationChainBuilder;
     * cookie: ValidationChainBuilder;
     * header: ValidationChainBuilder;
     * param: ValidationChainBuilder;
     * query: ValidationChainBuilder;
     */
    switch (fieldLocation) {
        case "query":
            return query(fieldName, errorString);
        case "body":
            return body(fieldName, errorString);
        case "header":
            return header(fieldName, errorString);
        case "param":
            return param(fieldName, errorString);
        default:
            logger.error(`${TAG} Invalid field location: ${fieldLocation}`);
    }
}
github soha-moosa / node-auth-kit / middleware / validation-middleware.js View on Github external
'email',
  'Please enter a valid e-mail address.'
)
  .isEmail()
  .custom((value, { req }) => {
    return User.findOne({ 'local.email': value }).then(user => {
      if (user) {
        return Promise.reject(
          'E-Mail exists already, please select a different one!'
        );
      }
    });
  })
  .normalizeEmail();

export const validateLoginEmail = body(
  'email',
  'Please enter a valid e-mail address.'
)
  .isEmail()
  .normalizeEmail();

export const validatePassword = body(
  'password',
  'Please enter a alphanumeric password and at least 6 characters long.'
)
  .isLength({ min: 6 })
  .isAlphanumeric()
  .trim();

export const validateConfirmPassword = body('confirmPassword')
  .trim()
github soha-moosa / node-auth-kit / middleware / validation-middleware.js View on Github external
export const validateLoginEmail = body(
  'email',
  'Please enter a valid e-mail address.'
)
  .isEmail()
  .normalizeEmail();

export const validatePassword = body(
  'password',
  'Please enter a alphanumeric password and at least 6 characters long.'
)
  .isLength({ min: 6 })
  .isAlphanumeric()
  .trim();

export const validateConfirmPassword = body('confirmPassword')
  .trim()
  .custom((value, { req }) => {
    if (value !== req.body.password) {
      throw new Error('Password have to match!');
    }
    return true;
  });