Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- twitter.com/cryptsploit
- function signIn () {
- firebaseSignInTimerStart = new Date();
- playerAccount = new PlayerAccount();
- console.log('Signing in to Firebase...');
- // Try signing into Firebase
- // If success, send token to services in auth request
- // If failed, send local ID in auth request
- // If no local ID exists, send blank auth request to have server generate a local ID
- var config = {
- apiKey: "AIzaSyDP4SIjKaw6A4c-zvfYxICpbEjn1rRnN50",
- authDomain: "shellshockio-181719.firebaseapp.com",
- databaseURL: "https://shellshockio-181719.firebaseio.com",
- projectId: "shellshockio-181719",
- storageBucket: "shellshockio-181719.appspot.com",
- messagingSenderId: "68327206324"
- }
- firebase.initializeApp(config);
- firebase.auth().onAuthStateChanged(function (signedInUser) {
- //console.log('user: ' + JSON.stringify(signedInUser));
- if (upgradingAnon && !hasValue(signedInUser)) {
- return;
- }
- //vueApp.hideFirebaseSignIn();
- if (signedInUser) {
- firebaseUser = signedInUser;
- if (firebaseUser.isAnonymous) {
- console.log('Firebase: anonymous user');
- anonymousUser = firebaseUser;
- } else {
- console.log('Firebase: auth provider: ' + firebaseUser.providerData[0].providerId);
- // If this is an email/password login, and user has yet to verify email address, do so here
- if (!firebaseUser.emailVerified && firebaseUser.providerData[0].providerId == 'password') {
- console.log('Firebase: email not yet verified');
- vueApp.showResendEmail();
- }
- }
- firebaseAccountFound();
- } else {
- console.log('Firebase: no account found');
- noFirebaseAccount();
- }
- });
- }
- function firebaseAccountFound () {
- if (signingIn) {
- return;
- }
- signingIn = true;
- upgradingAnon = false;
- firebaseUser.getIdToken(true)
- .then((firebaseToken) => {
- vueApp.showSpinner('signin_auth_title', 'signin_auth_msg');
- // Send ID token to server
- // Server verifies token against Firebase, then generates and
- // returns a session ID that will be used for future transactions
- // in the Shell Shockers database
- //console.log('Authing player\'s firebase account with services, token: ' + JSON.stringify(firebaseToken));
- api_auth(firebaseToken, authSuccess, authFailure, authClosed);
- }).catch(function (error) {
- console.log(error);
- signingIn = false;
- });
- // Anon users don't have provider data
- if (firebaseUser.photoURL && firebaseUser.providerData && firebaseUser.providerData.length > 0) {
- var url = firebaseUser.photoURL;
- var pd = firebaseUser.providerData[0];
- if (pd.providerId == 'facebook.com') { // Facebook sucks
- url = 'https://graph.facebook.com/' + pd.uid + '/picture';
- }
- vueApp.photoUrl = url;
- }
- }
- function noFirebaseAccount () {
- firebase.auth().signInAnonymously().catch(function(error) {
- writeMsg('Failed Firebase anonymous signin, code: {0}, msg: {1}'.format(error.code, error.message));
- })
- sendOneSignalTagsForAnon();
- }
- function sendFirebaseVerificationEmail () {
- console.log('sending email verification to: ' + firebaseUser.email);
- firebaseUser.sendEmailVerification();
- }
- function authSuccess(authResponse) {
- //console.log('authorization successful: ' + JSON.stringify(authResponse));
- if (authResponse.error) {
- console.log('accountDataResponse Error: ' + JSON.stringify(accountDataResponse.error));
- } else {
- //console.log('services auth response: ' + JSON.stringify(authResponse));
- playerAccount.signedIn(firebaseUser, authResponse);
- ready_auth = true;
- sendOneSignalTagsForUser();
- ga('send', 'event', vueData.googleAnalytics.cat.playerStats, vueData.googleAnalytics.action.eggCount, vueData.googleAnalytics.isUser, vueData.eggs );
- theTimeTracker(firebaseSignInTimerStart, vueData.googleAnalytics.label.signInTiming, vueData.googleAnalytics.label.loading);
- ga('send', 'event', vueData.googleAnalytics.cat.playerStats, vueData.googleAnalytics.action.signIn, vueData.googleAnalytics.label.signInCompleted);
- console.log('Signed in');
- }
- vueApp.authCompleted(authResponse.emailVerified);
- }
- function authFailure() {
- console.log('authorization failed');
- ga('send', 'event', googleAnalytics.cat.playerStats, googleAnalytics.action.signIn, googleAnalytics.label.signInAuthFailed);
- vueApp.authCompleted();
- }
- function authClosed(code) {
- console.log('auth ws closed, code: ' + code);
- if (code === 1006) {
- vueApp.showGenericPopup('signin_failed_title', 'signin_failed', 'ok');
- return;
- }
- signingIn = false;
- }
- function showSignInDialog () {
- if (!firebaseUi) {
- firebaseUi = new firebaseui.auth.AuthUI(firebase.auth());
- }
- var firebaseUiConfig = firebaseUiCreateConfig();
- firebaseUi.start('#firebaseui-auth-container', firebaseUiConfig);
- }
- function firebaseUiCreateConfig () {
- return {
- autoUpgradeAnonymousUsers: true,
- callbacks: {
- signInSuccessWithAuthResult: firebaseUiSignInSuccess,
- signInFailure: firebaseUiSignInFailure,
- uiShown: function (e) { console.log('UI: showed firebase UI'); } // TODO: Remove Cancel button?
- },
- credentialHelper: firebaseui.auth.CredentialHelper.NONE,
- signInFlow: 'popup',
- //signInSuccessUrl: 'https://shellshock.io',
- signInOptions: [
- // Leave the lines as is for the providers you want to offer your users.
- {
- provider: firebase.auth.EmailAuthProvider.PROVIDER_ID,
- requireDisplayName: false,
- },
- firebase.auth.FacebookAuthProvider.PROVIDER_ID,
- firebase.auth.GoogleAuthProvider.PROVIDER_ID,
- ],
- // Terms of service url.
- tosUrl: 'http://www.bluewizard.com/terms'
- };
- }
- function firebaseUiSignInSuccess (firebaseResult, redirectUrl) {
- firebaseUser = firebaseResult.user;
- var emailVerified = firebaseUser.emailVerified;
- var credential = firebaseResult.credential;
- var isNewUser = firebaseResult.additionalUserInfo.isNewUser;
- var providerId = firebaseResult.additionalUserInfo.providerId;
- var operationType = firebaseResult.operationType;
- vueApp.hideFirebaseSignIn();
- // For email verification only
- if (providerId == 'password' && !emailVerified) {
- sendFirebaseVerificationEmail();
- }
- console.log('Authing Firebase ID: ' + firebase.uid);
- firebaseAccountFound();
- return false; // Don't automatically redirect
- }
- function firebaseUiSignInFailure (error) {
- vueApp.hideFirebaseSignIn();
- console.log('Firebase: sign in failure, error code: ' + error.code);
- if (error.code === 'firebaseui/anonymous-upgrade-merge-conflict') {
- // Player has signed into a pre-existing Firebase account
- // The firebase.authStateChanged handler is automatically fired after this event with a null user
- // Need to flag this so it doesn't create a new anonymous user
- upgradingAnon = true;
- firebase.auth().signInWithCredential(error.credential);
- anonymousUser.delete();
- setTimeout(() => {
- vueApp.$nextTick(() => {
- vueApp.urlParamSet = vueApp.urlParams ? true : null;
- vueApp.shellShockUrlParamaterEvents();
- });
- }, 2000);
- } else {
- return Promise.resolve();
- }
- }
- function signOut () {
- firebase.auth().signOut().then(function() {
- playerAccount = new PlayerAccount();
- }, function(err) {
- console.log(err);
- });
- ga('send', 'event', googleAnalytics.cat.playerStats, googleAnalytics.action.signIn, googleAnalytics.label.signInOut);
- vueApp.photoUrl = null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement