Created
January 23, 2012 12:41
-
-
Save jfromaniello/1662945 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var openDb = require("../db"), | |
bcrypt = require('bcrypt'); | |
module.exports = function(user, callback) { | |
user.availablePoints = 10; | |
openDb() | |
.collection('users') | |
.findOne({login: user.login}, function(err, userFromDb){ | |
if(userFromDb){ | |
callback("there is an user with the same login"); | |
return; | |
} | |
if(user.password){ | |
var salt = bcrypt.genSaltSync(10); | |
user.password = bcrypt.hashSync(user.password, salt); | |
} | |
openDb() | |
.collection('users') | |
.insert(user, function(err, user){ | |
delete user.password; | |
callback(err,user); | |
}); | |
}.bind(this)); | |
}; | |
//usage: | |
var createUser = require("data/createUser"); | |
createUser({login: "yadayada", password: "blabla"}, ...a callback) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment