Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post('/api/users/authenticate', function(req, res, next) {
- var username = req.body.username;
- var password = req.body.password;
- console.log("post authentication request received.\n");
- console.log("username is: " + username + "\n");
- console.log("password is: " + password + "\n");
- var url = 'mongodb://localhost/admin';
- var authenticate = function(db, callback) {
- var cursor = db.collection('users').find({
- "username" : username,
- "password" : password}
- );
- var array = new Array();
- var isAuthenticated = false;
- cursor.each(function(err,doc)
- {
- if (err)
- {
- console.log(err);
- }
- else
- {
- console.log('Fetched:', doc);
- isAuthenticated = true;
- console.log("succesfully authenticated1. ");
- console.log("isAuthenticated1 is: " + isAuthenticated + "\n");
- }
- });
- callback(isAuthenticated);
- };
- MongoClient.connect(url, function(err, db) {
- assert.equal(null, err);
- authenticate(db, function(isAuthenticated) {
- //res.writeHead(200, {"Content-Type": "text/plain"});
- console.log("callback ran <<<<<<<<<-----------");
- console.log("isAuthenticated3 is: " + isAuthenticated + "\n");
- if (isAuthenticated == true) {
- res.json({authenticated: 'true'});
- } else {
- res.json({authenticated: 'false'});
- }
- db.close();
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement