Commit a957e21431cc1ae3dd78e087e2ba465526d0e656

Authored by Nicolás Guarnieri
1 parent 32eadf8739
Exists in master and in 2 other branches demo, develop

fix login

Showing 2 changed files with 7 additions and 5 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaLogin') 1 angular.module('focaLogin')
2 .controller('focaLoginController', [ 2 .controller('focaLoginController', [
3 '$scope', 'focaLoginService', '$location', '$cookies', 'focaModalService', 3 '$scope', 'focaLoginService', '$location', '$cookies', 'focaModalService',
4 function($scope, focaLoginService, $location, $cookies, focaModalService) { 4 function($scope, focaLoginService, $location, $cookies, focaModalService) {
5 $scope.paso = 1; 5 $scope.paso = 1;
6 $scope.enviar = function() { 6 $scope.enviar = function() {
7 focaLoginService.login($scope.usuario).then(function(datos) { 7 focaLoginService.login($scope.usuario).then(function(datos) {
8 8
9 if (datos.data.chofer.id) { 9 if (datos.data.chofer && datos.data.chofer.id) {
10 $cookies.put('chofer', datos.data.chofer.id); 10 $cookies.put('chofer', datos.data.chofer.id);
11 } else if (datos.data.vendedorCobrador.CodVen) { 11 } else if (datos.data.vendedorCobrador && datos.data.vendedorCobrador.CodVen) {
12 $cookies.put('vendedorCobrador', datos.data.vendedorCobrador.CodVen); 12 $cookies.put('vendedorCobrador', datos.data.vendedorCobrador.CodVen);
13 } else { 13 } else {
14 focaModalService.alert('Existe un error con el usuario ingresado'); 14 focaModalService.alert('Existe un error con el usuario ingresado');
15 return; 15 return;
16 } 16 }
17 17
18 18 console.info(datos.data);
19 $cookies.put('token', datos.data.token); 19 $cookies.put('token', datos.data.token);
20 $location.path('/'); 20 $location.path('/');
21 $scope.$emit('blur'); 21 $scope.$emit('blur');
22 }, function(error) { 22 }, function(error) {
23 if (error.status === 401) { 23 if (error.status === 401) {
24 focaModalService.alert('El usuario o la contraseña han sido mal introducidos'); 24 focaModalService.alert('El usuario o la contraseña han sido mal introducidos');
25 } 25 }
26 26
27 if(error.status === -1) { 27 if(error.status === -1) {
28 focaModalService.alert('Sin servicio'); 28 focaModalService.alert('Sin servicio');
29 return; 29 return;
30 } 30 }
31 }); 31 });
32 }; 32 };
33 $scope.irPaso = function(numeroPaso) { 33 $scope.irPaso = function(numeroPaso) {
34 $scope.paso = numeroPaso; 34 $scope.paso = numeroPaso;
35 }; 35 };
36 } 36 }
37 ]) 37 ])
38 .controller('focaLogoutController', [ 38 .controller('focaLogoutController', [
39 '$cookies', '$location', 39 '$cookies', '$location',
40 function($cookies, $location) { 40 function($cookies, $location) {
41 $cookies.remove('chofer'); 41 $cookies.remove('chofer');
42 $cookies.remove('vendedorCobrador'); 42 $cookies.remove('vendedorCobrador');
43 $cookies.remove('token'); 43 $cookies.remove('token');
44 //Cierra ventana 44 //Cierra ventana
45 window.open('', '_self', ''); //bug fix 45 window.open('', '_self', ''); //bug fix
46 window.close(); 46 window.close();
47 $location.path('/login'); 47 $location.path('/login');
48 } 48 }
49 ]); 49 ]);
50 50
1 angular.module('focaLogin') 1 angular.module('focaLogin')
2 .factory('focaLoginService', [ 2 .factory('focaLoginService', [
3 '$http', 'API_ENDPOINT', 'APP', '$cookies', 3 '$http', 'API_ENDPOINT', 'APP', '$cookies',
4 function($http, API_ENDPOINT, APP, $cookies) { 4 function($http, API_ENDPOINT, APP, $cookies) {
5 return { 5 return {
6 login: function(usuario) { 6 login: function(usuario) {
7 var param = '';
8
7 if (APP) { 9 if (APP) {
8 APP = '/' + APP; 10 param = '/' + APP;
9 } 11 }
10 12
11 return $http.post(API_ENDPOINT.URL + '/usuario/login' + APP , usuario); 13 return $http.post(API_ENDPOINT.URL + '/usuario/login' + param , usuario);
12 }, 14 },
13 getLoginData: function() { 15 getLoginData: function() {
14 if ($cookies.get('chofer')) { 16 if ($cookies.get('chofer')) {
15 return {chofer: $cookies.get('chofer')}; 17 return {chofer: $cookies.get('chofer')};
16 } 18 }
17 19
18 if ($cookies.get('vendedorCobrador')) { 20 if ($cookies.get('vendedorCobrador')) {
19 return {vendedorCobrador: $cookies.get('vendedorCobrador')}; 21 return {vendedorCobrador: $cookies.get('vendedorCobrador')};
20 } 22 }
21 } 23 }
22 }; 24 };
23 } 25 }
24 ]); 26 ]);
25 27