Commit 325b03905c5866e236779c341eb92215ccc69402
Exists in
master
and in
2 other branches
Merge branch 'master' into 'master'
Master See merge request !6
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 | $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('/'); |
17 | $scope.$emit('blur'); | 21 | $scope.$emit('blur'); |
18 | }, function(error) { | 22 | }, function(error) { |
19 | if (error.status === 401) { | 23 | if (error.status === 401) { |
20 | 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'); |
21 | } | 25 | } |
22 | 26 | ||
23 | if(error.status === -1) { | 27 | if(error.status === -1) { |
24 | focaModalService.alert('Sin servicio'); | 28 | focaModalService.alert('Sin servicio'); |
25 | return; | 29 | return; |
26 | } | 30 | } |
27 | }); | 31 | }); |
28 | }; | 32 | }; |
29 | $scope.irPaso = function(numeroPaso) { | 33 | $scope.irPaso = function(numeroPaso) { |
30 | $scope.paso = numeroPaso; | 34 | $scope.paso = numeroPaso; |
31 | }; | 35 | }; |
32 | } | 36 | } |
33 | ]) | 37 | ]) |
34 | .controller('focaLogoutController', [ | 38 | .controller('focaLogoutController', [ |
35 | '$cookies', '$location', | 39 | '$cookies', '$location', |
36 | function($cookies, $location) { | 40 | function($cookies, $location) { |
37 | $cookies.remove('chofer'); | 41 | $cookies.remove('chofer'); |
38 | $cookies.remove('vendedorCobrador'); | 42 | $cookies.remove('vendedorCobrador'); |
39 | $cookies.remove('token'); | 43 | $cookies.remove('token'); |
40 | //Cierra ventana | 44 | //Cierra ventana |
41 | window.open('', '_self', ''); //bug fix | 45 | window.open('', '_self', ''); //bug fix |
42 | window.close(); | 46 | window.close(); |
43 | $location.path('/login'); | 47 | $location.path('/login'); |
44 | } | 48 | } |
45 | ]); | 49 | ]); |