Skip to content

Commit

Permalink
azure deployement
Browse files Browse the repository at this point in the history
  • Loading branch information
babatech committed Dec 14, 2016
1 parent 6fe4a27 commit 3c660b8
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 57 deletions.
16 changes: 5 additions & 11 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
console.log('baba start time:'+Date.now());
var mysql = require('mysql');
var settings = require('./config/config');
var mysqlConn = mysql.createConnection(settings.Database);
mysqlConn.connect(function(err){

if(!err) {
console.log('Database is connected!');

} else {
console.log('Error connecting database!'+err);
}
});
var mysqlConn = require('./config/db');

var express = require('express');
var session = require('express-session');
Expand Down Expand Up @@ -62,7 +53,10 @@ app.use(session({
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session

app.use(function(req, res, next) {
res.locals.messages = req.flash();
next();
});
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
Expand Down
5 changes: 0 additions & 5 deletions config/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,5 @@ module.exports = {
'callbackURL' : 'http://localhost:3000/auth/twitter/callback'
},

'googleAuth' : {
'clientID' : 'your-secret-clientID-here',
'clientSecret' : 'your-client-secret-here',
'callbackURL' : 'http://localhost:3000/auth/google/callback'
}

};
12 changes: 11 additions & 1 deletion config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
*/
// config/auth.js
module.exports = {
'baseURL' : "http://localhost:3000",
'baseURL' : "http://asp-fh-kiel.azurewebsites.net",
'baseURLlocal' : "http://localhost:3000",
'baseURLazure' : "http://asp-fh-kiel.azurewebsites.net",

'Database' : {

'host' : '127.0.0.1',
'user' : 'asp',
'password' : 'hidden',
'database' : 'asp'
},
"onlineDatabase":{
'host' : 'sql7.freemysqlhosting.net',
'user' : 'sql7149348',
'password' : 'lVZ2ULhQdC',
'database' : 'sql7149348',
'port':"3306",
"accountpassword":"Fjxe$ykib0Rcbmkn"
}
};
8 changes: 4 additions & 4 deletions config/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ var mysql = require('mysql');
var settings = require('./config');
var db;
var exports = {};
exports.connectdb = function () {
//exports.connectdb = function () {
// if (!db){
db = mysql.createConnection(settings.Database);
db = mysql.createConnection(settings.onlineDatabase);

db.connect(function(err){

Expand All @@ -18,6 +18,6 @@ exports.connectdb = function () {
}
});
// }
}
//}

module.exports = exports;
module.exports = db;
21 changes: 14 additions & 7 deletions config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,21 @@ module.exports = function(passport,databaseConnection) {
var result = usermodule.login(email,password);
if(result === true )
{
req.flash("successmessage", "Welcome ");
console.log('usercraeted');
user["email"]=email;
user["status"]=true;
user["name"]="John Snow";
user["name"]=email;
user["avatar"]="";
user["loginStatus"]=true;
return done(null, user);
}else{
req.flash("errormessage", "Invalide email or password!");
user["msg"]="User not exists";
console.log('error ');
}
}else{
req.flash("errormessage", "Invalide email!");
user["msg"]="invalide email";
console.log("out");
}
Expand Down Expand Up @@ -94,21 +97,24 @@ module.exports = function(passport,databaseConnection) {
var result = usermodule.createuser(email,password);
if(result === true )
{
req.flash("successmessage", "You have sign up successfully ");
//console.log('usercraeted');
user["email"]=email;
user["status"]=true;
user["name"]="John Snow";
user["name"]=email;
user["avatar"]="";
user["loginStatus"]=true;
return done(null, user);

}else{

console.log('error ');
req.flash("errormessage", "sign up ptocess failed");
//console.log('error ');
}
}else{
console.log("out");
req.flash("errormessage", "Invalide email!");
//console.log("out");
}
return done(null, user);
return done(null,false, user);

});

Expand Down Expand Up @@ -167,7 +173,7 @@ module.exports = function(passport,databaseConnection) {
var user={};


var result = usermodule.fblogin(profile.emails[0].value,profile.id);
var result = usermodule.fblogin(profile.emails[0].value,profile.id,profile.name.givenName);


user["id"]=profile.id;
Expand All @@ -177,6 +183,7 @@ module.exports = function(passport,databaseConnection) {
user["name"]=profile.name.givenName + ' ' + profile.name.familyName;;
user["avatar"]="";
user["loginStatus"]=true;
//req.flash("successmessage", "Welcome "+user["name"]);
return done(null, user);
});

Expand Down
10 changes: 5 additions & 5 deletions models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module.exports = function(databaseConnection) {
login: function(email,password) {

var userdetails = { name:email, password:password};
if ( databaseConnection == null ) console.log('still nul');
else console.log('not nul');
//if ( databaseConnection == null ) console.log('still nul');
//else console.log('not nul');

databaseConnection.query("SELECT * FROM users where email = '"+email+"' and password = '"+password +"'", function (err, result) {
if(err)
{
console.log(result[0]+' err');
console.log('err:'+err);
return null;
}
else {
Expand All @@ -21,7 +21,7 @@ module.exports = function(databaseConnection) {
// console.log('The solution is: ', result); // object difference result is same
});
},
fblogin: function(email,profileid) {
fblogin: function(email,profileid,name) {
//var userdetails = { name:email, password:profileid};
databaseConnection.query("SELECT * FROM users where email = '"+email+"' and password = '"+profileid +"'", function (err, result) {
if(err)
Expand All @@ -33,7 +33,7 @@ module.exports = function(databaseConnection) {
else {
//console.log(result[0] + ' ress' );
if (typeof result[0] === "undefined" ){
var userdetails = { name:email, password:profileid};
var userdetails = { name:name,email:email, password:profileid};
databaseConnection.query('INSERT INTO users SET ?', userdetails, function(err,res){
if(err)
{console.log('err in insert fb');
Expand Down
6 changes: 5 additions & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ body { padding-top: 60px; }
}
.checkbox input[type="checkbox"].rememberme{
margin-left: 0;
}
}
.btn-login-facebook{
background: #3B5998;
color: #ffffff;
}
93 changes: 84 additions & 9 deletions public/scripts/globle.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ var autocomplete;
var cityn;
var positionTimer,usermarker,shareusermarker;
var NearbyAttarctions={};
var selectedNearbyAttarctions={};
var selectedNearbyAttarctions=[];
var infoWindows=[];


function initMap() {
var mapelemtn =document.getElementById('map');
if (typeof mapelemtn !== 'undefined'){
//alert();
}
if(typeof map === 'undefined' && typeof mapelemtn !== 'undefined' ){
if(typeof map === 'undefined' && $("#map").is(':visible') ){

map = new google.maps.Map(mapelemtn, {
zoom: 2,
Expand Down Expand Up @@ -204,20 +205,35 @@ $(document).ready(function(){

event.preventDefault();
});
$(".make-route").click(function(event) {
if(selectedNearbyAttarctions === undefined || Object.keys(selectedNearbyAttarctions).length === 0){
alert("Please select point of attraction first. ");
return false;
}
drawPOIRoute();
event.preventDefault();
});
$( ".toggle-map-plan-panel" ).click(function() {
$( ".map-plan-panel" ). toggleClass( "hidden" );
$( ".map-plan-panel" ). toggleClass( "toggled-poi" );
$( ".make-route" ). toggleClass( "hidden" );
$( ".map-city-panel" ). toggleClass( "hidden" );
initMap();
});
$( ".get-current-location" ).click(function() {
getbrowserGeolocation();
});
$(document).on('change', '.addselectedNearbyAttarction[type=checkbox]', function() {

if($( this ).is(":checked")) {
var placeID= $( this ).val();
if($( this ).is(":checked")) {

addselectedNearbyAttarction(placeID);
createMarker(selectedNearbyAttarctions[placeID]);
//console.log(placeID);
}else{

selectedNearbyAttarctions[placeID]["markerref"].setMap(null);
removeselectedNearbyAttarction(placeID);
//createMarker(selectedNearbyAttarctions[placeID]);
}
});

Expand Down Expand Up @@ -387,11 +403,13 @@ function createMarker(place) {
position: place.geometry.location/*,
icon:place.icon*/
});

infoWindows[place.id] = new google.maps.InfoWindow({map: map});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
infoWindows[place.id].setContent(place.name);
infoWindows[place.id].open(map, this);
});
selectedNearbyAttarctions[place.id]["markerref"] = marker;
selectedNearbyAttarctions[place.id]["markerinfo"] = infoWindows[place.id];
}

function makePanel(place) {
Expand Down Expand Up @@ -490,10 +508,67 @@ socket.on('get-user-location-request', function(data){
socket.on('share-user-not-online', function(data){
alert("user not active on site");
});

var lastselectionmarker=null;
function addselectedNearbyAttarction(placeID) {
if(typeof autocomplete !== 'undefined'){
selectedNearbyAttarctions[placeID]=NearbyAttarctions[placeID];
lastselectionmarker=NearbyAttarctions[placeID];
}

}
function removeselectedNearbyAttarction(placeID) {
delete selectedNearbyAttarctions[placeID];
}
function drawPOIRoute() {
if(selectedNearbyAttarctions === undefined || Object.keys(selectedNearbyAttarctions).length === 0){
alert("Please select point of attraction first.");
return false;
}
// Instantiate a directions service.
var directionsService = new google.maps.DirectionsService;
// Create a renderer for directions and bind it to the map.
var directionsDisplay = new google.maps.DirectionsRenderer({map: map});

// Instantiate an info window to hold step text.
var stepDisplay = new google.maps.InfoWindow;
var waypts = [];
// First, remove any existing markers from the map.
for (poikey in selectedNearbyAttarctions) {
selectedNearbyAttarctions[poikey]["markerref"].setMap(null);
waypts.push({
location: selectedNearbyAttarctions[poikey].geometry.location,
stopover: true
});

}

directionsService.route({
origin: new google.maps.LatLng(pos.lat, pos.lng),
destination: lastselectionmarker.geometry.location,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: 'DRIVING'
}, function(response, status) {
if (status === 'OK') {
directionsDisplay.setDirections(response);
var route = response.routes[0];
console.log(route);
var summaryPanel = document.getElementById('directions-panel');
summaryPanel.innerHTML = '<div class="jumbotron">';
// For each route, display summary information.
for (var i = 0; i < route.legs.length; i++) {
var routeSegment = i + 1;
summaryPanel.innerHTML += '<b>Route Segment: ' + routeSegment +
'</b><br>';
summaryPanel.innerHTML += route.legs[i].start_address + ' to ';
summaryPanel.innerHTML += route.legs[i].end_address + '<br>';
summaryPanel.innerHTML += route.legs[i].distance.text + '<br><br>';
}
summaryPanel.innerHTML += "</div>";
} else {
window.alert('Directions request failed due to ' + status);
}
});


}
9 changes: 8 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ module.exports = function( express,passport,databaseConnection ) {
/* GET about page. */
router.get('/about', function(req, res, next) {
header["title"] = 'About Us';
req.flash("errormessage", "test message");


console.log(res.locals.messages);
//console.log(req.session);
res.render('about', { header: header,user: user,title: 'About us' });
});
Expand Down Expand Up @@ -84,6 +87,10 @@ module.exports = function( express,passport,databaseConnection ) {

router.get('/logout', function(req, res) {
req.logout();
user['name'] = "John Snow";
user['avatar'] = "image link";
user['status'] = false;
user['loginStatus'] = false;
res.redirect('/');
});
/*
Expand All @@ -109,6 +116,6 @@ module.exports = function( express,passport,databaseConnection ) {
header["title"] = 'Share location with your buddy';
res.render('sharelocation', { header: header,user: user,title: 'Sh' });
});
console.log('baba rout export:'+Date.now());
//console.log('baba rout export:'+Date.now());
return router;
};
7 changes: 5 additions & 2 deletions views/about.jade
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
extends layout

block content
h1= title
p Welcome to #{title}
div.container
div.row
div.col-md-12
h1= title
p Welcome to #{title}
Loading

0 comments on commit 3c660b8

Please sign in to comment.