Browse Source

comprovació de token activada al server, falta afegir headers als request de la app

pull/1/head
nau 8 years ago
parent
commit
7e313047f1
2 changed files with 21 additions and 6 deletions
  1. +17
    -3
      app/www/js/controllers.js
  2. +4
    -3
      server/server.js

+ 17
- 3
app/www/js/controllers.js

@ -1,6 +1,6 @@
//var urlapi="http://localhost:3000/api/";
var urlapi="http://192.168.1.40:3000/api/";
var urlapi="http://localhost:3000/api/";
//var urlapi="http://192.168.1.40:3000/api/";
//localStorage.setItem("c_username", "user2"); //localStorage.setItem("c_username", "user2");
//localStorage.setItem("c_token", ""); //localStorage.setItem("c_token", "");
@ -77,6 +77,7 @@ angular.module('starter.controllers', [])
}, },
function(response) { // optional function(response) { // optional
// failed // failed
console.log(response);
}); });
}; };
@ -110,7 +111,7 @@ angular.module('starter.controllers', [])
}) })
.controller('TravelsCtrl', function($scope, $http, $ionicModal, $timeout) {
.controller('TravelsCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading) {
$scope.travels=""; $scope.travels="";
$scope.travels=JSON.parse(localStorage.getItem('c_travels')); $scope.travels=JSON.parse(localStorage.getItem('c_travels'));
@ -130,6 +131,7 @@ angular.module('starter.controllers', [])
}) })
.then(function(result){ .then(function(result){
travels = result.data; travels = result.data;
$ionicLoading.show({ template: 'Travels actualized from server!', noBackdrop: true, duration: 2000 });
}); });
}; };
@ -200,6 +202,10 @@ angular.module('starter.controllers', [])
$scope.newtravel._id=response.data._id; $scope.newtravel._id=response.data._id;
$scope.travels.push($scope.newtravel); $scope.travels.push($scope.newtravel);
$scope.newtravel={}; $scope.newtravel={};
if(response.data.success==false){
$ionicLoading.show({ template: 'failed to generate new travel', noBackdrop: true, duration: 2000 });
}
}, },
function(response) { // optional function(response) { // optional
// failed // failed
@ -231,6 +237,10 @@ angular.module('starter.controllers', [])
console.log(response); console.log(response);
$scope.newtravel._id=response.data._id; $scope.newtravel._id=response.data._id;
$scope.travels.push($scope.newtravel); $scope.travels.push($scope.newtravel);
if(response.data.success==false){
$ionicLoading.show({ template: 'failed to generate new asking travel', noBackdrop: true, duration: 2000 });
}
}, },
function(response) { // optional function(response) { // optional
// failed // failed
@ -263,6 +273,10 @@ angular.module('starter.controllers', [])
console.log(response); console.log(response);
$scope.newtravel._id=response.data._id; $scope.newtravel._id=response.data._id;
$scope.travels.push($scope.newtravel); $scope.travels.push($scope.newtravel);
if(response.data.success==false){
$ionicLoading.show({ template: 'failed to generate new asking package', noBackdrop: true, duration: 2000 });
}
}, },
function(response) { // optional function(response) { // optional
// failed // failed

+ 4
- 3
server/server.js

@ -71,7 +71,7 @@ apiRoutes.route('/travels')
apiRoutes.route('/travels/:id') apiRoutes.route('/travels/:id')
.get(travelCtrl.findById) .get(travelCtrl.findById)
/* OJU AQUÏ TREC la verificació de token temporalment, per fer les proves des de l'app
// OJU AQUÏ TREC la verificació de token temporalment, per fer les proves des de l'app
// route middleware to verify a token // route middleware to verify a token
apiRoutes.use(function(req, res, next) { apiRoutes.use(function(req, res, next) {
@ -96,13 +96,14 @@ apiRoutes.use(function(req, res, next) {
// if there is no token // if there is no token
// return an error // return an error
return res.status(403).send({
return res.status(201).send({
success: false, success: false,
message: 'No token provided.' message: 'No token provided.'
}); });
} }
});*/
}); //fi verificació de token
apiRoutes.route('/users/:id') apiRoutes.route('/users/:id')
.put(userCtrl.updateUser) .put(userCtrl.updateUser)

Loading…
Cancel
Save