Created
December 8, 2012 20:42
-
-
Save Jigarsolanki/4241841 to your computer and use it in GitHub Desktop.
user/auth handler
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
exports.generateToken = function(req, res) { | |
var username, password; | |
username = req.param('username'); | |
password = req.param('password'); | |
if(username === 'foo' && password === 'bar') { | |
res.send(200, {'token': "ABC123"}); | |
} else { | |
res.send(401, {'message': 'Unauthorised'}); | |
} | |
}; | |
exports.authorize = function(req, res, next) { | |
var token; | |
token = req.headers['auth-token'] || ''; | |
if(token !== "ABC123") { | |
res.send(401, {'message': 'Unauthorised'}); | |
} else { | |
next(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment