Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component } from '@angular/core';
- import { NavController, NavParams } from 'ionic-angular';
- import { HomePage } from '../home/home';
- import { Observable } from 'rxjs';
- import { HttpClient } from '@angular/common/http';
- import { PeopleServiceProvider } from '../../providers/people-service/people-service';
- import { AlertController } from 'ionic-angular';
- import { LoadingController } from 'ionic-angular';
- /**
- * Generated class for the LoginPage page.
- *
- * See https://ionicframework.com/docs/components/#navigation for more info on
- * Ionic pages and navigation.
- */
- @Component({
- selector: 'page-login',
- templateUrl: 'login.html'
- })
- export class LoginPage {
- splash: boolean = true;
- tarBarElement: any;
- private username: string;
- private password: string;
- loader: any;
- private invalidLogin: boolean = false;
- private invalidLoginMessage: string = "";
- constructor(public navCtrl: NavController, public navParams: NavParams, public peopleProvider: PeopleServiceProvider, public http: HttpClient, public alertCtrl: AlertController, public loadingCtrl: LoadingController) {
- this.tarBarElement = document.querySelector('.tabbar');
- }
- ionViewDidLoad() {
- setTimeout(() => this.splash = false, 5000);
- }
- login() {
- let user = {
- "username": this.username,
- "password": this.password
- }
- this.peopleProvider.callWebApi(user)
- .subscribe(
- result => {
- this.presentLoading();
- console.log('Result from server:', result);
- if (result.result == "true") {
- this.peopleProvider.namesur = result.user.namesur;
- this.peopleProvider.pservices = result.user.pservices;
- this.peopleProvider.uservices = result.user.uservices;
- this.peopleProvider.nservices = result.user.nservices;
- this.peopleProvider.phone = result.user.phone;
- this.peopleProvider.type = result.user.type;
- this.peopleProvider.model = result.user.model;
- this.peopleProvider.address = result.user.address;
- this.peopleProvider.access_date = result.user.access_date;
- this.peopleProvider.company = result.user.company;
- this.peopleProvider.intervention = result.user.intervention;
- this.peopleProvider.intervention_details = result.user.intervention_details;
- this.peopleProvider.id = result.user.id;
- this.navCtrl.push(HomePage,
- {'id' : result.user.id, 'namesur': result.user.namesur, 'pservices': result.user.pservices, 'uservices': result.user.uservices, 'nservices': result.user.nservices, 'company' : result.user.company } );
- this.loader.dismiss();
- }
- else {
- this.presentAlert();
- this.loader.dismiss();
- this.invalidLogin = true;
- }
- },
- error => {
- }
- );
- }
- presentLoading() {
- this.loader = this.loadingCtrl.create({
- content: "Please wait...",
- duration: 3000
- });
- this.loader.present();
- }
- presentAlert() {
- let alert = this.alertCtrl.create({
- title: 'Login error',
- subTitle: 'Wrong username or password.',
- buttons: ['Dismiss']
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement