Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  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('/login');
  28.  
  29. }, function errorCallback(response) {
  30. console.log("error");
  31. });
  32. };
  33.  
  34.  
  35. $scope.dechex = function(n){
  36. return n.toString(16);
  37. }
  38.  
  39. $scope.intval = function(n){
  40. return parseInt(n.toString());
  41. }
  42. $scope.encpwd = function(password){
  43. // alert(password);
  44. var key = new Array(16);
  45. var dst = new Array(16);
  46. var nBytes = password.length;
  47. var i = 0;
  48. var rslt;
  49. var one, two, three, four;
  50.  
  51. while(i<nBytes){
  52. key[i] = parseInt(password.charCodeAt(i));
  53. dst[i] = key[i];
  54. i++;
  55.  
  56. }
  57.  
  58. while(i<16){
  59. key[i] = 0;
  60. dst[i] = key[i];
  61. i++;
  62.  
  63. }
  64.  
  65. rslt = key[0] + key[1] * 256 + key[2] * 65536 + key[3] * 16777216;
  66. one = rslt * 213119 + 2529077;
  67. one = one - $scope.intval(one / 4294967296) * 4294967296;
  68.  
  69. rslt = key[4] + key[5] * 256 + key[6] * 65536 + key[7] * 16777216;
  70. two = rslt * 213247 + 2529089;
  71. two = two - $scope.intval(two / 4294967296) * 4294967296;
  72.  
  73. rslt = key[8] + key[9] * 256 + key[10] * 65536 + key[11] * 16777216;
  74. three = rslt * 213203 + 2529589;
  75. three = three - $scope.intval(three / 4294967296) * 4294967296;
  76.  
  77. rslt = key[12] + key[13] * 256 + key[14] * 65536 + key[15] * 16777216;
  78. four = rslt * 213821 + 2529997;
  79. four = four - $scope.intval(four / 4294967296) * 4294967296;
  80.  
  81. key[3] = $scope.intval(one / 16777216);
  82. key[2] = $scope.intval((one - key[3] * 16777216) / 65535);
  83. key[1] = $scope.intval((one - key[3] * 16777216 - key[2] * 65536) / 256);
  84. key[0] = $scope.intval((one - key[3] * 16777216 - key[2] * 65536 - key[1] * 256));
  85.  
  86. key[7] = $scope.intval(two / 16777216);
  87. key[6] = $scope.intval((two - key[7] * 16777216) / 65535);
  88. key[5] = $scope.intval((two - key[7] * 16777216 - key[6] * 65536) / 256);
  89. key[4] = $scope.intval((two - key[7] * 16777216 - key[6] * 65536 - key[5] * 256));
  90.  
  91. key[11] = $scope.intval(three / 16777216);
  92. key[10] = $scope.intval((three - key[11] * 16777216) / 65535);
  93. key[9] = $scope.intval((three - key[11] * 16777216 - key[10] * 65536) / 256);
  94. key[8] = $scope.intval((three - key[11] * 16777216 - key[10] * 65536 - key[9] * 256));
  95.  
  96. key[15] = $scope.intval(four / 16777216);
  97. key[14] = $scope.intval((four - key[15] * 16777216) / 65535);
  98. key[13] = $scope.intval((four - key[15] * 16777216 - key[14] * 65536) / 256);
  99. key[12] =$scope. intval((four - key[15] * 16777216 - key[14] * 65536 - key[13] * 256));
  100.  
  101. dst[0] = dst[0] ^ key[0];
  102.  
  103. i = 0;
  104. while (i < 15)
  105. {
  106. i++;
  107. dst[i] = dst[i] ^ dst[i - 1] ^ key[i];
  108. }
  109.  
  110. i = -1;
  111. while (i < 15)
  112. {
  113. i++;
  114. if (dst[i] == 0)
  115. {
  116. dst[i] = 102;
  117. }
  118. }
  119.  
  120. var sEnc = "0x";
  121. i = -1;
  122. while (i < 15)
  123. {
  124. i++;
  125. if (dst[i] < 16)
  126. {
  127. sEnc += '0' + $scope.dechex(dst[i]).toUpperCase();
  128. }
  129. else
  130. {
  131. sEnc += $scope.dechex(dst[i]).toUpperCase();
  132. }
  133. }
  134. //console.log(sEnc);
  135. return sEnc;
  136. }
  137.  
  138.  
  139. $scope.submit = function(){
  140.  
  141. if($rootScope.regUser.password == $scope.usr.confirmPassword){
  142. $scope.regUser.password = $scope.encpwd($scope.regUser.password);
  143. $scope.usr.confirmPassword = $scope.regUser.password;
  144. $scope.RegUser();
  145.  
  146. }else{
  147. alert("Enter Correct Password");
  148. }
  149. };
  150.  
  151.  
  152. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement