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/services/auth-route.service.ts
import { Injectable } from "@angular/core";
import { Platform, AlertController, ModalController } from "@ionic/angular";
import { TranslateService } from "@ngx-translate/core";
import { StorageService } from './storage.service';

import { UserService } from "./user.service";
import { InitialService } from "./initial.service";
import { AuthService } from "./auth.service";
import { CityService } from "./city.service";
import { UtilsService } from "./utils.service";
import { ParameterService } from "./parameter.service";
import { EndVersionPage } from "../pages/end-version/end-version";

import { NativeMarket } from "@capacitor-community/native-market";

@Injectable({
  providedIn: "root",
})
export class AuthRouteService {
  backButtonSubscription: any;
  isNavigator: boolean = false;
  constructor(
    private platform: Platform,
    public alertController: AlertController,
    private translate: TranslateService,
    public userService: UserService,
    private storage: StorageService,
    public modalCtrl: ModalController,
    public initialService: InitialService,
    public cityService: CityService,
    public authService: AuthService,
    public utilsService: UtilsService,
    public parameterService: ParameterService
  ) {}

  validateLoginUser() {
    return new Promise((resolve, reject) => {
      this.storage
        .get("HAS_LOGGED_IN")
        .then((HAS_LOGGED_IN) => {
          this.utilsService._HAS_LOGGED_IN = HAS_LOGGED_IN;
          if (this.platform.is("cordova")) {
            this.initialService.getParameters().subscribe(
              (resp) => {
                if (resp["status"] == "success") {
                  let infoEndVersion = {
                    image_end_version: resp["parameters"].image_end_version,
                    text_end_version: resp["parameters"].text_end_version,
                    link_end_version: resp["parameters"].link_end_version,
                    end_version_home: resp["parameters"].end_version_home,
                  };
                  this.storage.set("infoEndVersion", infoEndVersion);
                  if (resp["parameters"].end_version) {
                    resolve("showEndVersionModal");
                    this.showEndVersionModal(
                      resp["parameters"].image_end_version,
                      resp["parameters"].text_end_version,
                      resp["parameters"].link_end_version
                    );
                  } else {
                    if (HAS_LOGGED_IN) {
                      this.cityService.getInfoHost();
                      resolve("existsUser");
                    } else {
                      this.storage.get("productsCart").then((productsCart) => {
                        if (productsCart) {
                          this.storage.clear();
                        }
                        resolve("notExistsUser");
                      });
                    }
                  }
                }
              },
              (error) => {
                console.log("error initialService.getParameters: ", error);
                this.storage.clear();
                this.exitApp();
              }
            );
          } else {
            this.initialService.getParameters().subscribe((resp) => {
              this.storage.get("infoUser").then((infoUser) => {
                let infoEndVersion = {
                  image_end_version: resp["parameters"].image_end_version,
                  text_end_version: resp["parameters"].text_end_version,
                  link_end_version: resp["parameters"].link_end_version,
                  end_version_home: resp["parameters"].end_version_home,
                };
                this.storage.set("infoEndVersion", infoEndVersion);
                if (infoUser) {
                  this.cityService.getInfoHost();
                  resolve("existsUser");
                } else {
                  resolve("notExistsUser");
                }
              });
            });
          }
        })
        .catch((error) => {
          reject(false);
          console.log("error getHAS_LOGGED_IN: ", error);
        });
    });
  }
  async showConfirmVersionAppOld(appId) {
    const alert = await this.alertController.create({
      header: this.translate.instant("TITLE_ALERT_UPDATE_APP"),
      message: this.translate.instant("TEXT_ALERT_UPDATE_APP"),
      buttons: [
        {
          text: this.translate.instant("BUTTON1_ALERT_UPDATE_APP"),
          handler: () => {
            this.exitApp();
          },
        },
        {
          text: this.translate.instant("BUTTON2_ALERT_UPDATE_APP"),
          handler: () => {
            NativeMarket.openStoreListing({
              appId: appId,
            });
            this.exitApp();
          },
        },
      ],
    });
    await alert.present();
  }

  async showEndVersionModal(image_end_version, text_end_version, link_end_version) {
    const modal = await this.modalCtrl.create({
      component: EndVersionPage,
      componentProps: { image_end_version, text_end_version, link_end_version },
    });
    await modal.present();

    await modal.onWillDismiss().then(() => {
      this.exitApp();
    });
  }

  exitApp() {
    this.backButtonSubscription = this.platform.backButton.subscribe(() => {
      navigator["app"].exitApp();
    });
  }
}