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