Created
March 31, 2015 02:50
-
-
Save reecefenwick/3645c6acfd778fc66660 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 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) | |
}) | |
}) | |
} | |
} |
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 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