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}
- //{"username" : "user", "password" : "pass"}
- //{"_id" : ObjectId("580c074cffc27c14fffe126c")}
- );
- 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'});
- }
- //res.end(JSON.stringify(array));
- //res.json(JSON.stringify(array));
- db.close();
- });
- });
- //res.json({status: 'user added'});
- //console.log("price: " + price);
- //res.json({'message': 'product put', 'price': price});
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement