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 | 1 | angular.module('focaLogin', ['ngRoute', 'ngCookies', 'focaDirectivas']) |
2 | 2 | .run(['$rootScope', '$cookies', '$location', function($rootScope, $cookies, $location) { |
3 | 3 | $rootScope.$on('$locationChangeStart', function() { |
4 | - var idUsuario = $cookies.get('idUsuario'); | |
5 | - if(!idUsuario) { | |
4 | + if(!$cookies.get('token')) { | |
6 | 5 | if($location.path() !== '/login') { |
7 | 6 | $location.path('/login'); |
8 | 7 | } |
src/js/controller.js
... | ... | @@ -5,10 +5,20 @@ angular.module('focaLogin') |
5 | 5 | $scope.paso = 1; |
6 | 6 | $scope.enviar = function() { |
7 | 7 | focaLoginService.login($scope.usuario).then(function(datos) { |
8 | - $cookies.put('idUsuario', $scope.usuario.idUsuario); | |
9 | 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 | 16 | $location.path('/'); |
11 | 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 | 24 | $scope.irPaso = function(numeroPaso) { |
... | ... | @@ -19,7 +29,8 @@ angular.module('focaLogin') |
19 | 29 | .controller('focaLogoutController', [ |
20 | 30 | '$cookies', '$location', |
21 | 31 | function($cookies, $location) { |
22 | - $cookies.remove('idUsuario'); | |
32 | + $cookies.remove('chofer'); | |
33 | + $cookies.remove('vendedorCobrador'); | |
23 | 34 | $cookies.remove('token'); |
24 | 35 | $location.path('/login'); |
25 | 36 | } |
src/js/service.js
1 | 1 | angular.module('focaLogin') |
2 | 2 | .service('focaLoginService', [ |
3 | - '$http', 'API_ENDPOINT', | |
4 | - function($http, API_ENDPOINT) { | |
3 | + '$http', 'API_ENDPOINT', 'APP', | |
4 | + function($http, API_ENDPOINT, APP) { | |
5 | 5 | return { |
6 | 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 | } |