How to use the validator.trim function in validator

To help you get started, we’ve selected a few 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 timeoff-management / application / lib / route / users / index.js View on Github external
function get_and_validate_user_parameters(args) {
    var req         = args.req,
        item_name   = args.item_name,
        require_password = args.require_password || false;

    // Get user parameters
    var name     = validator.trim(req.body['name']),
        lastname = validator.trim(req.body['lastname']),
        email    = validator.trim(req.body['email_address']),
        department_id     = validator.trim(req.body['department']),
        start_date        = validator.trim(req.body['start_date']),
        end_date          = validator.trim(req.body['end_date']),
        adjustment        = validator.trim(req.body['adjustment']),
        password          = validator.trim(req.body['password_one']),
        password_confirm  = validator.trim(req.body['password_confirm']),
        admin             = validator.toBoolean(req.body['admin']),
        auto_approve      = validator.toBoolean(req.body['auto_approve']);

    // Validate provided parameters

    if (!validator.isEmail(email)) {
        req.session.flash_error(
            'New email of '+item_name+' should be valid email address'
github timeoff-management / application / lib / route / departments.js View on Github external
function get_and_validate_department(args) {
  var req             = args.req,
      index           = args.suffix,
      company         = args.company,
      // If no_suffix is set then parameter names are considered without "indexes"
      no_suffix        = args.no_suffix,
      department_name = args.department_name;

  // Get user parameters
  let
    name      = validator.trim(req.body[no_suffix ? 'name'      : 'name__'+index]),
    allowance = validator.trim(req.body[no_suffix ? 'allowance' : 'allowance__'+index]),
    boss_id   = validator.trim(req.body[no_suffix ? 'boss_id'   : 'boss_id__'+index]),
    include_public_holidays = validator.toBoolean(
      req.body[no_suffix ? 'include_public_holidays' : 'include_public_holidays__'+index]
    ),
    is_accrued_allowance = validator.toBoolean(
      req.body[no_suffix ? 'is_accrued_allowance' : 'is_accrued_allowance__'+index]
    );

  // Validate provided parameters
  //
  // New allowance should be from range of (0;50]
  if (!validator.isFloat(allowance)) {
    req.session.flash_error(
      'New allowance for '+department_name+' should be numeric'
    );
  } else if (!((0 <= allowance) && (allowance <= 50))) {
    req.session.flash_error(
github fedte / alblog / alblog-service / api / v1 / admin / article.js View on Github external
exports.create = function (req, res, next) {
  let catetory= validator.trim(req.body.catetory || '')
  let userId  = validator.trim(req.body.userId)
  let title   = validator.trim(req.body.title || '')
  let tag     = validator.trim(req.body.tag || '')
  let content = validator.trim(req.body.content || '')
  // 验证
  let message
  if (title === '') {
    message = '标题不能为空'
  } else if (title.length < 3) {
    message = '标题不可少于3个字符'
  } else if (title.length > 100) {
    message = '标题太长了'
  } else if (content === '') {
    message = '内容不可为空'
  } else if (content.length < 10) {
    message = '内容不可少于10个字符'
  }
github k-dylan / easyclub / routes / user.js View on Github external
router.get('/:username', async (ctx, next) => {
  let username = validator.trim(ctx.params.username);
  let User = ctx.model('user');
  let user = await User.findOneQ({
    username: username
  });
  if(!user) {
    return ctx.error('没有找到此用户!');
  }
  if(user.deleted) {
    return ctx.error('该用户已被删除', {
      jump: '/'
    });
  }

  let Topic = ctx.model('topic');
  // 查询参数
  let options = {
github cnodejs / nodeclub / controllers / user.js View on Github external
accessToken: data.accessToken,
    };
    if (isSuccess) {
      data2.success = msg;
    } else {
      data2.error = msg;
    }
    res.render('user/setting', data2);
  }

  // post
  var action = req.body.action;
  if (action === 'change_setting') {
    var url = validator.trim(req.body.url);
    var location = validator.trim(req.body.location);
    var weibo = validator.trim(req.body.weibo);
    var signature = validator.trim(req.body.signature);

    User.getUserById(req.session.user._id, ep.done(function (user) {
      user.url = url;
      user.location = location;
      user.signature = signature;
      user.weibo = weibo;
      user.save(function (err) {
        if (err) {
          return next(err);
        }
        req.session.user = user.toObject({virtual: true});
        return res.redirect('/setting?save=success');
      });
    }));
  }
github luoyjx / gaoqi-blog / api / topic.js View on Github external
exports.create = function(req, res, next) {
  var title = validator.trim(req.body.title);//文章标题
  var link = validator.trim(req.body.link);//文章链接
  var accountName = validator.trim(req.body.accountName);//公众号名称
  var accountLink = validator.trim(req.body.accountLink);//公众号链接
  var categoryName = validator.trim(req.body.category);//分类名称

  var ep = new EventProxy();
  ep.fail(next);
  var events = ['topic_account', 'topic_category'];

  ep.assign(events, function(topic_account, topic_category) {
    console.log('pre save done');
    //存储文章
    Topic.newAndSave(title, '', topic_category._id, link, topic_account._id, function(err, topic) {
      if (err) {
        next(err);
      }
      res.send({
        success: 1,
        topic_id: topic._id
github bs32g1038 / node-blog / controllers / guestbook.js View on Github external
exports.b_guestbook_reply_do = function(req, res, next) {

    var id = req.params.id;
    var reply_content = validator.trim(req.body.reply);

    guestbookDao.updateById(id, { reply_content: reply_content }, function(err) {
        if(err){
            return next(err);
        }
        return res.redirect('/admin/guestbook/list');
    });
}
github timeoff-management / application / lib / route / settings.js View on Github external
router.post('/company/', function(req, res){

  const
    name              = validator.trim(req.body['name']),
    country_code      = validator.trim(req.body['country']),
    date_format       = validator.trim(req.body['date_format']),
    timezone          = validator.trim(req.body['timezone']),
    carriedOverDays   = validator.trim(req.body['carry_over']),
    share_all_absences= validator.toBoolean(
      req.body['share_all_absences']
    ),
    isTeamViewHidden = validator.toBoolean(
      req.body['is_team_view_hidden']
    );

  if (!validator.isAlphanumeric(country_code)){
    req.session.flash_error('Country should contain only letters and numbers');
  }

  if ( ! moment_tz.tz.names().find(tz_str => tz_str === timezone) ) {
    req.session.flash_error('Time zone is unknown');
  }
github cnodejs / nodeclub / controllers / sign.js View on Github external
exports.updatePass = function (req, res, next) {
  var psw   = validator.trim(req.body.psw) || '';
  var repsw = validator.trim(req.body.repsw) || '';
  var key   = validator.trim(req.body.key) || '';
  var name  = validator.trim(req.body.name) || '';

  var ep = new eventproxy();
  ep.fail(next);

  if (psw !== repsw) {
    return res.render('sign/reset', {name: name, key: key, error: '两次密码输入不一致。'});
  }
  User.getUserByNameAndKey(name, key, ep.done(function (user) {
    if (!user) {
      return res.render('notify/notify', {error: '错误的激活链接'});
    }
    tools.bhash(psw, ep.done(function (passhash) {
      user.pass          = passhash;