|
|
|
@@ -1,9 +1,6 @@ |
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core'; |
|
|
|
import { IonItemOption, IonSlides, ModalController } from '@ionic/angular'; |
|
|
|
import { GooglePlus } from '@ionic-native/google-plus/ngx'; |
|
|
|
import { IonSlides, ModalController } from '@ionic/angular'; |
|
|
|
import { Platform } from '@ionic/angular'; |
|
|
|
import { AngularFireAuth } from '@angular/fire/auth'; |
|
|
|
import firebase from 'firebase'; |
|
|
|
import { ArFanCamPage } from '../ar-fan-cam/ar-fan-cam.page'; |
|
|
|
|
|
|
|
|
|
|
|
@@ -57,20 +54,10 @@ export class FanZonePage implements OnInit { |
|
|
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
private google: GooglePlus, |
|
|
|
private fireAuth: AngularFireAuth, |
|
|
|
private platform: Platform, |
|
|
|
private modalController: ModalController, |
|
|
|
) { } |
|
|
|
|
|
|
|
// async loginWithGoogle() { |
|
|
|
// await this.afAuth.signInWithPopup(new firebase.auth.GoogleAuthProvider()).then((data) => { |
|
|
|
// }, (err) => { |
|
|
|
// alert("Failed to login"); |
|
|
|
// this.showSocialLogin = true; |
|
|
|
// }); |
|
|
|
// } |
|
|
|
|
|
|
|
async ngOnInit() { |
|
|
|
|
|
|
|
this.fanStories = [{ |
|
|
|
@@ -89,13 +76,7 @@ export class FanZonePage implements OnInit { |
|
|
|
} |
|
|
|
|
|
|
|
ngAfterViewInit() { |
|
|
|
if (localStorage.googleUserData) { |
|
|
|
this.googleUserData = JSON.parse(localStorage.googleUserData); |
|
|
|
this.showSocialLogin = false; |
|
|
|
} else { |
|
|
|
this.googleUserData = {}; |
|
|
|
this.showSocialLogin = false; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
generateEmojiStream() { |
|
|
|
@@ -128,73 +109,10 @@ export class FanZonePage implements OnInit { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
doLogin(){ |
|
|
|
let params: any; |
|
|
|
if (this.platform.is('cordova')) { |
|
|
|
|
|
|
|
if (this.platform.is('android')) { |
|
|
|
params = { |
|
|
|
webClientId: '5602499136-aonjflj2acqva5gm4vvbuen4bc10sll1.apps.googleusercontent.com', // webclientID 'string' |
|
|
|
offline: true |
|
|
|
}; |
|
|
|
} else { |
|
|
|
params = {}; |
|
|
|
} |
|
|
|
|
|
|
|
alert(JSON.stringify(params)); |
|
|
|
|
|
|
|
this.google.login(params).then((response) => { |
|
|
|
alert("called google login plugin"); |
|
|
|
const { idToken, accessToken } = response; |
|
|
|
this.onLoginSuccess(idToken, accessToken); |
|
|
|
}).catch((error) => { |
|
|
|
console.log(error); |
|
|
|
alert('error:' + JSON.stringify(error)); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
console.log('else...'); |
|
|
|
this.fireAuth.signInWithPopup(new firebase.auth.GoogleAuthProvider()).then(data => { |
|
|
|
console.log('success in google login', data); |
|
|
|
this.googleUserData = { |
|
|
|
name: data.user.displayName, |
|
|
|
email: data.user.email, |
|
|
|
profileImage: data.user.photoURL, |
|
|
|
credentials: data.credential |
|
|
|
}; |
|
|
|
|
|
|
|
localStorage.googleUserData = JSON.stringify(this.googleUserData); |
|
|
|
|
|
|
|
this.showSocialLogin = false; |
|
|
|
}).catch(err => { |
|
|
|
alert(err.message); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
onLoginSuccess(accessToken, accessSecret) { |
|
|
|
const credential = accessSecret ? firebase.auth.GoogleAuthProvider.credential(accessToken, accessSecret) : firebase.auth.GoogleAuthProvider.credential(accessToken); |
|
|
|
this.fireAuth.signInWithCredential(credential).then((data) => { |
|
|
|
alert('successfully logged in'); |
|
|
|
this.googleUserData = { |
|
|
|
name: data.user.displayName, |
|
|
|
email: data.user.email, |
|
|
|
profileImage: data.user.photoURL, |
|
|
|
credentials: data.credential |
|
|
|
}; |
|
|
|
this.showSocialLogin = false; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
onLoginError(err) { |
|
|
|
console.log(err); |
|
|
|
} |
|
|
|
|
|
|
|
logout() { |
|
|
|
this.fireAuth.signOut().then(() => { |
|
|
|
this.isGoogleLogin = false; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
reversed(data: Array<any>) { |
|
|
|
return data.reverse(); |
|
|
|
} |
|
|
|
|