Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.controller('registroCtrl', function ($scope, $rootScope, $http, $localStorage, $sessionStorage, $window, $location) {
- $rootScope.regUser = {
- 'name':'',
- 'lastname':'',
- 'email':'',
- 'phone':'',
- 'password':''
- };
- $scope.usr = {};
- $scope.confirmPassword = '';
- $scope.RegUser= function(){
- // console.log($rootScope.regUser);
- $http({
- method: 'POST',
- url: 'http://api.warningbeeps.com/GPS/Service/Service_UsrRegister.svc/register',
- headers: {
- 'Content-Type': 'application/json'
- },
- data:$rootScope.regUser
- }).then(function successCallback(response) {
- $rootScope.user_id = response.data.objetoResultado;
- console.log($rootScope.user_id);
- $window.localStorage.setItem('user_id', response.data.objetoResultado);
- $location.path('/mapa/profile');
- //objetoResultado is to be saved as user_id
- }, function errorCallback(response) {
- console.log("error");
- });
- };
- $scope.dechex = function(n){
- return n.toString(16);
- }
- $scope.intval = function(n){
- return parseInt(n.toString());
- }
- $scope.encpwd = function(password){
- // alert(password);
- var key = new Array(16);
- var dst = new Array(16);
- var nBytes = password.length;
- var i = 0;
- var rslt;
- var one, two, three, four;
- while(i<nBytes){
- key[i] = parseInt(password.charCodeAt(i));
- dst[i] = key[i];
- i++;
- }
- while(i<16){
- key[i] = 0;
- dst[i] = key[i];
- i++;
- }
- rslt = key[0] + key[1] * 256 + key[2] * 65536 + key[3] * 16777216;
- one = rslt * 213119 + 2529077;
- one = one - $scope.intval(one / 4294967296) * 4294967296;
- rslt = key[4] + key[5] * 256 + key[6] * 65536 + key[7] * 16777216;
- two = rslt * 213247 + 2529089;
- two = two - $scope.intval(two / 4294967296) * 4294967296;
- rslt = key[8] + key[9] * 256 + key[10] * 65536 + key[11] * 16777216;
- three = rslt * 213203 + 2529589;
- three = three - $scope.intval(three / 4294967296) * 4294967296;
- rslt = key[12] + key[13] * 256 + key[14] * 65536 + key[15] * 16777216;
- four = rslt * 213821 + 2529997;
- four = four - $scope.intval(four / 4294967296) * 4294967296;
- key[3] = $scope.intval(one / 16777216);
- key[2] = $scope.intval((one - key[3] * 16777216) / 65535);
- key[1] = $scope.intval((one - key[3] * 16777216 - key[2] * 65536) / 256);
- key[0] = $scope.intval((one - key[3] * 16777216 - key[2] * 65536 - key[1] * 256));
- key[7] = $scope.intval(two / 16777216);
- key[6] = $scope.intval((two - key[7] * 16777216) / 65535);
- key[5] = $scope.intval((two - key[7] * 16777216 - key[6] * 65536) / 256);
- key[4] = $scope.intval((two - key[7] * 16777216 - key[6] * 65536 - key[5] * 256));
- key[11] = $scope.intval(three / 16777216);
- key[10] = $scope.intval((three - key[11] * 16777216) / 65535);
- key[9] = $scope.intval((three - key[11] * 16777216 - key[10] * 65536) / 256);
- key[8] = $scope.intval((three - key[11] * 16777216 - key[10] * 65536 - key[9] * 256));
- key[15] = $scope.intval(four / 16777216);
- key[14] = $scope.intval((four - key[15] * 16777216) / 65535);
- key[13] = $scope.intval((four - key[15] * 16777216 - key[14] * 65536) / 256);
- key[12] =$scope. intval((four - key[15] * 16777216 - key[14] * 65536 - key[13] * 256));
- dst[0] = dst[0] ^ key[0];
- i = 0;
- while (i < 15)
- {
- i++;
- dst[i] = dst[i] ^ dst[i - 1] ^ key[i];
- }
- i = -1;
- while (i < 15)
- {
- i++;
- if (dst[i] == 0)
- {
- dst[i] = 102;
- }
- }
- var sEnc = "0x";
- i = -1;
- while (i < 15)
- {
- i++;
- if (dst[i] < 16)
- {
- sEnc += '0' + $scope.dechex(dst[i]).toUpperCase();
- }
- else
- {
- sEnc += $scope.dechex(dst[i]).toUpperCase();
- }
- }
- //console.log(sEnc);
- return sEnc;
- }
- $scope.submit = function(){
- if($rootScope.regUser.password == $scope.usr.confirmPassword){
- $scope.regUser.password = $scope.encpwd($scope.regUser.password);
- $scope.usr.confirmPassword = $scope.regUser.password;
- $scope.RegUser();
- }else{
- alert("Enter Correct Password");
- }
- };
- });
- app.controller('loginCtrl', function ($scope,$rootScope, $http, $window, $location) {
- $scope.uemail = $window.localStorage.getItem('uemail'),
- $scope.upassword = $window.localStorage.getItem('upassword');
- // console.log($scope.uemail + " - " + $scope.upassword);
- $scope.dechex = function(n){
- return n.toString(16);
- }
- $scope.intval = function(n){
- return parseInt(n.toString());
- }
- $scope.encpwd = function(password){
- // alert(password);
- var key = new Array(16);
- var dst = new Array(16);
- var nBytes = password.length;
- var i = 0;
- var rslt;
- var one, two, three, four;
- while(i<nBytes){
- key[i] = parseInt(password.charCodeAt(i));
- dst[i] = key[i];
- i++;
- }
- while(i<16){
- key[i] = 0;
- dst[i] = key[i];
- i++;
- }
- rslt = key[0] + key[1] * 256 + key[2] * 65536 + key[3] * 16777216;
- one = rslt * 213119 + 2529077;
- one = one - $scope.intval(one / 4294967296) * 4294967296;
- rslt = key[4] + key[5] * 256 + key[6] * 65536 + key[7] * 16777216;
- two = rslt * 213247 + 2529089;
- two = two - $scope.intval(two / 4294967296) * 4294967296;
- rslt = key[8] + key[9] * 256 + key[10] * 65536 + key[11] * 16777216;
- three = rslt * 213203 + 2529589;
- three = three - $scope.intval(three / 4294967296) * 4294967296;
- rslt = key[12] + key[13] * 256 + key[14] * 65536 + key[15] * 16777216;
- four = rslt * 213821 + 2529997;
- four = four - $scope.intval(four / 4294967296) * 4294967296;
- key[3] = $scope.intval(one / 16777216);
- key[2] = $scope.intval((one - key[3] * 16777216) / 65535);
- key[1] = $scope.intval((one - key[3] * 16777216 - key[2] * 65536) / 256);
- key[0] = $scope.intval((one - key[3] * 16777216 - key[2] * 65536 - key[1] * 256));
- key[7] = $scope.intval(two / 16777216);
- key[6] = $scope.intval((two - key[7] * 16777216) / 65535);
- key[5] = $scope.intval((two - key[7] * 16777216 - key[6] * 65536) / 256);
- key[4] = $scope.intval((two - key[7] * 16777216 - key[6] * 65536 - key[5] * 256));
- key[11] = $scope.intval(three / 16777216);
- key[10] = $scope.intval((three - key[11] * 16777216) / 65535);
- key[9] = $scope.intval((three - key[11] * 16777216 - key[10] * 65536) / 256);
- key[8] = $scope.intval((three - key[11] * 16777216 - key[10] * 65536 - key[9] * 256));
- key[15] = $scope.intval(four / 16777216);
- key[14] = $scope.intval((four - key[15] * 16777216) / 65535);
- key[13] = $scope.intval((four - key[15] * 16777216 - key[14] * 65536) / 256);
- key[12] =$scope. intval((four - key[15] * 16777216 - key[14] * 65536 - key[13] * 256));
- dst[0] = dst[0] ^ key[0];
- i = 0;
- while (i < 15)
- {
- i++;
- dst[i] = dst[i] ^ dst[i - 1] ^ key[i];
- }
- i = -1;
- while (i < 15)
- {
- i++;
- if (dst[i] == 0)
- {
- dst[i] = 102;
- }
- }
- var sEnc = "0x";
- i = -1;
- while (i < 15)
- {
- i++;
- if (dst[i] < 16)
- {
- sEnc += '0' + $scope.dechex(dst[i]).toUpperCase();
- }
- else
- {
- sEnc += $scope.dechex(dst[i]).toUpperCase();
- }
- }
- //console.log(sEnc);
- return sEnc;
- }
- $scope.login = {
- email:'',
- password:''
- };
- $scope.loginSubmit = function(u,p){
- $http({
- method: 'GET',
- url: 'http://api.warningbeeps.com/GPS/Service/Service_ValidateUser.svc/Validate/'+ u +'/' +p,
- headers: {
- 'Content-Type': 'application/json'
- }
- }).then(function successCallback(response) {
- console.log(response);
- //objetoResultado is to be saved as user_id
- if(response.data>0){
- $rootScope.user_id = response.data;
- $window.localStorage.setItem('user_id', response.data);
- $window.localStorage.setItem('uemail', u),
- $window.localStorage.setItem('upassword', p);
- $location.path('mapa/tab4/map');
- }
- }, function errorCallback(response) {
- console.log("error");
- });
- }
- $scope.login = function(){
- $scope.loginSubmit($scope.login.email,$scope.encpwd($scope.login.password));
- }
- if(!($scope.uemail === null || $scope.upassword === null)){
- $scope.loginSubmit($scope.uemail,$scope.upassword);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement