Created
November 18, 2013 01:50
-
-
Save projectweekend/7521138 to your computer and use it in GitHub Desktop.
Node.js User Signup Socket - A pattern I'm testing out to for a socket that handles user signup actions using MongooseJS and Passport.
This file contains 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 hat = require('hat'); | |
module.exports = function (socket, handleError, config) { | |
// set some common items we will need from config | |
var route = config.route; | |
var userModel = config.model; | |
socket.on(route, function (data) { | |
var rack = hat.rack(); | |
var token = rack(); | |
var newUserConfig = { | |
username: data.email, | |
token: token | |
}; | |
var password = data.password; | |
userModel.register(new userModel(newUserConfig), password, function (err, newProfile) { | |
if (err) { | |
return handleError(route, err); | |
} else { | |
var successData = { | |
token: newProfile.token | |
}; | |
socket.emit(route + ':success', successData); | |
} | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment