Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
64
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.       var 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.       $http({
  29.           method: 'POST',
  30.           url: 'http://api.espaciosvirtuales.info/public/index.php/create_userCredentials',
  31.           data: params
  32.           }).then(function successCallback(response) {
  33.             // this callback will be called asynchronously
  34.             // when the response is available
  35.             console.log("Éxito");
  36.             console.log(response)
  37.             $ionicLoading.show({
  38.               template: '<ion-spinner></ion-spinner>'
  39.             });
  40.             $timeout(function() {
  41.               $ionicLoading.hide();
  42.               $state.go('home.explore');
  43.             }, 2000);
  44.           }, function errorCallback(response) {
  45.             // called asynchronously if an error occurs
  46.             // or server returns response with an error status.
  47.             console.log("Error");
  48.             console.log(response);
  49.             response.data = Object.values(response.data).toString();
  50.             showAlert(response.data, 'Error de registro');
  51.         });
  52.     }// FIN DE LA FUNCION REGISTRAR
  53.     $scope.validar = function($params){
  54.       if($scope.email == ''){
  55.         $scope.showPopupemail();
  56.         return false;
  57.       }
  58.       else if($scope.password == ''){
  59.         $scope.showPopupemail();
  60.         return false;
  61.       }
  62.       else if($scope.password != $scope.passwordConfirm){
  63.         $scope.showPopuppass();
  64.         return false;
  65.       }
  66.       else{
  67.         return true
  68.       }
  69.     }// FIN DE FUNCION VALIDAR
  70.  
  71.     $scope.IsItValidated = function($params){
  72.       if($scope.validar($params) == true){
  73.         $scope.registrar($params);
  74.       }else{
  75.         console.log("No")
  76.       }
  77.  
  78.  
  79.     }
  80.     console.log(params)
  81.     console.log("1");
  82.     })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement