Advertisement
Guest User

Untitled

a guest
May 16th, 2018
127
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 (this.network.type !== "none" && this.network.type !== "unknown") {
  42.    
  43.                         if (info.SIMTELCO1 != "60502" || info.SIMSTATE1 != 5) {
  44.    
  45.                             let alert = this.alertCtrl.create({
  46.                                 title: "Vérification SIM TT",
  47.                                 enableBackdropDismiss: false,
  48.                                 message: "Pour accéder aux applications :\nVotre SIM Tunisie Telecom doit être dans le 1er emplacement du téléphone.",
  49.                                 buttons: [
  50.                                     {
  51.                                         text: "OK",
  52.                                         handler: data => {
  53.                                             this.platform.exitApp();
  54.                                         }
  55.                                     }
  56.                                 ]
  57.                             });
  58.    
  59.                             alert.present();
  60.                         } else {
  61.                             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")
  62.                            
  63.                             .map(res => res.json())
  64.                            
  65.                             .subscribe(data => {
  66.                                 if (data.reponseabo == "000") {
  67.                                     this.storage.remove('validite')
  68.        
  69.                                     let alert = this.alertCtrl.create({
  70.                                         title: "NUR",
  71.                                         enableBackdropDismiss: false,
  72.                                         message: data.textFR,
  73.                                         buttons: [
  74.                                             {
  75.                                                 text: "Télécharger",
  76.                                                 handler: data => {
  77.                                                     appAvailability.check("com.youvas.nurstore").then(() => {
  78.                                                         // success callback
  79.                                                         window.open("nur-store://", "_system");
  80.                                                         this.platform.exitApp();
  81.                                                     }, () => {
  82.                                                         // error callback
  83.                                                         iab.create("market://details?id=com.youvas.nurstore", "_system", "hidden=true");
  84.                                                         this.platform.exitApp();
  85.                                                     });
  86.                                                 }
  87.                                             },
  88.                                             {
  89.                                                 text: "Cancel",
  90.                                                 handler: data => {
  91.                                                     this.platform.exitApp();
  92.                                                 }
  93.                                             }
  94.                                         ]
  95.                                     });
  96.        
  97.                                     alert.present();
  98.                                 }
  99.        
  100.                                 if (data.reponseabo == "100") {
  101.        
  102.                                     this.storage.remove('validite')
  103.        
  104.                                     let alert = this.alertCtrl.create({
  105.                                         title: "NUR",
  106.                                         enableBackdropDismiss: false,
  107.                                         message: data.textFR,
  108.                                         buttons: [
  109.                                             {
  110.                                                 text: "OK",
  111.                                                 handler: data => {
  112.                                                     this.platform.exitApp();
  113.                                                 }
  114.                                             },
  115.                                             {
  116.                                                 text: "Cancel",
  117.                                                 handler: data => {
  118.                                                     this.platform.exitApp();
  119.                                                 }
  120.                                             }
  121.                                         ]
  122.                                     });
  123.                                     alert.present();
  124.                                 }
  125.        
  126.                                 if (data.reponseabo == "101") {
  127.                                     this.storage.set("validite",
  128.                                         JSON.stringify({
  129.                                             timeStamp: data.dateFin
  130.                                         })
  131.                                     );
  132.                                 }
  133.                             }, (error) => {
  134.                                 let alert = this.alertCtrl.create({
  135.                                     title: "Vérification abonnement indisponible",
  136.                                     enableBackdropDismiss: false,
  137.                                     message: "Réessayez plus tard.",
  138.                                     buttons: [
  139.                                         {
  140.                                             text: "OK",
  141.                                             handler: data => {
  142.                                                 this.platform.exitApp();
  143.                                             }
  144.                                         }
  145.                                     ]
  146.                                 });
  147.        
  148.                                 alert.present();
  149.                             });
  150.                         }
  151.                     } else {
  152.                         this.storage.get("validite").then(result => {
  153.                             if (result !== null) {
  154.                                 let validite = JSON.parse(result);
  155.    
  156.                                 if (new Date().getTime() > new Date(validite.timeStamp).getTime()) {
  157.                                     let alert = this.alertCtrl.create({
  158.                                         title: "Vérification abonnement indisponible",
  159.                                         enableBackdropDismiss: false,
  160.                                         message: "Merci de vous connecter à internet.",
  161.                                         buttons: [
  162.                                             {
  163.                                                 text: "OK",
  164.                                                 handler: data => {
  165.                                                     this.platform.exitApp();
  166.                                                 }
  167.                                             }
  168.                                         ]
  169.                                     });
  170.    
  171.                                     alert.present();
  172.                                 }
  173.                             } else {
  174.                                 let alert = this.alertCtrl.create({
  175.                                     title: "Vérification abonnement indisponible",
  176.                                     enableBackdropDismiss: false,
  177.                                     message: "Merci de vous connecter à internet.",
  178.                                     buttons: [
  179.                                     {
  180.                                         text: "OK",
  181.                                         handler: data => {
  182.                                             this.platform.exitApp();
  183.                                         }
  184.                                     }
  185.                                     ]
  186.                                 });
  187.    
  188.                                 alert.present();
  189.                             }
  190.                         });
  191.                     }
  192.                 })
  193.    
  194.                 .catch(err => {
  195.                     console.log(err);
  196.                 });
  197.             })
  198.            
  199.             .catch(error => {
  200.    
  201.                 console.log(error)
  202.                 // we don't have permission to read phone state
  203.                 let alert = this.alertCtrl.create({
  204.                     title: "NUR",
  205.                     enableBackdropDismiss: false,
  206.                     message: "Merci de nous donner la permission de vérifier que votre carte sim est TT.",
  207.                     buttons: [
  208.                         {
  209.                             text: "OK",
  210.                             handler: data => {
  211.                                 this.platform.exitApp();
  212.                             }
  213.                         }
  214.                     ]
  215.                 });
  216.    
  217.                 alert.present();
  218.             });
  219.         })
  220.     }
  221.  
  222.     ionViewDidEnter() {
  223.         this.slider.lockSwipeToPrev(true);
  224.     }
  225.  
  226.     slideChanged() {
  227.  
  228.         if (this.slider != undefined) {
  229.             if (this.slider.isBeginning()) {
  230.                 this.slider.lockSwipeToPrev(true);
  231.             }
  232.  
  233.             if (!this.slider.isBeginning()) {
  234.                 this.slider.lockSwipeToPrev(false);
  235.             }
  236.  
  237.             if (this.slider.isEnd()) {
  238.                 this.slider.lockSwipeToNext(true);
  239.             }
  240.  
  241.             if (!this.slider.isEnd()) {
  242.                 this.slider.lockSwipeToNext(false);
  243.             }
  244.         }
  245.     }
  246.  
  247.     goToHome() {
  248.         this.menu.swipeEnable(true);
  249.  
  250.         this.storage.ready().then(() => {
  251.             this.storage.get('gender').then((val) => {
  252.                 if (val) {
  253.                     this.navCtrl.setRoot(Home);
  254.                 } else {
  255.                     this.navCtrl.setRoot(Start);
  256.                 }
  257.             });
  258.         });
  259.  
  260.     }
  261.  
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement