Skip to content

Instantly share code, notes, and snippets.

@reecefenwick
Created March 31, 2015 02:50
Show Gist options
  • Save reecefenwick/3645c6acfd778fc66660 to your computer and use it in GitHub Desktop.
Save reecefenwick/3645c6acfd778fc66660 to your computer and use it in GitHub Desktop.
var Auth = require('../services/AuthService')
module.exports = {
login: function(req, res) {
Auth.login(req.body, function(err) {
if (err) return res.status(401).json({
message: 'You are not authorized'
})
res.status(200).json({
message: 'You are authorized'
})
})
},
signup: function(req, res) {
Auth.signup(req.body, function(err, newUser) {
if (err) return res.status(400).json({
message: 'No email provided...'
})
Auth.login(newUser, function(err) {
// so on so forth...
if (err) return res.status(400).json({
message: '...'
})
res.status(201).json(newUser)
})
})
}
}
var mongoskin = require('mongoskin');
module.exports = {
login: function(credentials, callback) {
req.db.collection('auth').findOne({
_id: mongoskin.helper.toObjectID(credentials.id)
},
function(err, results) {
if (err) return callback(err)
// Return null if successful
return callback(null)
// log person in and send results to client
}
)
},
signup: function(userDetails, callback) {
req.db.collection('auth').insert(userDetails, function(err, newUser) {
if (err) return callback(err);
return callback(null, newUser)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment