Commit 4b93fedd7249975d086e2625df84ab0ac04eddc5
Exists in
master
Merge branch 'develop' into 'master'
Develop See merge request !11
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', 'md5', |
| 4 | function($scope, focaLoginService, $location, $cookies, focaModalService) { | 4 | function($scope, focaLoginService, $location, $cookies, focaModalService, md5) { |
| 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({ |
| 8 | 8 | idUsuario: $scope.usuario.idUsuario, | |
| 9 | clave: md5.createHash($scope.usuario.clave) | ||
| 10 | }).then(function(datos) { | ||
| 9 | if (datos.data.chofer && datos.data.chofer.id) { | 11 | if (datos.data.chofer && datos.data.chofer.id) { |
| 10 | $cookies.put('chofer', datos.data.chofer.id); | 12 | $cookies.put('chofer', datos.data.chofer.id); |
| 13 | $cookies.put('nombreUsuario', datos.data.chofer.nombre); | ||
| 11 | } else if (datos.data.vendedorCobrador && datos.data.vendedorCobrador.id) { | 14 | } else if (datos.data.vendedorCobrador && datos.data.vendedorCobrador.id) { |
| 12 | $cookies.put('vendedorCobrador', datos.data.vendedorCobrador.id); | 15 | $cookies.put('vendedorCobrador', datos.data.vendedorCobrador.id); |
| 16 | $cookies.put('nombreUsuario', datos.data.vendedorCobrador.NOM); | ||
| 13 | } else { | 17 | } else { |
| 14 | focaModalService.alert('Existe un error con el usuario ingresado'); | 18 | focaModalService.alert('Existe un error con el usuario ingresado'); |
| 15 | return; | 19 | return; |
| 16 | } | 20 | } |
| 17 | 21 | ||
| 18 | console.info(datos.data); | 22 | console.info(datos.data); |
| 19 | $cookies.put('token', datos.data.token); | 23 | $cookies.put('token', datos.data.token); |
| 20 | $location.path('/'); | 24 | $location.path('/'); |
| 21 | $scope.$emit('blur'); | 25 | $scope.$emit('blur'); |
| 22 | }, function(error) { | 26 | }, function(error) { |
| 23 | if (error.status === 401) { | 27 | if (error.status === 401) { |
| 24 | focaModalService.alert('El usuario o la contraseña han sido mal introducidos'); | 28 | focaModalService.alert('El usuario o la contraseña han sido mal introducidos'); |
| 25 | } | 29 | } |
| 26 | 30 | ||
| 27 | if(error.status === -1) { | 31 | if(error.status === -1) { |
| 28 | focaModalService.alert('Sin servicio'); | 32 | focaModalService.alert('Sin servicio'); |
| 29 | return; | 33 | return; |
| 30 | } | 34 | } |
| 31 | }); | 35 | }); |
| 32 | }; | 36 | }; |
| 33 | $scope.irPaso = function(numeroPaso) { | 37 | $scope.irPaso = function(numeroPaso) { |
| 34 | $scope.paso = numeroPaso; | 38 | $scope.paso = numeroPaso; |
| 35 | }; | 39 | }; |
| 36 | } | 40 | } |
| 37 | ]) | 41 | ]) |
| 38 | .controller('focaLogoutController', [ | 42 | .controller('focaLogoutController', [ |
| 39 | '$cookies', '$location', | 43 | '$cookies', '$location', |
| 40 | function($cookies, $location) { | 44 | function($cookies, $location) { |
| 41 | $cookies.remove('chofer'); | 45 | $cookies.remove('chofer'); |
| 42 | $cookies.remove('vendedorCobrador'); | 46 | $cookies.remove('vendedorCobrador'); |
| 47 | $cookies.remove('nombreUsuario'); | ||
| 43 | $cookies.remove('token'); | 48 | $cookies.remove('token'); |
| 44 | //Cierra ventana | 49 | //Cierra ventana |
| 45 | window.open('', '_self', ''); //bug fix | 50 | window.open('', '_self', ''); //bug fix |
| 46 | window.close(); | 51 | window.close(); |
| 47 | $location.path('/login'); | 52 | $location.path('/login'); |
| 48 | } | 53 | } |
| 49 | ]); | 54 | ]); |
| 50 | 55 |