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