import { Component } from '@angular/core' ; import { TranslateService } from '@ngx-translate/core' ; import { IonicPage , NavController , ToastController } from 'ionic-angular' ; import { Storage } from '@ionic/storage' ; import { User } from '../../providers/providers' ; import { MainPage } from '../pages' ; import { Settings } from "../../providers/settings/settings" ; @ IonicPage ( ) @ Component ( { selector : 'page-login' , templateUrl : 'login.html' } ) export class LoginPage { account : { email : string ; password : string ; } = { email : '' , password : '' } ; private loginErrorString : string ; private networkErrorString : string ; constructor ( public navCtrl , public user , public settings , public storage , public toastCtrl , public translateService ) { this . translateService . get ( 'LOGIN_ERROR' ) . subscribe ( ( value ) => { this . loginErrorString = value ; } ) ; this . translateService . get ( 'NETWORK_ERROR' ) . subscribe ( ( value ) => { this . networkErrorString = value ; } ) ; } doLogin ( ) { this . user . login ( this . account ) . subscribe ( ( resp ) => { if ( resp . success ) { this . navCtrl . push ( MainPage ) ; } else { let toast = this . toastCtrl . create ( { message : this . loginErrorString , duration : 3000 , position : 'top' } ) ; toast . present ( ) ; } } , ( err ) => { let toast = this . toastCtrl . create ( { message : this . networkErrorString , duration : 3000 , position : 'top' } ) ; toast . present ( ) ; } ) ; } forget ( ) { this . navCtrl . push ( 'LoginPage' ) ; } signup ( ) { this . navCtrl . push ( 'SignupPage' ) ; } }