import { Component } from '@angular/core' ; import { FormBuilder , FormGroup , Validators } from '@angular/forms' ; import { AlertController , Loading , LoadingController , NavController , NavParams } from 'ionic-angular' ; import { AuthService } from './../../providers/auth.service' ; import { HomePage } from './../home/home' ; import { SignupPage } from './../signup/signup' ; @ Component ( { selector : 'page-signin' , templateUrl : 'signin.html' , } ) export class SigninPage { signinForm : FormGroup ; constructor ( public alertCtrl , public authService , public formBuilder , public loadingCtrl , public navCtrl , public navParams ) { let emailRegex = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i ; this . signinForm = this . formBuilder . group ( { email : [ '' , Validators . compose ( [ Validators . required , Validators . pattern ( emailRegex ) ] ) ] , password : [ '' , [ Validators . required , Validators . minLength ( 6 ) ] ] , } ) ; } onSubmit ( ) { let loading = this . showLoading ( ) ; this . authService . signinWithEmail ( this . signinForm . value ) . then ( ( isLogged ) => { if ( isLogged ) { this . navCtrl . setRoot ( HomePage ) ; loading . dismiss ( ) ; } } ) . catch ( ( error ) => { console . log ( error ) ; loading . dismiss ( ) ; this . showAlert ( error ) ; } ) ; } onSignup ( ) { this . navCtrl . push ( SignupPage ) ; } private showLoading ( ) { let loading = this . loadingCtrl . create ( { content : 'Please wait...' } ) ; loading . present ( ) ; return loading ; } private showAlert ( message ) { this . alertCtrl . create ( { message : message , buttons : [ 'Ok' ] } ) . present ( ) ; } }