Example #1
0
        private static void login(Provider provider, bool autoLogin, string payload = "", Reward reward = null)
        {
            SoomlaUtils.LogDebug(TAG, "Trying to login with provider " + provider.ToString());
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                SoomlaUtils.LogError(TAG, "Provider not supported or not set as active: " + provider.ToString());
                return;
            }


            setLoggedInForProvider(provider, false);
            ProfileEvents.OnLoginStarted(provider, autoLogin, userPayload);
            targetProvider.Login(
                /* success */ () => {
                targetProvider.GetUserProfile((UserProfile userProfile) => {
                    StoreUserProfile(userProfile);
                    setLoggedInForProvider(provider, true);
                    ProfileEvents.OnLoginFinished(userProfile, autoLogin, userPayload);
                    if (reward != null)
                    {
                        reward.Give();
                    }
                }, (string message) => {
                    ProfileEvents.OnLoginFailed(provider, message, autoLogin, userPayload);
                });
            },
                /* fail */ (string message) => { ProfileEvents.OnLoginFailed(provider, message, autoLogin, userPayload); },
                /* cancel */ () => { ProfileEvents.OnLoginCancelled(provider, autoLogin, userPayload); }
                );
        }
        /// <summary>
        /// Logs the user into the given provider.
        /// Supported platforms: Facebook, Twitter, Google+
        /// </summary>
        /// <param name="provider">The provider to log in to.</param>
        /// <param name="payload">A string to receive when the function returns.</param>
        /// <param name="reward">A <c>Reward</c> to give the user after a successful login.</param>
        public static void Login(Provider provider, string payload = "", Reward reward = null)
        {
            SoomlaUtils.LogDebug(TAG, "Trying to login with provider " + provider.ToString());
            SocialProvider targetProvider = GetSocialProvider(provider);
            string         userPayload    = (payload == null) ? "" : payload;

            if (targetProvider == null)
            {
                SoomlaUtils.LogError(TAG, "Provider not supported or not set as active: " + provider.ToString());
                return;
            }

            if (targetProvider.IsNativelyImplemented())
            {
                //fallback to native
                string rewardId = reward != null ? reward.ID : "";
                instance._login(provider, ProfilePayload.ToJSONObj(userPayload, rewardId).ToString());
            }

            else
            {
                setLoggedInForProvider(provider, false);
                ProfileEvents.OnLoginStarted(provider, userPayload);
                targetProvider.Login(
                    /* success */ () => {
                    targetProvider.GetUserProfile((UserProfile userProfile) => {
                        StoreUserProfile(userProfile);
                        setLoggedInForProvider(provider, true);
                        ProfileEvents.OnLoginFinished(userProfile, userPayload);
                        if (reward != null)
                        {
                            reward.Give();
                        }
                    }, (string message) => {
                        ProfileEvents.OnLoginFailed(provider, message, userPayload);
                    });
                },
                    /* fail */ (string message) => { ProfileEvents.OnLoginFailed(provider, message, userPayload); },
                    /* cancel */ () => { ProfileEvents.OnLoginCancelled(provider, userPayload); }
                    );
            }
        }