Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2. import { NavController, NavParams } from 'ionic-angular';
  3. import { HomePage } from '../home/home';
  4. import { Observable } from 'rxjs';
  5. import { HttpClient } from '@angular/common/http';
  6. import { PeopleServiceProvider } from '../../providers/people-service/people-service';
  7. import { AlertController } from 'ionic-angular';
  8. import { LoadingController } from 'ionic-angular';
  9.  
  10. /**
  11. * Generated class for the LoginPage page.
  12. *
  13. * See https://ionicframework.com/docs/components/#navigation for more info on
  14. * Ionic pages and navigation.
  15. */
  16.  
  17. @Component({
  18. selector: 'page-login',
  19. templateUrl: 'login.html'
  20. })
  21. export class LoginPage {
  22.  
  23. splash: boolean = true;
  24. tarBarElement: any;
  25. private username: string;
  26. private password: string;
  27. loader: any;
  28.  
  29. private invalidLogin: boolean = false;
  30. private invalidLoginMessage: string = "";
  31.  
  32.  
  33. constructor(public navCtrl: NavController, public navParams: NavParams, public peopleProvider: PeopleServiceProvider, public http: HttpClient, public alertCtrl: AlertController, public loadingCtrl: LoadingController) {
  34.  
  35. this.tarBarElement = document.querySelector('.tabbar');
  36.  
  37. }
  38.  
  39. ionViewDidLoad() {
  40. setTimeout(() => this.splash = false, 5000);
  41. }
  42.  
  43. login() {
  44. let user = {
  45. "username": this.username,
  46. "password": this.password
  47. }
  48.  
  49. this.peopleProvider.callWebApi(user)
  50. .subscribe(
  51. result => {
  52. this.presentLoading();
  53. console.log('Result from server:', result);
  54.  
  55. if (result.result == "true") {
  56.  
  57. this.peopleProvider.namesur = result.user.namesur;
  58. this.peopleProvider.pservices = result.user.pservices;
  59. this.peopleProvider.uservices = result.user.uservices;
  60. this.peopleProvider.nservices = result.user.nservices;
  61.  
  62. this.peopleProvider.phone = result.user.phone;
  63. this.peopleProvider.type = result.user.type;
  64. this.peopleProvider.model = result.user.model;
  65. this.peopleProvider.address = result.user.address;
  66. this.peopleProvider.access_date = result.user.access_date;
  67. this.peopleProvider.company = result.user.company;
  68. this.peopleProvider.intervention = result.user.intervention;
  69. this.peopleProvider.intervention_details = result.user.intervention_details;
  70. this.peopleProvider.id = result.user.id;
  71.  
  72.  
  73.  
  74. this.navCtrl.push(HomePage,
  75. {'id' : result.user.id, 'namesur': result.user.namesur, 'pservices': result.user.pservices, 'uservices': result.user.uservices, 'nservices': result.user.nservices, 'company' : result.user.company } );
  76. this.loader.dismiss();
  77.  
  78. }
  79.  
  80. else {
  81.  
  82. this.presentAlert();
  83. this.loader.dismiss();
  84. this.invalidLogin = true;
  85.  
  86. }
  87.  
  88.  
  89. },
  90. error => {
  91.  
  92. }
  93. );
  94.  
  95.  
  96.  
  97.  
  98.  
  99. }
  100. presentLoading() {
  101. this.loader = this.loadingCtrl.create({
  102. content: "Please wait...",
  103. duration: 3000
  104.  
  105. });
  106. this.loader.present();
  107. }
  108. presentAlert() {
  109. let alert = this.alertCtrl.create({
  110. title: 'Login error',
  111. subTitle: 'Wrong username or password.',
  112. buttons: ['Dismiss']
  113. });
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement