Advertisement
Guest User

Untitled

a guest
May 16th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, ViewChild } from '@angular/core';
  2. import { NavController, MenuController, AlertController, Platform } from 'ionic-angular';
  3. import { Storage } from '@ionic/storage';
  4. import { Start } from '../start/start';
  5. import { Home } from '../home/home';
  6. import { Slides } from 'ionic-angular';
  7. import { Http } from '@angular/http';
  8. import { Network } from '@ionic-native/network';
  9. import { InAppBrowser } from '@ionic-native/in-app-browser';
  10. import { AppAvailability } from '@ionic-native/app-availability';
  11. import { Device } from '@ionic-native/device';
  12. import { Sim } from '@ionic-native/sim';
  13.  
  14. @Component({
  15.     selector: 'page-intro',
  16.     templateUrl: 'intro.html',
  17.     providers: [Network, AppAvailability, Device, InAppBrowser]
  18. })
  19.  
  20. export class Intro {
  21.  
  22.     sliderOptions: any;
  23.  
  24.     @ViewChild('introSlider') slider: Slides;
  25.  
  26.     constructor(public navCtrl: NavController, public menu: MenuController, public alertCtrl: AlertController, public platform: Platform,
  27.         public storage: Storage, public device: Device, public network: Network, public http: Http, public sim: Sim,
  28.         public appAvailability: AppAvailability, public iab: InAppBrowser) {
  29.         menu.swipeEnable(false);
  30.  
  31.         this.sliderOptions = {
  32.             pager: true
  33.         };
  34.  
  35.         this.platform.ready().then(() => {
  36.  
  37.             sim.requestReadPermission().then(() => {
  38.    
  39.                 sim.getSimInfo().then((info) => {
  40.  
  41.                     if (! info.hasOwnProperty('IMSI1')) {
  42.                         // we don't have permission to read phone state
  43.                         let alert = this.alertCtrl.create({
  44.                             title: "NUR",
  45.                             enableBackdropDismiss: false,
  46.                             message: "Merci de nous donner la permission de vérifier que votre carte sim est TT.",
  47.                             buttons: [
  48.                                 {
  49.                                     text: "OK",
  50.                                     handler: data => {
  51.                                         this.platform.exitApp();
  52.                                     }
  53.                                 }
  54.                             ]
  55.                         });
  56.            
  57.                         alert.present();
  58.  
  59.                         return;
  60.                     }
  61.    
  62.                     if (this.network.type !== "none" && this.network.type !== "unknown") {
  63.    
  64.                         if (info.SIMTELCO1 != "60502" || info.SIMSTATE1 != 5) {
  65.    
  66.                             let alert = this.alertCtrl.create({
  67.                                 title: "Vérification SIM TT",
  68.                                 enableBackdropDismiss: false,
  69.                                 message: "Pour accéder aux applications :\nVotre SIM Tunisie Telecom doit être dans le 1er emplacement du téléphone.",
  70.                                 buttons: [
  71.                                     {
  72.                                         text: "OK",
  73.                                         handler: data => {
  74.                                             this.platform.exitApp();
  75.                                         }
  76.                                     }
  77.                                 ]
  78.                             });
  79.    
  80.                             alert.present();
  81.                         } else {
  82.                             this.http.get("https://us-central1-nur-store.cloudfunctions.net/checkabo?app=com.youvas.sujood&IMEI1=" + info.IMEI1 + "&IMSI1=" + info.IMSI1 + "&SIMTELCONAME1=" + info.SIMTELCONAME1 + "&Field1&Field2")
  83.                            
  84.                             .map(res => res.json())
  85.                            
  86.                             .subscribe(data => {
  87.                                 if (data.reponseabo == "000") {
  88.                                     this.storage.remove('validite')
  89.        
  90.                                     let alert = this.alertCtrl.create({
  91.                                         title: "NUR",
  92.                                         enableBackdropDismiss: false,
  93.                                         message: data.textFR,
  94.                                         buttons: [
  95.                                             {
  96.                                                 text: "Télécharger",
  97.                                                 handler: data => {
  98.                                                     appAvailability.check("com.youvas.nurstore").then(() => {
  99.                                                         // success callback
  100.                                                         window.open("nur-store://", "_system");
  101.                                                         this.platform.exitApp();
  102.                                                     }, () => {
  103.                                                         // error callback
  104.                                                         iab.create("market://details?id=com.youvas.nurstore", "_system", "hidden=true");
  105.                                                         this.platform.exitApp();
  106.                                                     });
  107.                                                 }
  108.                                             },
  109.                                             {
  110.                                                 text: "Cancel",
  111.                                                 handler: data => {
  112.                                                     this.platform.exitApp();
  113.                                                 }
  114.                                             }
  115.                                         ]
  116.                                     });
  117.        
  118.                                     alert.present();
  119.                                 }
  120.        
  121.                                 if (data.reponseabo == "100") {
  122.        
  123.                                     this.storage.remove('validite')
  124.        
  125.                                     let alert = this.alertCtrl.create({
  126.                                         title: "NUR",
  127.                                         enableBackdropDismiss: false,
  128.                                         message: data.textFR,
  129.                                         buttons: [
  130.                                             {
  131.                                                 text: "OK",
  132.                                                 handler: data => {
  133.                                                     this.platform.exitApp();
  134.                                                 }
  135.                                             },
  136.                                             {
  137.                                                 text: "Cancel",
  138.                                                 handler: data => {
  139.                                                     this.platform.exitApp();
  140.                                                 }
  141.                                             }
  142.                                         ]
  143.                                     });
  144.                                     alert.present();
  145.                                 }
  146.        
  147.                                 if (data.reponseabo == "101") {
  148.                                     this.storage.set("validite",
  149.                                         JSON.stringify({
  150.                                             timeStamp: data.dateFin
  151.                                         })
  152.                                     );
  153.                                 }
  154.                             }, (error) => {
  155.                                 let alert = this.alertCtrl.create({
  156.                                     title: "Vérification abonnement indisponible",
  157.                                     enableBackdropDismiss: false,
  158.                                     message: "Réessayez plus tard.",
  159.                                     buttons: [
  160.                                         {
  161.                                             text: "OK",
  162.                                             handler: data => {
  163.                                                 this.platform.exitApp();
  164.                                             }
  165.                                         }
  166.                                     ]
  167.                                 });
  168.        
  169.                                 alert.present();
  170.                             });
  171.                         }
  172.                     } else {
  173.                         this.storage.get("validite").then(result => {
  174.                             if (result !== null) {
  175.                                 let validite = JSON.parse(result);
  176.    
  177.                                 if (new Date().getTime() > new Date(validite.timeStamp).getTime()) {
  178.                                     let alert = this.alertCtrl.create({
  179.                                         title: "Vérification abonnement indisponible",
  180.                                         enableBackdropDismiss: false,
  181.                                         message: "Merci de vous connecter à internet.",
  182.                                         buttons: [
  183.                                             {
  184.                                                 text: "OK",
  185.                                                 handler: data => {
  186.                                                     this.platform.exitApp();
  187.                                                 }
  188.                                             }
  189.                                         ]
  190.                                     });
  191.    
  192.                                     alert.present();
  193.                                 }
  194.                             } else {
  195.                                 let alert = this.alertCtrl.create({
  196.                                     title: "Vérification abonnement indisponible",
  197.                                     enableBackdropDismiss: false,
  198.                                     message: "Merci de vous connecter à internet.",
  199.                                     buttons: [
  200.                                     {
  201.                                         text: "OK",
  202.                                         handler: data => {
  203.                                             this.platform.exitApp();
  204.                                         }
  205.                                     }
  206.                                     ]
  207.                                 });
  208.    
  209.                                 alert.present();
  210.                             }
  211.                         });
  212.                     }
  213.                 }, (err) => {
  214.                     console.log(err);
  215.                 });
  216.  
  217.             }, (error) => {
  218.                 // we don't have permission to read phone state
  219.                 let alert = this.alertCtrl.create({
  220.                     title: "NUR",
  221.                     enableBackdropDismiss: false,
  222.                     message: "Merci de nous donner la permission de vérifier que votre carte sim est TT.",
  223.                     buttons: [
  224.                         {
  225.                             text: "OK",
  226.                             handler: data => {
  227.                                 this.platform.exitApp();
  228.                             }
  229.                         }
  230.                     ]
  231.                 });
  232.    
  233.                 alert.present();
  234.             });
  235.         })
  236.     }
  237.  
  238.     ionViewDidEnter() {
  239.         this.slider.lockSwipeToPrev(true);
  240.     }
  241.  
  242.     slideChanged() {
  243.  
  244.         if (this.slider != undefined) {
  245.             if (this.slider.isBeginning()) {
  246.                 this.slider.lockSwipeToPrev(true);
  247.             }
  248.  
  249.             if (!this.slider.isBeginning()) {
  250.                 this.slider.lockSwipeToPrev(false);
  251.             }
  252.  
  253.             if (this.slider.isEnd()) {
  254.                 this.slider.lockSwipeToNext(true);
  255.             }
  256.  
  257.             if (!this.slider.isEnd()) {
  258.                 this.slider.lockSwipeToNext(false);
  259.             }
  260.         }
  261.     }
  262.  
  263.     goToHome() {
  264.         this.menu.swipeEnable(true);
  265.  
  266.         this.storage.ready().then(() => {
  267.             this.storage.get('gender').then((val) => {
  268.                 if (val) {
  269.                     this.navCtrl.setRoot(Home);
  270.                 } else {
  271.                     this.navCtrl.setRoot(Start);
  272.                 }
  273.             });
  274.         });
  275.  
  276.     }
  277.  
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement