Advertisement
tomasMiddleton

Untitled

Jun 10th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  app.controller('registroCtrl', function ($scope, $rootScope, $http, $localStorage, $sessionStorage, $window, $location) {
  2.  
  3.      $rootScope.regUser = {
  4.         'name':'',
  5.         'lastname':'',
  6.         'email':'',
  7.         'phone':'',
  8.         'password':''
  9.      };
  10.      $scope.usr = {};
  11.      $scope.confirmPassword = '';
  12.  
  13.      $scope.RegUser= function(){
  14.          // console.log($rootScope.regUser);
  15.  
  16.            $http({
  17.             method: 'POST',
  18.             url: 'http://api.warningbeeps.com/GPS/Service/Service_UsrRegister.svc/register',
  19.            headers: {
  20.                'Content-Type': 'application/json'
  21.            },
  22.             data:$rootScope.regUser
  23.             }).then(function successCallback(response) {
  24.               $rootScope.user_id = response.data.objetoResultado;
  25.              console.log($rootScope.user_id);
  26.               $window.localStorage.setItem('user_id', response.data.objetoResultado);
  27.               $location.path('/mapa/profile');
  28.  
  29.                //objetoResultado is to be saved as user_id
  30.  
  31.             }, function errorCallback(response) {
  32.               console.log("error");
  33.             });
  34.      };
  35.  
  36.      
  37.       $scope.dechex = function(n){
  38.         return n.toString(16);
  39.       }
  40.  
  41.       $scope.intval = function(n){
  42.         return parseInt(n.toString());
  43.       }
  44.       $scope.encpwd = function(password){
  45.       //  alert(password);
  46.         var key = new Array(16);
  47.         var dst = new Array(16);
  48.         var nBytes = password.length;
  49.         var i = 0;
  50.         var rslt;
  51.         var one, two, three, four;
  52.  
  53.         while(i<nBytes){
  54.           key[i] = parseInt(password.charCodeAt(i));
  55.           dst[i] = key[i];
  56.           i++;
  57.  
  58.         }
  59.  
  60.         while(i<16){
  61.           key[i] = 0;
  62.           dst[i] = key[i];
  63.           i++;
  64.  
  65.         }
  66.  
  67.         rslt = key[0] + key[1] * 256 + key[2] * 65536 + key[3] * 16777216;
  68.         one = rslt * 213119 + 2529077;
  69.         one = one - $scope.intval(one / 4294967296) * 4294967296;
  70.        
  71.         rslt = key[4] + key[5] * 256 + key[6] * 65536 + key[7] * 16777216;
  72.         two = rslt * 213247 + 2529089;
  73.         two = two - $scope.intval(two / 4294967296) * 4294967296;
  74.  
  75.         rslt = key[8] + key[9] * 256 + key[10] * 65536 + key[11] * 16777216;
  76.         three = rslt * 213203 + 2529589;
  77.         three = three - $scope.intval(three / 4294967296) * 4294967296;
  78.  
  79.         rslt = key[12] + key[13] * 256 + key[14] * 65536 + key[15] * 16777216;
  80.         four = rslt * 213821 + 2529997;
  81.         four = four - $scope.intval(four / 4294967296) * 4294967296;
  82.  
  83.         key[3] = $scope.intval(one / 16777216);
  84.         key[2] = $scope.intval((one - key[3] * 16777216) / 65535);
  85.         key[1] = $scope.intval((one - key[3] * 16777216 - key[2] * 65536) / 256);
  86.         key[0] = $scope.intval((one - key[3] * 16777216 - key[2] * 65536 - key[1] * 256));
  87.  
  88.         key[7] = $scope.intval(two / 16777216);
  89.         key[6] = $scope.intval((two - key[7] * 16777216) / 65535);
  90.         key[5] = $scope.intval((two - key[7] * 16777216 - key[6] * 65536) / 256);
  91.         key[4] = $scope.intval((two - key[7] * 16777216 - key[6] * 65536 - key[5] * 256));
  92.  
  93.         key[11] = $scope.intval(three / 16777216);
  94.         key[10] = $scope.intval((three - key[11] * 16777216) / 65535);
  95.         key[9] = $scope.intval((three - key[11] * 16777216 - key[10] * 65536) / 256);
  96.         key[8] = $scope.intval((three - key[11] * 16777216 - key[10] * 65536 - key[9] * 256));
  97.  
  98.         key[15] = $scope.intval(four / 16777216);
  99.         key[14] = $scope.intval((four - key[15] * 16777216) / 65535);
  100.         key[13] = $scope.intval((four - key[15] * 16777216 - key[14] * 65536) / 256);
  101.         key[12] =$scope. intval((four - key[15] * 16777216 - key[14] * 65536 - key[13] * 256));
  102.  
  103.         dst[0] = dst[0] ^ key[0];
  104.  
  105.         i = 0;
  106.         while (i < 15)
  107.         {
  108.           i++;
  109.           dst[i] = dst[i] ^ dst[i - 1] ^ key[i];
  110.         }
  111.  
  112.         i = -1;
  113.         while (i < 15)
  114.         {
  115.           i++;
  116.           if (dst[i] == 0)
  117.           {
  118.             dst[i] = 102;
  119.           }
  120.         }
  121.  
  122.         var sEnc = "0x";
  123.         i = -1;
  124.         while (i < 15)
  125.         {
  126.           i++;
  127.           if (dst[i] < 16)
  128.           {
  129.             sEnc += '0' + $scope.dechex(dst[i]).toUpperCase();
  130.           }
  131.           else
  132.           {
  133.             sEnc += $scope.dechex(dst[i]).toUpperCase();
  134.           }
  135.         }
  136.         //console.log(sEnc);
  137.         return sEnc;
  138.       }
  139.  
  140.      
  141.      $scope.submit = function(){
  142.      
  143.       if($rootScope.regUser.password == $scope.usr.confirmPassword){
  144.         $scope.regUser.password = $scope.encpwd($scope.regUser.password);
  145.         $scope.usr.confirmPassword =  $scope.regUser.password;
  146.         $scope.RegUser();
  147.  
  148.       }else{
  149.         alert("Enter Correct Password");
  150.       }      
  151.      };
  152.      
  153.    
  154.  });
  155.  
  156.  app.controller('loginCtrl', function ($scope,$rootScope, $http,  $window, $location) {
  157.  
  158.       $scope.uemail = $window.localStorage.getItem('uemail'),
  159.       $scope.upassword = $window.localStorage.getItem('upassword');
  160.  
  161.      // console.log($scope.uemail + " - " + $scope.upassword);
  162.      
  163.       $scope.dechex = function(n){
  164.         return n.toString(16);
  165.       }
  166.  
  167.       $scope.intval = function(n){
  168.         return parseInt(n.toString());
  169.       }
  170.       $scope.encpwd = function(password){
  171.       //  alert(password);
  172.         var key = new Array(16);
  173.         var dst = new Array(16);
  174.         var nBytes = password.length;
  175.         var i = 0;
  176.         var rslt;
  177.         var one, two, three, four;
  178.  
  179.         while(i<nBytes){
  180.           key[i] = parseInt(password.charCodeAt(i));
  181.           dst[i] = key[i];
  182.           i++;
  183.  
  184.         }
  185.  
  186.         while(i<16){
  187.           key[i] = 0;
  188.           dst[i] = key[i];
  189.           i++;
  190.  
  191.         }
  192.  
  193.         rslt = key[0] + key[1] * 256 + key[2] * 65536 + key[3] * 16777216;
  194.         one = rslt * 213119 + 2529077;
  195.         one = one - $scope.intval(one / 4294967296) * 4294967296;
  196.        
  197.         rslt = key[4] + key[5] * 256 + key[6] * 65536 + key[7] * 16777216;
  198.         two = rslt * 213247 + 2529089;
  199.         two = two - $scope.intval(two / 4294967296) * 4294967296;
  200.  
  201.         rslt = key[8] + key[9] * 256 + key[10] * 65536 + key[11] * 16777216;
  202.         three = rslt * 213203 + 2529589;
  203.         three = three - $scope.intval(three / 4294967296) * 4294967296;
  204.  
  205.         rslt = key[12] + key[13] * 256 + key[14] * 65536 + key[15] * 16777216;
  206.         four = rslt * 213821 + 2529997;
  207.         four = four - $scope.intval(four / 4294967296) * 4294967296;
  208.  
  209.         key[3] = $scope.intval(one / 16777216);
  210.         key[2] = $scope.intval((one - key[3] * 16777216) / 65535);
  211.         key[1] = $scope.intval((one - key[3] * 16777216 - key[2] * 65536) / 256);
  212.         key[0] = $scope.intval((one - key[3] * 16777216 - key[2] * 65536 - key[1] * 256));
  213.  
  214.         key[7] = $scope.intval(two / 16777216);
  215.         key[6] = $scope.intval((two - key[7] * 16777216) / 65535);
  216.         key[5] = $scope.intval((two - key[7] * 16777216 - key[6] * 65536) / 256);
  217.         key[4] = $scope.intval((two - key[7] * 16777216 - key[6] * 65536 - key[5] * 256));
  218.  
  219.         key[11] = $scope.intval(three / 16777216);
  220.         key[10] = $scope.intval((three - key[11] * 16777216) / 65535);
  221.         key[9] = $scope.intval((three - key[11] * 16777216 - key[10] * 65536) / 256);
  222.         key[8] = $scope.intval((three - key[11] * 16777216 - key[10] * 65536 - key[9] * 256));
  223.  
  224.         key[15] = $scope.intval(four / 16777216);
  225.         key[14] = $scope.intval((four - key[15] * 16777216) / 65535);
  226.         key[13] = $scope.intval((four - key[15] * 16777216 - key[14] * 65536) / 256);
  227.         key[12] =$scope. intval((four - key[15] * 16777216 - key[14] * 65536 - key[13] * 256));
  228.  
  229.         dst[0] = dst[0] ^ key[0];
  230.  
  231.         i = 0;
  232.         while (i < 15)
  233.         {
  234.           i++;
  235.           dst[i] = dst[i] ^ dst[i - 1] ^ key[i];
  236.         }
  237.  
  238.         i = -1;
  239.         while (i < 15)
  240.         {
  241.           i++;
  242.           if (dst[i] == 0)
  243.           {
  244.             dst[i] = 102;
  245.           }
  246.         }
  247.  
  248.         var sEnc = "0x";
  249.         i = -1;
  250.         while (i < 15)
  251.         {
  252.           i++;
  253.           if (dst[i] < 16)
  254.           {
  255.             sEnc += '0' + $scope.dechex(dst[i]).toUpperCase();
  256.           }
  257.           else
  258.           {
  259.             sEnc += $scope.dechex(dst[i]).toUpperCase();
  260.           }
  261.         }
  262.         //console.log(sEnc);
  263.         return sEnc;
  264.       }
  265.  
  266.       $scope.login = {
  267.         email:'',
  268.         password:''
  269.       };
  270.  
  271.       $scope.loginSubmit = function(u,p){
  272.        
  273.         $http({
  274.             method: 'GET',
  275.             url: 'http://api.warningbeeps.com/GPS/Service/Service_ValidateUser.svc/Validate/'+ u +'/' +p,
  276.            headers: {
  277.                'Content-Type': 'application/json'
  278.            }          
  279.             }).then(function successCallback(response) {
  280.              console.log(response);
  281.                //objetoResultado is to be saved as user_id
  282.               if(response.data>0){
  283.                 $rootScope.user_id = response.data;
  284.                 $window.localStorage.setItem('user_id', response.data);
  285.                 $window.localStorage.setItem('uemail', u),
  286.                 $window.localStorage.setItem('upassword', p);
  287.                 $location.path('mapa/tab4/map');
  288.               }
  289.             }, function errorCallback(response) {
  290.               console.log("error");
  291.             });
  292.       }
  293.       $scope.login = function(){
  294.           $scope.loginSubmit($scope.login.email,$scope.encpwd($scope.login.password));
  295.       }
  296.  
  297.       if(!($scope.uemail === null || $scope.upassword === null)){
  298.        
  299.         $scope.loginSubmit($scope.uemail,$scope.upassword);
  300.       }
  301.    
  302.  });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement