Commit 6b3f3e7da5ea5fa2a82b39c9ccf1b50d63a1e01f
1 parent
dbde30ee99
Exists in
master
md5 antes de enviar
Showing
1 changed file
with
6 additions
and
4 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', '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); |
11 | $cookies.put('nombreUsuario', datos.data.chofer.nombre); | 13 | $cookies.put('nombreUsuario', datos.data.chofer.nombre); |
12 | } else if (datos.data.vendedorCobrador && datos.data.vendedorCobrador.id) { | 14 | } else if (datos.data.vendedorCobrador && datos.data.vendedorCobrador.id) { |
13 | $cookies.put('vendedorCobrador', datos.data.vendedorCobrador.id); | 15 | $cookies.put('vendedorCobrador', datos.data.vendedorCobrador.id); |
14 | $cookies.put('nombreUsuario', datos.data.vendedorCobrador.NOM); | 16 | $cookies.put('nombreUsuario', datos.data.vendedorCobrador.NOM); |
15 | } else { | 17 | } else { |
16 | focaModalService.alert('Existe un error con el usuario ingresado'); | 18 | focaModalService.alert('Existe un error con el usuario ingresado'); |
17 | return; | 19 | return; |
18 | } | 20 | } |
19 | 21 | ||
20 | console.info(datos.data); | 22 | console.info(datos.data); |
21 | $cookies.put('token', datos.data.token); | 23 | $cookies.put('token', datos.data.token); |
22 | $location.path('/'); | 24 | $location.path('/'); |
23 | $scope.$emit('blur'); | 25 | $scope.$emit('blur'); |
24 | }, function(error) { | 26 | }, function(error) { |
25 | if (error.status === 401) { | 27 | if (error.status === 401) { |
26 | 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'); |
27 | } | 29 | } |
28 | 30 | ||
29 | if(error.status === -1) { | 31 | if(error.status === -1) { |
30 | focaModalService.alert('Sin servicio'); | 32 | focaModalService.alert('Sin servicio'); |
31 | return; | 33 | return; |
32 | } | 34 | } |
33 | }); | 35 | }); |
34 | }; | 36 | }; |
35 | $scope.irPaso = function(numeroPaso) { | 37 | $scope.irPaso = function(numeroPaso) { |
36 | $scope.paso = numeroPaso; | 38 | $scope.paso = numeroPaso; |
37 | }; | 39 | }; |
38 | } | 40 | } |
39 | ]) | 41 | ]) |
40 | .controller('focaLogoutController', [ | 42 | .controller('focaLogoutController', [ |
41 | '$cookies', '$location', | 43 | '$cookies', '$location', |
42 | function($cookies, $location) { | 44 | function($cookies, $location) { |
43 | $cookies.remove('chofer'); | 45 | $cookies.remove('chofer'); |
44 | $cookies.remove('vendedorCobrador'); | 46 | $cookies.remove('vendedorCobrador'); |
45 | $cookies.remove('nombreUsuario'); | 47 | $cookies.remove('nombreUsuario'); |
46 | $cookies.remove('token'); | 48 | $cookies.remove('token'); |
47 | //Cierra ventana | 49 | //Cierra ventana |
48 | window.open('', '_self', ''); //bug fix | 50 | window.open('', '_self', ''); //bug fix |
49 | window.close(); | 51 | window.close(); |
50 | $location.path('/login'); | 52 | $location.path('/login'); |
51 | } | 53 | } |
52 | ]); | 54 | ]); |
53 | 55 |