controller.js
1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
angular.module('focaLogin')
.controller('focaLoginController', [
'$scope', 'focaLoginService', '$location', '$cookies', 'focaModalService',
function($scope, focaLoginService, $location, $cookies, focaModalService) {
$scope.paso = 1;
$scope.enviar = function() {
focaLoginService.login($scope.usuario).then(function(datos) {
if (datos.data.chofer && datos.data.chofer.id) {
$cookies.put('chofer', datos.data.chofer.id);
} else if (datos.data.vendedorCobrador && datos.data.vendedorCobrador.CodVen) {
$cookies.put('vendedorCobrador', datos.data.vendedorCobrador.CodVen);
} else {
focaModalService.alert('Existe un error con el usuario ingresado');
return;
}
console.info(datos.data);
$cookies.put('token', datos.data.token);
$location.path('/');
$scope.$emit('blur');
}, function(error) {
if (error.status === 401) {
focaModalService.alert('El usuario o la contraseña han sido mal introducidos');
}
if(error.status === -1) {
focaModalService.alert('Sin servicio');
return;
}
});
};
$scope.irPaso = function(numeroPaso) {
$scope.paso = numeroPaso;
};
}
])
.controller('focaLogoutController', [
'$cookies', '$location',
function($cookies, $location) {
$cookies.remove('chofer');
$cookies.remove('vendedorCobrador');
$cookies.remove('token');
//Cierra ventana
window.open('', '_self', ''); //bug fix
window.close();
$location.path('/login');
}
]);