generators/app/templates/server/api/user(auth)/user.controller.js
function (req, res, next) {
    var userId = req[this.paramName]._id;
    var oldPass = String(req.body.oldPassword);
    var newPass = String(req.body.newPassword);

    this.model.findOne({'_id': userId}, function (err, user) {
      if (user.authenticate(oldPass)) {
        user.password = newPass;

        user.save(function (err) {
          if (err) {
            return res.handleError(err);
          }
          return res.noContent();
        });
      } else {
        res.forbidden();
      }
    });
  }
function (req, res, next) {
    var userId = req[this.paramName]._id;
    var oldPass = String(req.body.oldPassword);
    var newPass = String(req.body.newPassword);

    this.model.findOne({'_id': userId}, function (err, user) {
      if (user.authenticate(oldPass)) {
        user.password = newPass;

        user.save(function (err) {
          if (err) {
            return res.handleError(err);
          }
          return res.noContent();
        });
      } else {
        res.forbidden();
      }
    });
  }
function ( req , res , next ) { var userId = req [ this . paramName ] . _id ; var oldPass = String ( req . body . oldPassword ) ; var newPass = String ( req . body . newPassword ) ; this . model . findOne ( { '_id' : userId } , function ( err , user ) { if ( user . authenticate ( oldPass ) ) { user . password = newPass ; user . save ( function ( err ) { if ( err ) { return res . handleError ( err ) ; } return res . noContent ( ) ; } ) ; } else { res . forbidden ( ) ; } } ) ; }
Change the password of a user in the DB. The 'oldPassword' and 'newPassword' property of the
request body are used.
@param {IncomingMessage} req - The request message object containing the 'oldPassword' and 'newPassword' property
@param {ServerResponse} res - The outgoing response object
@param {function} next - The next handler function
@returns {ServerResponse} The response status OK or FORBIDDEN if an error occurs
Change the password of a user in the DB . The oldPassword and newPassword property of the request body are used .