How to use the restify.MissingParameterError function in restify

To help you get started, we’ve selected a few restify 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 xbrowsersync / api / bookmarks.js View on Github external
var getBookmarks = function(req, res, next) {
        if (!!config.status.offline) {
            return next(new restify.ServiceUnavailableError());
        }
        
        if (req.params.id === undefined) {
            return next(new restify.MissingParameterError('No ID provided'));
        }
        
        // Get binary from id
        var binId;
        try {
            binId = db.getBinaryFromUuid(req.params.id);
        }
        catch(ex) {
            return next(new restify.InvalidArgumentError('Invalid ID'));
        }

        db.bookmarks().findOne(
            { _id: binId }, 
            function(err, result) {
                if (err) {
                    return next(err);
github pcimino / nodejs-restify-mongodb / models / user.js View on Github external
UserSchema.pre('save', function(next) {
  if (!validatePresenceOf(this.username)) {
    next(new restify.MissingParameterError('Username cannot be blank'));
  }
  if (!validatePresenceOf(this.name)) {
    next(new restify.MissingParameterError('Name cannot be blank'));
  }
  if (!validatePresenceOf(this.role)) {
    next(new restify.MissingParameterError('Role cannot be blank'));
  }
  if (!validatePresenceOf(this.email)) {
    next(new restify.MissingParameterError('Email cannot be blank'));
  }
  if (this.email.indexOf('@') <= 0) {
//    next(new restify.MissingParameterError('Email address must be valid'));
  }

  // password not blank when creating, otherwise skip
  if (!this.isNew) return next();
github pcimino / nodejs-restify-mongodb / config / routes-user.js View on Github external
function putUserValidations(req, res, next) {
      // validations
      if (req.params.email) {
        if (!mail.validateEmail(req.params.email)) {
          return next(new restify.MissingParameterError('Please enter a valid email address.'));
        } else {
          gUser.newEmail = req.params.email;
        }
      }

      if (req.params.password) {
        if (req.params.password != req.params.vPassword) {
          return next(new restify.MissingParameterError('Password and Verify Password must match.'));
        }
        if (gCheckCurrentPassword && req.params.password && !req.params.cPassword) {
          return next(new restify.MissingParameterError('You must enter your current password to verify.'));
        }
        if (req.params.cPassword) {
          if (!gUser.authenticate(req.params.cPassword)) {
            return next(new restify.MissingParameterError('You must enter your current password to verify.'));
          }
github pcimino / nodejs-restify-mongodb / config / routes-user-signup.js View on Github external
function postUser(req, res, next) {
     if (req.params.password != req.params.vPassword) {
       return next(new restify.MissingParameterError('Password and Verify Password must match.'));
     }
     if (!mail.validateEmail(req.params.email)) {
       return next(new restify.MissingParameterError('Please enter a valid email address.'));
     }
     var user = new User(req.params);
     if (user.role == 'Admin' && !config.openUserSignup) {
       //TODO allow admin to modify create/modify a user with Admin access
       return next(new restify.MissingParameterError('You cannot create an Administrator.'));
     }
      if (user.username !== null && user.username !== '') {
         user.save(function (err, user) {
            if (!err) {
              // create a verification code
              mail.generateVerifyCode(req, res, next, user);
              res.send(user);
              return next();
            } else {
               return next(err);
            }
         });
      } else {
         return next(new restify.MissingParameterError('Username required.'));
      }
   }
github rgallagher27 / node-restify-oauth2-mongodb / Models / user.js View on Github external
UserSchema.pre('save', function(next) {
  if (!validatePresenceOf(this.name)) {
    next(new restify.MissingParameterError('Name cannot be blank'));
  }
  if (!validatePresenceOf(this.username)) {
    next(new restify.MissingParameterError('Username cannot be blank'));
  }
  if (!validatePresenceOf(this.role)) {
    next(new restify.MissingParameterError('Role cannot be blank'));
  }
  if (!validatePresenceOf(this.email)) {
    next(new restify.MissingParameterError('Email cannot be blank'));
  }
  if (this.email.indexOf('@') <= 0) {
//    next(new restify.MissingParameterError('Email address must be valid'));
  }

  // password not blank when creating, otherwise skip
  if (!this.isNew) return next();
  if (!validatePresenceOf(this.password)) {
    next(new restify.MissingParameterError('Invalid password'));
  }
  next();
})
github pcimino / nodejs-restify-mongodb / config / routes-user.js View on Github external
function putUserValidations(req, res, next) {
      // validations
      if (req.params.email) {
        if (!mail.validateEmail(req.params.email)) {
          return next(new restify.MissingParameterError('Please enter a valid email address.'));
        } else {
          gUser.newEmail = req.params.email;
        }
      }

      if (req.params.password) {
        if (req.params.password != req.params.vPassword) {
          return next(new restify.MissingParameterError('Password and Verify Password must match.'));
        }
        if (gCheckCurrentPassword && req.params.password && !req.params.cPassword) {
          return next(new restify.MissingParameterError('You must enter your current password to verify.'));
        }
        if (req.params.cPassword) {
          if (!gUser.authenticate(req.params.cPassword)) {
            return next(new restify.MissingParameterError('You must enter your current password to verify.'));
          }
          gUser.tempPasswordFlag = true;
          gUser.password = req.params.password;
        }
      }
      return next();
  }
  /* validate change step 2 */
github pcimino / nodejs-restify-mongodb / config / routes-user.js View on Github external
function getUser(req, res, next) {
      if (req.session && req.session.user) {
        id = req.session.user;
        if (req.params.id) { id = req.params.id; }
        User.findById(id, function (err, user) {
          if (!err) {
            res.send(user);
            return next();
          } else {
             var errObj = err;
             if (err.err) { errObj = err.err; }
             return next(new restify.InternalError(errObj));
          }
       });
      } else {
        return next(new restify.MissingParameterError('No search params sent.'));
      }
   }
github pcimino / nodejs-restify-mongodb / config / routes-user.js View on Github external
function putUserPostValidate(req, res, next) {
     var user = gUser;
     if (req.params.role) {
        user.role = req.params.role;
        if (gCheckRoleRestriction && user.role == 'Admin' && !config.openUserSignup) {
           return next(new restify.MissingParameterError('You cannot change this user to an Administrator.'));
        }
     }
     if (user.newEmail) {
        var queryObj = {$or :[{'email': new RegExp('^'+user.newEmail+'$', 'i')}, {'newEmail': new RegExp('^'+user.newEmail+'$', 'i')}]};
        User.count(queryObj, function (err, count) {
          if (!err) {
             if (count === 0) {
                return next();
             } else {
                 return next(new restify.InternalError('Email already in use, or you must validate your new email before making more changes to your account.'));
             }
          } else {
             var errObj = err;
             if (err.err) {
               errObj = err.err;
             }
github joyent / sdc-docker / lib / endpoints / admin / progress.js View on Github external
function adminProgress(req, res, next) {
    var id = req.body.id;
    var payload = req.body.payload;
    var operation = req.app.sockets.getSocket('job', id);

    if (!id || !operation) {
        return next(new restify.ResourceNotFoundError('Operation not found'));
    } else if (!payload) {
        return next(new restify.MissingParameterError('Missing payload'));
    }

    operation.socket.write(JSON.stringify(payload));
    res.send(200);
    return next();
}
github pcimino / nodejs-restify-mongodb / config / routes-user.js View on Github external
User.findById(search, function (err, user) {
                    if (!err) {
                      res.send(user);
                    } else {
                      res.send(new restify.MissingParameterError('User not found.'));
                    }
                    return next();
                 });
               }