Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Designed homePage, user-portal; added user database, drone registration & approval system. #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
12 changes: 12 additions & 0 deletions .idea/drola.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/watcherTasks.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

591 changes: 591 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

91 changes: 67 additions & 24 deletions Drola_Base_Node/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,70 @@
var express = require("express");
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
//var re=require("socket");
var CronJob = require('cron').CronJob;

var app = express();
let express = require("express");
let cookieParser = require('cookie-parser');
let path = require('path');
let expressValidator = require('express-validator');
let flash = require('connect-flash');
let session = require('express-session');
let passport = require('passport');
let mongoose = require('mongoose');

//let re=require("socket");

// Connecting database
mongoose.connect('mongodb://localhost/droneSystem');

// Initializing express app
let app = express();
app.use(cookieParser());
app.use(bodyParser.json());

var router = express.Router();
var path = __dirname + '/';
// Setting the view-engine
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

let index = require('./routes/index');
let admin = require('./routes/admin');

// Express Session
app.use(session({
secret: 'secret',
saveUninitialized: true,
resave: true
}));

// Express Validator
app.use(expressValidator({
errorFormatter: function(param, msg, value) {
let namespace = param.split('.')
, root = namespace.shift()
, formParam = root;

while(namespace.length) {
formParam += '[' + namespace.shift() + ']';
}
return {
param : formParam,
msg : msg,
value : value
};
}
}));

// Connect Flash
app.use(flash());

router.use(function (req,res,next) {
// Global Vars
app.use(function (req, res, next) {
res.locals.success_msg = req.flash('success_msg');
res.locals.error_msg = req.flash('error_msg');
res.locals.error = req.flash('error');
res.locals.user = req.user || null;
next();
});

router.get("/",function(req,res){
//checkAndredirect(req,res);
res.sendFile(path + "web/index.html");
});

app.use("/",router);
// Associating the routes
app.use("/",index);
app.use('/admin', admin);
app.use("/css",express.static('web/css'));
app.use("/assets",express.static('web/assets'));
app.use("/js",express.static('web/js'));
app.use("/images",express.static('web/images'));
app.use("/fonts",express.static('web/fonts'));
Expand All @@ -33,10 +76,10 @@ app.listen(3000,function(){

///================Web socket server ======================//
/*
var WebSocketServer = require('websocket').server;
var http = require('http');
let WebSocketServer = require('websocket').server;
let http = require('http');

var server = http.createServer(function(request, response) {
let server = http.createServer(function(request, response) {
console.log((new Date()) + ' Received request for ' + request.url);
response.writeHead(404);
response.end();
Expand All @@ -45,15 +88,15 @@ server.listen(8080, function() {
console.log((new Date()) + 'Data Socket is listening on port 8080');
});

var wsServer = new WebSocketServer({
let wsServer = new WebSocketServer({
httpServer: server,

autoAcceptConnections: false
});

var listners=[];
let listners=[];
function notifyListners(){
for (var j=0;j=listners.length;j++){
for (let j=0;j=listners.length;j++){
if(listners[j]!=undefined) {
listners[j].sendUTF(JSON.stringify([{lat: 8.742579, lng: 80.288086, name: "dr1"}, {
lat: 8.118373,
Expand All @@ -67,7 +110,7 @@ function notifyListners(){

wsServer.on('request', function(request) {

var connection = request.accept('dronelink', request.origin);
let connection = request.accept('dronelink', request.origin);
console.log((new Date()) + ' Connection accepted.');
connection.on('message', function(message) {
if (message.type === 'utf8') {
Expand Down
23 changes: 23 additions & 0 deletions Drola_Base_Node/models/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let mongoose=require('mongoose');

let adminSchema=new mongoose.Schema({
fullName: {
type: String,
required: true
},
phone: {
type: String,
required: true
},
email: {
type: String,
required: true
},
password: {
type: String,
required: true
},
isAdmin: {type: Boolean, default: true}
});

module.exports=mongoose.model("Admin", adminSchema);
34 changes: 34 additions & 0 deletions Drola_Base_Node/models/drone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
let mongoose=require('mongoose');

let droneSchema=new mongoose.Schema({
name: {
type: String,
required: true
},
userId: {
type: String,
required: true
},
droneModel: {
type: String,
required: true
},
droneId: {
type: String,
required: true
},
drone_specs: {
type: String,
required: true
},
loraId: {
type: String,
required: true
},
verification_status: {
type: String,
default: false
}
});

module.exports=mongoose.model("Drone", droneSchema);
49 changes: 49 additions & 0 deletions Drola_Base_Node/models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
let mongoose=require('mongoose');
let bcrypt = require('bcryptjs');

let userSchema=new mongoose.Schema({
name: {
type: String,
required: true
},
username: {
type: String,
required: true
},
email: {
type: String,
required: true
},
password: {
type: String,
required: true
},
isAdmin: {type: Boolean, default: false}
});

let User=module.exports=mongoose.model("User", userSchema);

module.exports.createUser = function(newUser, callback){
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(newUser.password, salt, function(err, hash) {
newUser.password = hash;
newUser.save(callback);
});
});
};

module.exports.getUserByUsername = function(username, callback){
let query = {username: username};
User.findOne(query, callback);
};

module.exports.getUserById = function(id, callback){
User.findById(id, callback);
};

module.exports.comparePassword = function(candidatePassword, hash, callback){
bcrypt.compare(candidatePassword, hash, function(err, isMatch) {
if(err) throw err;
callback(null, isMatch);
});
};
32 changes: 14 additions & 18 deletions Drola_Base_Node/package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
{
"name": "webapp",
"name": "drola_base_node",
"version": "1.0.0",
"description": "",
"main": "socket.js",
"main": "index.js",
"scripts": {
"start": "node index.js"
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.17.2",
"connect": "^3.6.2",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.2",
"connect-flash": "^0.1.1",
"cookie-parser": "^1.4.3",
"csurf": "^1.9.0",
"express": "^4.15.3",
"express-stormpath": "^3.2.0",
"forms": "^1.3.0",
"jade": "^1.11.0",
"json": "^9.0.6",
"mongoose": "^4.10.8",
"node-schedule": "^1.2.3",
"websocket": "^1.0.24",
"xtend": "^4.0.1"
},
"devDependencies": {
"nodemon": "^1.11.0"
"cron": "^1.3.0",
"ejs": "^2.5.8",
"express": "^4.16.3",
"express-session": "^1.15.6",
"express-validator": "^5.1.0",
"mongoose": "^5.0.12",
"passport": "^0.4.0",
"passport-local": "^1.0.0"
}
}
Loading