Commit ad70c73e718006ae726966b64f174b4c1384f151
1 parent
996db0347d
Exists in
master
login segun tipo de aplicacion
Showing
3 changed files
with
21 additions
and
7 deletions
Show diff stats
src/js/app.js
1 | angular.module('focaLogin', ['ngRoute', 'ngCookies', 'focaDirectivas']) | 1 | angular.module('focaLogin', ['ngRoute', 'ngCookies', 'focaDirectivas']) |
2 | .run(['$rootScope', '$cookies', '$location', function($rootScope, $cookies, $location) { | 2 | .run(['$rootScope', '$cookies', '$location', function($rootScope, $cookies, $location) { |
3 | $rootScope.$on('$locationChangeStart', function() { | 3 | $rootScope.$on('$locationChangeStart', function() { |
4 | var idUsuario = $cookies.get('idUsuario'); | 4 | if(!$cookies.get('token')) { |
5 | if(!idUsuario) { | ||
6 | if($location.path() !== '/login') { | 5 | if($location.path() !== '/login') { |
7 | $location.path('/login'); | 6 | $location.path('/login'); |
8 | } | 7 | } |
9 | } | 8 | } |
10 | }); | 9 | }); |
11 | }]); | 10 | }]); |
12 | 11 |
src/js/controller.js
1 | angular.module('focaLogin') | 1 | angular.module('focaLogin') |
2 | .controller('focaLoginController', [ | 2 | .controller('focaLoginController', [ |
3 | '$scope', 'focaLoginService', '$location', '$cookies', | 3 | '$scope', 'focaLoginService', '$location', '$cookies', |
4 | function($scope, focaLoginService, $location, $cookies) { | 4 | function($scope, focaLoginService, $location, $cookies) { |
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('idUsuario', $scope.usuario.idUsuario); | ||
9 | $cookies.put('token', datos.data.token); | 8 | $cookies.put('token', datos.data.token); |
9 | |||
10 | if (datos.data.chofer) { | ||
11 | $cookies.put('chofer', datos.data.chofer.id); | ||
12 | } else if (datos.data.vendedorCobrador) { | ||
13 | $cookies.put('vendedorCobrador', datos.data.vendedorCobrador.CodVen); | ||
14 | } | ||
15 | |||
10 | $location.path('/'); | 16 | $location.path('/'); |
11 | $scope.$emit('blur'); | 17 | $scope.$emit('blur'); |
18 | }, function(error) { | ||
19 | if (error.status === 401) { | ||
20 | alert('El usuario o la contraseña han sido mal introducidos'); | ||
21 | } | ||
12 | }); | 22 | }); |
13 | }; | 23 | }; |
14 | $scope.irPaso = function(numeroPaso) { | 24 | $scope.irPaso = function(numeroPaso) { |
15 | $scope.paso = numeroPaso; | 25 | $scope.paso = numeroPaso; |
16 | }; | 26 | }; |
17 | } | 27 | } |
18 | ]) | 28 | ]) |
19 | .controller('focaLogoutController', [ | 29 | .controller('focaLogoutController', [ |
20 | '$cookies', '$location', | 30 | '$cookies', '$location', |
21 | function($cookies, $location) { | 31 | function($cookies, $location) { |
22 | $cookies.remove('idUsuario'); | 32 | $cookies.remove('chofer'); |
33 | $cookies.remove('vendedorCobrador'); | ||
23 | $cookies.remove('token'); | 34 | $cookies.remove('token'); |
24 | $location.path('/login'); | 35 | $location.path('/login'); |
25 | } | 36 | } |
26 | ]); | 37 | ]); |
src/js/service.js
1 | angular.module('focaLogin') | 1 | angular.module('focaLogin') |
2 | .service('focaLoginService', [ | 2 | .service('focaLoginService', [ |
3 | '$http', 'API_ENDPOINT', | 3 | '$http', 'API_ENDPOINT', 'APP', |
4 | function($http, API_ENDPOINT) { | 4 | function($http, API_ENDPOINT, APP) { |
5 | return { | 5 | return { |
6 | login: function(usuario) { | 6 | login: function(usuario) { |
7 | return $http.post(API_ENDPOINT.URL + '/usuario/login', usuario); | 7 | if (APP) { |
8 | APP = '/' + APP; | ||
9 | } | ||
10 | |||
11 | return $http.post(API_ENDPOINT.URL + '/usuario/login' + APP , usuario); | ||
8 | } | 12 | } |
9 | }; | 13 | }; |
10 | } | 14 | } |
11 | ]); | 15 | ]); |
12 | 16 |