Files
MASA/app/js/login/login.services.js
Reynaldo Reyes 90d22e3405 Initial commit
2016-02-29 00:49:18 -04:30

57 lines
1.6 KiB
JavaScript

(function(){
'use strict';
angular
.module('app.login')
.factory('Login', Login)
.factory('Rol', Rol)
.factory('GetRol', GetRol)
.factory('hash', hash)
.value('algoritmo','SHA-1')
.value('user',{})
.value('id',{})
Login.$inject = ['$resource','$rootScope'];
function Login($resource, $rootScope){
return $resource('http://'+$rootScope.domainUrl+'/api/VerifyUser');
};
Rol.$inject = ['$resource','$rootScope'];
function Rol($resource, $rootScope){
return $resource('http://'+$rootScope.domainUrl+'/api/Rol');
};
GetRol.$inject = ['$resource','$rootScope'];
function GetRol($resource, $rootScope){
return $resource('http://'+$rootScope.domainUrl+'/api/User/:id');
};
hash.$inject = ['algoritmo'];
function hash(algoritmo){
var hashFunction;
if (algoritmo==="MD5") {
hashFunction=CryptoJS.MD5;
} else if (algoritmo==="SHA-1") {
hashFunction=CryptoJS.SHA1;
} else if (algoritmo==="SHA-2-256") {
hashFunction=CryptoJS.SHA256;
} else if (algoritmo==="SHA-2-512") {
hashFunction=CryptoJS.SHA512;
} else {
throw Error("El tipo de algoritmo no es válido:"+algoritmo);
}
var hash=function(message) {
var objHashResult=hashFunction(message);
var strHashResult=objHashResult.toString(CryptoJS.enc.Base64);
return strHashResult;
}
return hash;
};
})();