diff --git a/LICENSE.md b/LICENSE.md old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/controller/controller.js b/controller/controller.js old mode 100644 new mode 100755 index 87a8686..8678f3c --- a/controller/controller.js +++ b/controller/controller.js @@ -18,6 +18,7 @@ module.exports = function (app,io){ var user={ "name":req.body.name, "handle":req.body.handle, + "password":req.body.password, "phone":req.body.phone, "email":req.body.email, }; @@ -46,19 +47,24 @@ module.exports = function (app,io){ var private=null; var users={}; var keys={}; - app.get('/login',function(req,res){ + + app.post('/login',function(req,res){ + console.log("FUKKKK"); + console.log(req.body.handle); res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader("Access-Control-Allow-Method","'GET, POST, OPTIONS, PUT, PATCH, DELETE'"); - handle = req.query.handle; - models.user.findOne({"handle":handle},function(err,doc){ + handle = req.body.handle; + models.user.findOne({"handle":req.body.handle, "password":req.body.password},function(err,doc){ if(err){ - res.json(err); + res.send(err); } if(doc==null){ res.send("User has not registered"); } else{ - res.sendFile(path.resolve(__dirname+"/../views/chat1.html")); + console.log("Asas"+__dirname); +// res.sendFile(path.resolve(__dirname+"/../views/chat1.html")); + res.send("success"); } }); @@ -158,36 +164,51 @@ module.exports = function (app,io){ app.post('/friend_request/confirmed',function(req,res){ console.log("friend request confirmed : "+req.body); if(req.body.confirm=="Yes"){ - models.user.update({ - "handle":req.body.my_handle, - "friends.name":req.body.friend_handle - },{ - '$set':{ - "friends.$.status":"Friend" - } - },function(err,doc){ - if(err){res.json(err);} - else{ + models.user.find({ + "handle" : req.body.friend_handle, + "friends.name":req.body.my_handle + },function(err,doc){ + if(err){ + res.json(err); + } + else if(doc.length!=0){ + console.log("Friend request confirmed : "+doc.length); + console.log("Friend request confirmed : friend request already sent "+doc); + res.send("Friend request already accepted"); + } + else{ + models.user.update({ + "handle":req.body.my_handle, + "friends.name":req.body.friend_handle + },{ + '$set':{ + "friends.$.status":"Friend" + } + },function(err,doc){ + if(err){res.json(err);} + else{ - console.log("friend request confirmed : Inside yes confirmed"); - io.to(users[req.body.friend_handle]).emit('friend', req.body.my_handle); - io.to(users[req.body.my_handle]).emit('friend', req.body.friend_handle); - } - }); - models.user.update({ - handle:req.body.friend_handle - },{ - $push:{ - friends:{ - name: req.body.my_handle, - status: "Friend" - } + console.log("friend request confirmed : Inside yes confirmed"); + io.to(users[req.body.friend_handle]).emit('friend', req.body.my_handle); + io.to(users[req.body.my_handle]).emit('friend', req.body.friend_handle); + } + }); + models.user.update({ + handle:req.body.friend_handle + },{ + $push:{ + friends:{ + name: req.body.my_handle, + status: "Friend" + } + } + },{upsert:true},function(err,doc){ + if(err){res.json(err);} + // else{ + // console.log(doc); + // } + }); } - },{upsert:true},function(err,doc){ - if(err){res.json(err);} - // else{ - // console.log(doc); - // } }); } else{ diff --git a/model/model.js b/model/model.js old mode 100644 new mode 100755 index 8e7d541..61b3e21 --- a/model/model.js +++ b/model/model.js @@ -17,6 +17,7 @@ mongoose.connect('mongodb://localhost/mongodb'); module.exports.user=mongoose.model('User',new Schema({ name:String, handle: String, + password: String, phone:String, email:String, friends:[] diff --git a/package.json b/package.json old mode 100644 new mode 100755 diff --git a/screenshots/chat.png b/screenshots/chat.png old mode 100644 new mode 100755 diff --git a/screenshots/online_users.png b/screenshots/online_users.png old mode 100644 new mode 100755 diff --git a/screenshots/recieving_request.png b/screenshots/recieving_request.png old mode 100644 new mode 100755 diff --git a/screenshots/sending_request.png b/screenshots/sending_request.png old mode 100644 new mode 100755 diff --git a/server.js b/server.js old mode 100644 new mode 100755 diff --git a/views/angular/controller.js b/views/angular/controller.js old mode 100644 new mode 100755 index 0da3fc9..b27fa25 --- a/views/angular/controller.js +++ b/views/angular/controller.js @@ -1,4 +1,4 @@ -var app = angular.module('myapp',['ngMaterial']); +var app = angular.module('myapp',['ngMaterial','ui.router']); app.factory('socket', ['$rootScope', function($rootScope) { var socket = io.connect(); @@ -13,7 +13,49 @@ app.factory('socket', ['$rootScope', function($rootScope) { }; }]); -app.controller('myController',['$scope','socket','$http','$mdDialog','$compile',function($scope,socket,$http,$mdDialog,$compile){ +app.config(['$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider){ + $urlRouterProvider.otherwise('/'); + $stateProvider + .state('login',{ + url:'/', + views:{ + 'body':{ + templateUrl:'/views/login.html', + controller:'registerController' + } + } + }) + .state('loggedin',{ + url:'/login', + views:{ + 'body':{ + templateUrl:'/views/chat.html', + controller:'myController' + } + } + }) +}]); + + + + +app.directive('myEnter', function () { + return function (scope, element, attrs) { + element.bind("keydown keypress", function (event) { + if(event.which === 13) { + scope.$apply(function (){ + scope.$eval(attrs.myEnter); + }); + + event.preventDefault(); + } + }); + }; +}); + + +app.controller('myController',['$scope','socket','$http','$mdDialog','$compile','$location','$state',function($scope,socket,$http,$mdDialog,$compile,$location,$state){ + url= location.host; $scope.users=[]; $scope.online_friends=[]; $scope.allfriends=[]; @@ -75,7 +117,7 @@ app.controller('myController',['$scope','socket','$http','$mdDialog','$compile', // } // }; - $http({method: 'POST',url:'http://localhost:8080/friend_request',data})//, headers:config}) + $http({method: 'POST',url:'http://'+url+'/friend_request',data})//, headers:config}) .success(function (data) { console.log(data) }) @@ -96,14 +138,14 @@ app.controller('myController',['$scope','socket','$http','$mdDialog','$compile', $mdDialog.show(confirm).then(function() { data['confirm']="Yes"; - $http({method: 'POST',url:'http://localhost:8080/friend_request/confirmed', data//, headers:{ + $http({method: 'POST',url:'http://'+url+'/friend_request/confirmed', data//, headers:{ //'Content-Type': 'application/json' //} }) }, function() { data['confirm']="No"; - $http({method: 'POST',url:'http://localhost:8080/friend_request/confirmed', data//, headers:{ + $http({method: 'POST',url:'http://'+url+'/friend_request/confirmed', data//, headers:{ // 'Content-Type': 'application/json' //} }) @@ -312,27 +354,69 @@ app.controller('myController',['$scope','socket','$http','$mdDialog','$compile', } } } - - //displays the popups. Displays based on the maximum number of popups that can be displayed on the current viewport width - function display_popups() - { - document.getElementById(popups[popups.length-2]+"01").className=document.getElementById(popups[popups.length-2]+"01").className.replace(/(?:^|\s)popup-box-on(?!\S)/g , ''); - document.getElementById(popups[popups.length-1]+"01").className += "popup-box-on"; - } +// +// //displays the popups. Displays based on the maximum number of popups that can be displayed on the current viewport width +// function display_popups() +// { +// document.getElementById(popups[popups.length-2]+"01").className=document.getElementById(popups[popups.length-2]+"01").className.replace(/(?:^|\s)popup-box-on(?!\S)/g , ''); +// document.getElementById(popups[popups.length-1]+"01").className += "popup-box-on"; +// } }]); +app.service('encrypt', function() { + this.hash =function(str){ + h = 7; + letters = "abcdefghijklmnopqrstuvwxyz-_1234567890@!#$%&*.," + for (var i=0;i - -
-
-

{{friend}}

- -
- - - + +