Last active
August 29, 2015 14:11
-
-
Save daffl/ac19c17770d80da0f15f 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 userService = mongodb({ | |
| db: 'feathers-demo', | |
| collection: 'users' | |
| }).extend({ | |
| authenticate: function(username, password, callback) { | |
| // This will be used as the MongoDB query | |
| var query = { | |
| username: username | |
| }; | |
| this.find({ query: query }, function(error, users) { | |
| if(error) { | |
| return callback(error); | |
| } | |
| var user = users[0]; | |
| if(!user) { | |
| return callback(new Error('No user found')); | |
| } | |
| // Compare the hashed and salted passwords | |
| if(user.password !== hash(password, user.salt)) { | |
| return callback(new Error('User password does not match')); | |
| } | |
| // If we got to here, we call the callback with the user information | |
| return callback(null, user); | |
| }); | |
| } | |
| }); | |
| app.configure(feathers.socketio(function(io) { | |
| io.on('connection', function(socket){ | |
| io.on('login', function(username, password, callback) { | |
| app.service('users').authenticate(username, password, function(error, user) { | |
| socket.feathers.user = user; | |
| callback(error, user); | |
| }); | |
| }); | |
| }); | |
| }).use(userService); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment