Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  .controller('NewUserCtrl', function($scope, $http, $state, $timeout, $ionicPopup, $ionicLoading) {
  2.       $scope.params = {
  3.       email : $scope.email,
  4.       password : $scope.password,
  5.       password2 : $scope.passwordConfirm,
  6.       profile : 2
  7.     }
  8.     function showAlert(message, title) {
  9.       if (navigator.notification) {
  10.         navigator.notification.alert(message, null, title, 'OK');
  11.       } else {
  12.         alert(title ? (title + ": " + message) : message);
  13.       }
  14.     }
  15.     $scope.showPopupemail = function() {
  16.     var alertPopup = $ionicPopup.alert({
  17.       title: 'Error',
  18.       template: 'Verifica los datos'
  19.     });
  20.   }
  21.     $scope.showPopuppass = function() {
  22.     var alertPopup = $ionicPopup.alert({
  23.       title: 'Error',
  24.       template: 'Las contraseñas no coinciden'
  25.     });
  26.   }
  27.     $scope.registrar = function(){
  28.       console.log($scope.params)
  29.       $http({
  30.           method: 'POST',
  31.           url: 'http://api.espaciosvirtuales.info/public/index.php/create_userCredentials',
  32.           data: $scope.params
  33.           }).then(function successCallback(response) {
  34.             // this callback will be called asynchronously
  35.             // when the response is available
  36.             console.log("Éxito");
  37.             console.log(response)
  38.             $ionicLoading.show({
  39.               template: '<ion-spinner></ion-spinner>'
  40.             });
  41.             $timeout(function() {
  42.               $ionicLoading.hide();
  43.               $state.go('home.explore');
  44.             }, 2000);
  45.           }, function errorCallback(response) {
  46.             // called asynchronously if an error occurs
  47.             // or server returns response with an error status.
  48.             console.log("Error");
  49.             console.log(response);
  50.             response.data = Object.values(response.data).toString();
  51.             showAlert(response.data, 'Error de registro');
  52.         });
  53.     }// FIN DE LA FUNCION REGISTRAR
  54.     $scope.validar = function(){
  55.       if($scope.email == ''){
  56.         $scope.showPopupemail();
  57.         return false;
  58.       }
  59.       else if($scope.password == ''){
  60.         $scope.showPopupemail();
  61.         return false;
  62.       }
  63.       else if($scope.password != $scope.passwordConfirm){
  64.         $scope.showPopuppass();
  65.         return false;
  66.       }
  67.       else{
  68.         return true
  69.       }
  70.     }// FIN DE FUNCION VALIDAR
  71.  
  72.     $scope.IsItValidated = function($params){
  73.       if($scope.validar($scope.params) == true){
  74.         $scope.registrar($scope.params);
  75.       }else{
  76.         console.log("No")
  77.       }
  78.  
  79.  
  80.     }
  81.     console.log("1");
  82.     })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement