Permalink
Browse files

add mongoose-util extended method for updating user

  • Loading branch information...
1 parent 69909fb commit 9a44e92e15efcb0bb4bcb8c8c68fb7da670986f5 Jim Snodgrass committed Apr 5, 2013
Showing with 9 additions and 21 deletions.
  1. +0 −4 components/user/index.js
  2. +7 −16 components/user/middleware.js
  3. +1 −0 components/user/model/userModel.js
  4. +1 −1 package.json
View
@@ -24,10 +24,6 @@ module.exports = function(app) {
addParams,
function (req, res) {
if (req.session.user) {
-
- console.log(req.session.user);
-
-
if (req.session.user.resetPassword) {
req.session.user.resetPassword = false;
UserModel.findByIdAndUpdate(req.session.user._id, {resetPassword:false}, function(){});
@@ -19,24 +19,15 @@ module.exports = function(app) {
}
}
- UserModel.findById(req.session.user._id, function(err, user) {
- if (err || !user) {
- req.flash("There was an error finding the user.");
- return next(err);
+ UserModel.findByIdAndUpdateX(req.session.user._id, req.body, function(err, user) {
+ if (err) {
+ console.log(err);
+ req.flash("There was an error updating the user.");
+ return next();
}
- _.extend(user, req.body);
-
- user.save(function(err) {
- if (err) {
- console.log(err);
- req.flash("There was an error updating the user.");
- return next();
- }
-
- req.session.user = user;
- return next();
- });
+ req.session.user = user;
+ return next();
});
},
@@ -14,6 +14,7 @@ module.exports = function() {
// Plugins
User.plugin(utils.plugin.timestamps);
+ User.plugin(utils.plugin.extendedMethods);
// Getters and Setters
View
@@ -15,7 +15,7 @@
"jade": "0.28.2",
"stylus": "0.32.1",
"mongoose": "3.6.4",
- "mongoose-utils": "0.0.1",
+ "mongoose-utils": "0.0.2",
"redis": "0.8.2",
"bcrypt": "0.7.5",
"email": "0.2.4",

0 comments on commit 9a44e92

Please sign in to comment.