Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. var MongoClient = require('mongodb').MongoClient;
  2.  
  3. var mongoURL = 'mongodb://localhost:27017/';
  4. module.exports = {
  5. connect: function(callback) {
  6. var self = this;
  7. if (self.db) {
  8. return process.nextTick(callback.bind(null, null, self.db));
  9. }
  10. MongoClient.connect(mongoURL, function(err, db) {
  11. self.db = db;
  12. return callback(err, db);
  13. });
  14. },
  15. getDb: function() {
  16. if (!this.db) {
  17. throw new Error('not initialized.');
  18. }
  19. return this.db;
  20. }
  21. };
  22.  
  23.  
  24.  
  25. var mongoClient = require("./includes/mongo-client");
  26.  
  27. var checkVerification = function(username, verificationCode, callback) {
  28. var cursor = mongoClient.getDb().collection('users').find();
  29. var result = false;
  30. cursor.each(function(err, doc) {
  31. if (doc && doc.verificationDate && (new Date().getTime() - doc.sessionDate) < 1000 * 60 * 15) {
  32. result = true;
  33. }
  34. if (doc == null) {
  35. callback(result);
  36. }
  37. });
  38. }
  39.  
  40. mongoClient.connect(function(err, db){
  41. console.log('what');
  42. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement