HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/src/app/pages/signup/signup.ts
import { DataPolicyService } from './../../services/data-policy.service';
import { AnalyticsService } from './../../services/analytics.service';
import { Component, OnInit } from "@angular/core";
import { TranslateService } from "@ngx-translate/core";
import { NavController } from "@ionic/angular";
import { StorageService } from '../../services/storage.service';
import { UserService } from "../../services/user.service";
import { UtilsService } from "../../services/utils.service";
import { InAppBrowser } from '@capgo/inappbrowser';;
import { Capacitor } from '@capacitor/core';
import { Platform } from '@ionic/angular';

@Component({
  selector: "page-signup",
  templateUrl: "signup.html",
  styleUrls: ["./signup.scss"],
})
export class SignupPage implements OnInit {
  private toastMessageText: any;

  statusInvalidName: boolean = false;
  statusInvalidLastName: boolean = false;
  statusInvalidEmail: boolean = false;
  statusInvalidConfirmEmail: boolean = false;
  statusInvalidCellPhone: boolean = false;
  statusInvalidPassword: boolean = false;
  statusInvalidConfirmPassword: boolean = false;
  statusInvalidTerms: boolean = false;
  statusTerms: boolean = false;
  statusFormatEmail: boolean = false;
  parametersMain: any;
  statusDataPolicy: boolean = false;
  statusInvalidDataPolicy: boolean = false;
  dataPolicyUrl;
  statusAdultAuthorization: boolean = false;
  statusInvalidAdultAuthorization: boolean = false;

  constructor(
    public navCtrl: NavController,
    public user: UserService,
    public translateService: TranslateService,
    private storage: StorageService,
    public utilsService: UtilsService,
    private analyticsService: AnalyticsService,
    private dataPolicyService: DataPolicyService,
    private platform: Platform
  ) {
    // traduccion para textos toast
    this.translateService.get(["ALREADY_EXISTS_USER"]).subscribe((values) => {
      this.toastMessageText = {
        alreadyExistsUser: values.ALREADY_EXISTS_USER,
      };
    });
  }

  ngOnInit() {
    this.storage.get("parametersMain").then((parameters) => {
      if (parameters)
        this.parametersMain = parameters;
    });

    this.dataPolicyService.get().then((res: any) => {
      this.dataPolicyUrl = res.url;
    })
  }

  avoidSpecialChars(event) {
    if (event.type == 'input' && event.currentTarget.name == 'confirmEmail' && !('data' in event)) {
      event.currentTarget.value = '';
      event.preventDefault();
      return false;
    }
    let res: boolean = false;
    let value = String.fromCharCode(!event.charCode ? event.which : event.charCode);
    switch (event.target.type) {
      case 'text':
        res = /^[0-9a-zA-Zñáéíóúü ]+$/i.test(value);
        if (res) {
          return true;
        }
        break;

      case 'email':
        res = /^[0-9a-zA-Zñáéíóúü@.!#$%&'*/=?^_+-`{|}~]+$/i.test(value);
        if (res) {
          return true;
        }
        break;

      case 'tel':
        res = /^[0-9]+$/i.test(value);
        if (res) {
          return true;
        }
        break;
    }
    event.preventDefault();
    return false;
  }

  clearSpecialChars(target) {
    let res: boolean = false;
    switch (target.type) {
      case 'text':
        res = /^[0-9a-zA-Zñáéíóúü ]+$/i.test(target.value);
        if (!res) {
          target.value = target.value.replace(/[^0-9a-zA-Zñáéíóúü ]+/g, '').trim();
        }
        break;

      case 'email':
        res = /^[0-9a-zA-Zñáéíóúü@.!#$%&'*/=?^_+-`{|}~]+$/i.test(target.value);
        if (res) {
          target.value = target.value.replace(/[^0-9a-zA-Zñáéíóúü@.!#$%&'*/=?^_+-`{|}~]+/g, '').trim();
        }
        break;

      case 'tel':
        res = /^[0-9]+$/i.test(target.value);
        if (res) {
          target.value = target.value.replace(/[^0-9]+/g, '').trim();
        }
        break;
    }
  }

  onPaste(e) {
    e.preventDefault();
    return false;
  }

  openTermsSI() {
    if (this.parametersMain) {
      let link = this.parametersMain.terms.url;
      if (!link) {
        this.utilsService.presentAlertInfo(this.translateService.instant('error.alert'), '', this.translateService.instant('error.invalid_link'));
        return;
      }
      if (Capacitor.isNativePlatform()) {
        if (this.isAndroid()) {
          return this.utilsService.presentSeeDocument(this.translateService.instant('TERMS_AND_CONDITIONS_2'), link);
        } else {
          this.utilsService.openLink(link);
        }
      } else {
        window.open(link, "_blank");
      }
    }
  }

  openDataPolicy() {
    let link = this.dataPolicyUrl;
    if (!link) {
      this.utilsService.presentAlertInfo(this.translateService.instant('error.alert'), '', this.translateService.instant('error.invalid_link'));
      return;
    }
    if (Capacitor.isNativePlatform()) {
      if (this.isAndroid()) {
        this.utilsService.presentSeeDocument(this.translateService.instant('DATA_POLICY'), link);
      } else {
        InAppBrowser.open({ url: link });
      }
    } else {
      window.open(link, "_blank");
    }
  }

  doSignup(formSignup) {
    this.analyticsService.logEvent('Signup Click', this.utilsService.categoryWelcome);
    if (!formSignup.controls.name.valid) {
      this.statusInvalidName = true;
      return;
    }
    if (!formSignup.controls.lastName.valid) {
      this.statusInvalidLastName = true;
      return;
    }
    if (!formSignup.controls.email.valid) {
      this.statusInvalidEmail = true;
      return;
    }
    if (this.statusFormatEmail) {
      this.statusFormatEmail = true;
      return;
    }
    if (!formSignup.controls.confirmEmail.valid) {
      this.statusInvalidConfirmEmail = true;
      return;
    } else if (this.statusInvalidConfirmEmail) {
      this.statusInvalidConfirmEmail = true;
      return;
    }
    if (!formSignup.controls.password.valid) {
      this.statusInvalidPassword = true;
      return;
    }
    if (!formSignup.controls.confirmPassword.valid) {
      this.statusInvalidConfirmPassword = true;
      return;
    } else if (this.statusInvalidConfirmPassword) {
      this.statusInvalidConfirmPassword = true;
      return;
    }
    if (!this.statusAdultAuthorization) {
      this.statusInvalidAdultAuthorization = true;
      return;
    }
    if (!this.statusTerms) {
      this.statusInvalidTerms = true;
      return;
    }
    if (this.dataPolicyUrl && !this.statusDataPolicy) {
      this.statusInvalidDataPolicy = true;
      return;
    }

    formSignup.value.document = "";

    this.storage.get("infoHost").then((infoHost) => {
      if (infoHost) {
        this.utilsService.presentLoading(this.translateService.instant("all.loading"));
        this.user.isPreabonadoByEmail(formSignup.value.email).then((resp: any) => {
          if (resp["r"]) {
            formSignup.value.isSubscriber = true;
          } else if (resp["m"]) {
            this.utilsService.dismissLoading();
            this.utilsService.presentAlertInfo(this.translateService.instant("tickets.alert"), "", resp["m"]);
            return;
          }
          this.user.signup(formSignup.value, infoHost.name_database)
            .then((resp: any) => {
              this.utilsService.dismissLoading();
              if (resp["status"] == "email_already_exists") {
                this.utilsService.presentToast(4000, "warning", "top", this.toastMessageText.alreadyExistsUser);
              } else if (resp["status"] == "success") {
                this.navCtrl.navigateRoot("/app/tabs/home");
                this.utilsService.presentToast(3000, "tertiary", "top", this.translateService.instant("WELCOME_TITLE") + formSignup.value.name);
              }
            })
            .catch((error) => {
              this.utilsService.dismissLoading();
              if (error["status"] == "email_already_exists") {
                this.utilsService.presentToast(4000, "warning", "top", this.toastMessageText.alreadyExistsUser);
              } else {
                this.utilsService.presentToast(4000, "danger", "top", this.translateService.instant("all.error_request"));
              }
            });
        }).catch(error => {
          console.log("Error isPreabonadoByEmail: ", error);
        });
      }
    });
  }

  changeAdultAuthorization(e) {
    this.statusAdultAuthorization = e.detail.checked;
    this.statusInvalidAdultAuthorization = !e.detail.checked;
  }

  // validacion del checkbox de terminos y condiciones
  changeStatusTerms(e) {
    this.statusTerms = e.detail.checked;
    this.statusInvalidTerms = !e.detail.checked;
  }

  changeStatusDataPolicy(e) {
    this.statusDataPolicy = e.detail.checked;
    this.statusInvalidDataPolicy = !e.detail.checked;
  }

  matchingEmails(email: string, confirmEmail: string) {
    let re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    if (!re.test(String(email).toLowerCase()) || email !== confirmEmail) {
      this.statusInvalidConfirmEmail = true;
      return;
    } else {
      this.statusInvalidConfirmEmail = false;
    }
  }

  matchingPasswords(password: string, confirmPassword: string) {
    if (password !== confirmPassword) {
      this.statusInvalidConfirmPassword = true;
      return;
    } else {
      this.statusInvalidConfirmPassword = false;
    }
  }

  isAndroid() {
    return this.platform.is("android");
  }
}