Commit 322a93132cba58de50fef000e734cf933dd6928d

Authored by Nicolás Guarnieri
Exists in master

Merge branch 'master' into 'master'

Master(efernandez)

See merge request !5
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); 8 $cookies.put('token', datos.data.token);
9 9
10 if (datos.data.chofer) { 10 if (datos.data.chofer.id) {
11 $cookies.put('chofer', datos.data.chofer.id); 11 $cookies.put('chofer', datos.data.chofer.id);
12 } else if (datos.data.vendedorCobrador) { 12 } else if (datos.data.vendedorCobrador.CodVen) {
13 $cookies.put('vendedorCobrador', datos.data.vendedorCobrador.CodVen); 13 $cookies.put('vendedorCobrador', datos.data.vendedorCobrador.CodVen);
14 } 14 }
15 15
16 $location.path('/'); 16 $location.path('/');
17 $scope.$emit('blur'); 17 $scope.$emit('blur');
18 }, function(error) { 18 }, function(error) {
19 if (error.status === 401) { 19 if (error.status === 401) {
20 focaModalService.alert('El usuario o la contraseña han sido mal introducidos'); 20 focaModalService.alert('El usuario o la contraseña han sido mal introducidos');
21 } 21 }
22 22
23 if(error.status === -1) { 23 if(error.status === -1) {
24 focaModalService.alert('Sin servicio'); 24 focaModalService.alert('Sin servicio');
25 return; 25 return;
26 } 26 }
27 }); 27 });
28 }; 28 };
29 $scope.irPaso = function(numeroPaso) { 29 $scope.irPaso = function(numeroPaso) {
30 $scope.paso = numeroPaso; 30 $scope.paso = numeroPaso;
31 }; 31 };
32 } 32 }
33 ]) 33 ])
34 .controller('focaLogoutController', [ 34 .controller('focaLogoutController', [
35 '$cookies', '$location', 35 '$cookies', '$location',
36 function($cookies, $location) { 36 function($cookies, $location) {
37 $cookies.remove('chofer'); 37 $cookies.remove('chofer');
38 $cookies.remove('vendedorCobrador'); 38 $cookies.remove('vendedorCobrador');
39 $cookies.remove('token'); 39 $cookies.remove('token');
40 //Cierra ventana 40 //Cierra ventana
41 window.open('', '_self', ''); //bug fix 41 window.open('', '_self', ''); //bug fix
42 window.close(); 42 window.close();
43 $location.path('/login'); 43 $location.path('/login');
44 } 44 }
45 ]); 45 ]);
46 46
1 angular.module('focaLogin') 1 angular.module('focaLogin')
2 .service('focaLoginService', [ 2 .factory('focaLoginService', [
3 '$http', 'API_ENDPOINT', 'APP', '$cookies', 3 '$http', 'API_ENDPOINT', 'APP', '$cookies',
4 function($http, API_ENDPOINT, APP, $cookies) { 4 function($http, API_ENDPOINT, APP, $cookies) {
5 return { 5 return {
6 login: function(usuario) { 6 login: function(usuario) {
7 if (APP) { 7 if (APP) {
8 APP = '/' + APP; 8 APP = '/' + APP;
9 } 9 }
10 10
11 return $http.post(API_ENDPOINT.URL + '/usuario/login' + APP , usuario); 11 return $http.post(API_ENDPOINT.URL + '/usuario/login' + APP , usuario);
12 }, 12 },
13 getLoginData: function() { 13 getLoginData: function() {
14 if ($cookies.get('chofer')) { 14 if ($cookies.get('chofer')) {
15 return {chofer: $cookies.get('chofer')}; 15 return {chofer: $cookies.get('chofer')};
16 } 16 }
17 17
18 if ($cookies.get('vendedorCobrador')) { 18 if ($cookies.get('vendedorCobrador')) {
19 return {vendedorCobrador: $cookies.get('vendedorCobrador')}; 19 return {vendedorCobrador: $cookies.get('vendedorCobrador')};
20 } 20 }
21 } 21 }
22 }; 22 };
23 } 23 }
24 ]); 24 ]);
25 25