login.ts 1.37 KB
Newer Older
mohan122's avatar
mohan122 committed
1
2
3
4
5
6
7
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams ,AlertController} from 'ionic-angular';
import {User} from '../../models/user';
import {AngularFireAuth } from 'angularfire2/auth';
import { HomePage } from '../home/home';

import { RegisterPage } from '../register/register';
mohan122's avatar
mohan122 committed
8
import { TabhPage } from '../tabh/tabh';
mohan122's avatar
mohan122 committed
9
10
11
12
13
14
15
@IonicPage()
@Component({
  selector: 'page-login',
  templateUrl: 'login.html',
})
export class LoginPage {
  user={} as User;
mohan122's avatar
mohan122 committed
16
  public email:any;
mohan122's avatar
mohan122 committed
17
18
19
20
21
22
23
24
25
26
27
28
29
  
  constructor(public navCtrl: NavController, public navParams: NavParams,private fire:AngularFireAuth,private alertctrl:AlertController) {
  }
  alert(message:string){
    this.alertctrl.create({
      title: 'Alert',
      subTitle: message,
      buttons: ['OK']
    }).present();
  }
   login(user:User){
    this.fire.auth.signInWithEmailAndPassword(this.user.email,this.user.password)
    .then(data =>{
mohan122's avatar
mohan122 committed
30
    this.navCtrl.setRoot(TabhPage,{emails:this.user.email});
mohan122's avatar
mohan122 committed
31
    console.log(this.user.email);
mohan122's avatar
mohan122 committed
32
33
    //this.navCtrl.push(HomePage,{emails:this.user.email});
    //this.navCtrl.push(TabhPage,{emails:this.user.email});
mohan122's avatar
mohan122 committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  })
  
    .catch(error=>{
      this.navCtrl.setRoot(LoginPage);
      this.alert('Username and Password not match');
    })
  }
   
  Register() {
     this.navCtrl.push(RegisterPage);
}

  ionViewDidLoad() {
   
    console.log('ionViewDidLoad SplashPage');
  }

}