daily pastebin goal
53%
SHARE
TWEET

Untitled

a guest Jun 30th, 2018 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var static = require("node-static"),
  2.     fs = require("fs"),
  3.     mongoose = require("mongoose"),
  4.     Schema = mongoose.Schema,
  5.     file = new(static.Server)('./public'),
  6.     config = "";
  7.    
  8. //Read config file
  9. fs.readFile("./config.json", "utf8", function(err, data){
  10.     if(err) throw error;
  11.     config = JSON.parse(data);
  12.  
  13.  
  14.     //Mongoose
  15.     mongoose.connect("mongodb://localhost/"+config.Mongoose_DB+":"+config.Mongoose_Port);
  16.     mongoose.connection.on("open", function(error){
  17.         if(error) throw error;
  18.     });
  19.     console.log("\u001b[31mMongoose\u001b[0m running on port \u001b[31m"+config.Mongoose_Port+"\u001b[0m, with the databse \u001b[31m"+config.Mongoose_DB+"\u001b[0m");
  20.     //Users Model
  21.     var sUsers = new Schema({
  22.     id : mongoose.Schema.ObjectId,
  23.         user : String,
  24.         password : String,
  25.         mail : String,
  26.         lastLogin: Date,
  27.         RegisterDate: Date
  28.     });
  29.     var usersModel = mongoose.model('Users', sUsers);
  30.  
  31.  
  32.     //HTTP-Server
  33.     var http = require('http').createServer(function (request, response) {
  34.         request.addListener('end', function () {
  35.             file.serve(request, response);
  36.         });
  37.     }).listen(parseInt(config.Webserver_Port));
  38.     console.log("\u001b[31mWebserver\u001b[0m running on port \u001b[31m"+config.Webserver_Port+"\u001b[0m");
  39.  
  40.     //Sockets
  41.     var io = require("socket.io").listen(http);
  42.     console.log("\u001b[Socket.io\u001b[0m running on port \u001b[31m"+config.Webserver_Port+"\u001b[0m");
  43.     io.sockets.on("connection", function(socket) {
  44.         //Login request
  45.         socket.on(0, function(data) {
  46.        
  47.             console.log("A");
  48.             usersModel.count( {"mail": data.mail, "password": data.password}, function(error, count)
  49.              {
  50.                 console.log(count);
  51.                 if(error) throw error;
  52.                 if(count == 0){
  53.                     socket.emit(1, {"login":"0"});
  54.                 }else{
  55.                     socket.emit(1, {"login":"1"});
  56.                 }
  57.              });
  58.         });
  59.     });
  60. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top