Advertisement
Guest User

Untitled

a guest
Feb 24th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1.  
  2. socket.on('auth', function(data){
  3. authlogin = data.login;
  4. authpassword = data.password;
  5.  
  6.  
  7. MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {
  8. if(err) throw err;
  9.  
  10. var collection = db.collection('accounts');
  11.  
  12. collection.find({login: authlogin, password: authpassword}).toArray(function (err, result) {
  13. if (err) {
  14. console.log(err);
  15. } else if (result.length) {
  16. permission = 1;
  17. user = {"login": result[0].login, "mail": result[0].mail}
  18. console.log(user);
  19. def.writeHead(404, {'Content-Type': 'text/plain'}); // <- redirect
  20. def.write("Looked everywhere, but couldn't find that page at all!\n"); // <- content!
  21. def.end();
  22.  
  23. } else {
  24. socket.emit('auth', {'state': 'false'});
  25. }
  26. //Close connection
  27. db.close();
  28. });
  29. });
  30.  
  31. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement