Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //index.js file
- var express = require('express');
- var router = express.Router();
- var app = express();
- var functions = require('../public/javascripts/functions.js');
- router.post('/ajax', function(req, res , next){
- var username = req.param("username");
- var password = req.param("password");
- var operation = req.param("operation");
- else if (operation === "validate")
- {
- functions.validate(username, password, req);
- //req.session.username = "yaryar"; >>>THIS DOES WORK<<<
- }
- var strings = ["rad", "bla", "ska"]
- console.log('body: ' + JSON.stringify(req.body));
- console.log("AJAX RECEIVED");
- res.send(strings);
- });
- module.exports = router;
- module.exports = {
- validate: function(username, password, req) {
- var url = 'mongodb://localhost';
- var MongoClient = require('mongodb').MongoClient;
- var assert = require('assert');
- var ObjectId = require('mongodb').ObjectID;
- MongoClient.connect(url, function(err, db)
- {
- assert.equal(null, err);
- console.log("Connected correctly to server.");
- var cursor = db.collection('users').find({username : username});
- cursor.each(function(err,doc,req)
- {
- assert.equal(err, null);
- if (doc != null)
- {
- console.log("user found: " + doc.username);
- req.session.username = "ttyy"; // >>>DOESNT WORK<<<
- return true
- }
- else
- {
- console.log("user not found");
- return false;
- }
- });
- //db.close();
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement