import { Router } from '@angular/router' ; import { Logging } from './../../services/Logging' ; import { AppManager } from './../../services/AppManager' ; import { TranslateService } from '@ngx-translate/core' ; import { Component } from '@angular/core' ; import { Location } from '@angular/common' ; import { AlertController , LoadingController , ModalController } from '@ionic/angular' ; @ Component ( { templateUrl : 'signin.html' } ) export class SignInPage { email : string ; password : string ; constructor ( public appManager , public modalController , public translate , public alertController , public loadingController , public logging , public router , private location ) { this . email = '' ; } cancelSignIn ( ) { this . modalController . dismiss ( ) ; } async performSignIn ( ) { const loading = await this . loadingController . create ( { message : 'Signing In..' } ) ; await loading . present ( ) ; let signInFailed = false ; try { const signInResult = await this . appManager . api . performSignIn ( this . email , this . password ) ; loading . dismiss ( ) ; localStorage . setItem ( 'authResponse' , JSON . stringify ( this . appManager . api . authResponse ) ) ; this . appManager . isUserAuthenticated ( true ) ; this . modalController . dismiss ( ) ; this . appManager . analytics . appEvent ( "Profile" , "SignedIn" ) ; } catch ( err ) { signInFailed = true ; loading . dismiss ( ) ; const a = await this . alertController . create ( { header : 'Open Charge Map' , subHeader : 'Email or Password not recognised' , buttons : [ 'Ok' ] } ) ; await a . present ( ) ; this . logging . log ( 'Error logging in:' + err ) ; } } }