Commit e2ca9a761b3080a1963495aa712721b77212530d
Exists in
master
and in
2 other branches
Merge branch 'master' into 'master'
Master See merge request !8
Showing
1 changed file
 
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 && 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 && datos.data.vendedorCobrador.CodVen) { | 11 | } else if (datos.data.vendedorCobrador && datos.data.vendedorCobrador.id) { | 
| 12 | $cookies.put('vendedorCobrador', datos.data.vendedorCobrador.CodVen); | 12 | $cookies.put('vendedorCobrador', datos.data.vendedorCobrador.id); | 
| 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 | console.info(datos.data); | 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 |