Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .controller('CadastroUserCtrl', ['$scope', '$stateParams', '$http',
  2.     function($scope, $stateParams, $http) {
  3.       $scope.data = {};
  4.      
  5.       $scope.cadastrarUser = function(){
  6.             var nome = $scope.data.nome;
  7.             var email = $scope.data.email;
  8.             var login = $scope.data.login;
  9.             var senha = $scope.data.senha;
  10.             var confirmSenha = $scope.data.confirmSenha;
  11.  
  12.             var userJson = {
  13.               'name': nome,
  14.               'email': email,
  15.               'username': login,
  16.               'password': senha,
  17.               'confirmPassword': confirmSenha
  18.             };
  19.  
  20.            
  21.             userJson = serializeData(userJson);
  22.  
  23.                 $http.post('localhost:3000/registerdonor', {
  24.                     name: nome,
  25.                     email: email,
  26.                     username: login,
  27.                     password: senha,
  28.                     confirmPassword: confirmSenha
  29.                 })
  30.                     .success(function(response) {
  31.                         // authentication OK
  32.                        alert("Certo!");
  33.                     })
  34.                     .error(function(status) {
  35.                         // Error: authentication failed
  36.                         alert(status);
  37.                     });
  38.                 //$http.post('http://localhost:3000/registerdonor', userJson, 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8').success().error();
  39.                 //$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8de";
  40.                 /*$http({
  41.                       method: 'post',
  42.                       url: 'localhost:3000/registerdonor',
  43.                       params: userJson,
  44.                       headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'}
  45.                   }).success(function(status) {
  46.                          
  47.                           alert("Cadastrado!");
  48.                          
  49.                       }).error(function(status) {
  50.                          
  51.                           alert(status);
  52.                       });*/
  53.                          
  54.                   function serializeData( data ) {
  55.            
  56.                               // If this is not an object, defer to native stringification.
  57.                               if ( ! angular.isObject( data ) ) {
  58.            
  59.                                   return( ( data == null ) ? "" : data.toString() );
  60.            
  61.                               }
  62.            
  63.                               var buffer = [];
  64.            
  65.                               // Serialize each key in the object.
  66.                               for ( var name in data ) {
  67.            
  68.                                   if ( ! data.hasOwnProperty( name ) ) {
  69.            
  70.                                       continue;
  71.            
  72.                                   }
  73.            
  74.                                   var value = data[ name ];
  75.            
  76.                                   buffer.push(
  77.                                       encodeURIComponent( name ) +
  78.                                       "=" +
  79.                                       encodeURIComponent( ( value == null ) ? "" : value )
  80.                                   );
  81.            
  82.                               }
  83.            
  84.                               // Serialize the buffer and clean it up for transportation.
  85.                               var source = buffer
  86.                                   .join( "&" )
  87.                                   .replace( /%20/g, "+" )
  88.                               ;
  89.            
  90.                               return( source );
  91.                   }
  92.  
  93.       }
  94.     }
  95. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement