Ejemplo n.º 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); }
                );
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles an <c>onLoginStarted</c> event
        /// </summary>
        /// <param name="message">
        /// Will contain a numeric representation of <c>Provider</c>
        /// as well as payload </param>
        public void onLoginStarted(String message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onLoginStarted");

            JSONObject eventJson = new JSONObject(message);
            Provider   provider  = Provider.fromInt((int)(eventJson["provider"].n));

            JSONObject payloadJSON = new JSONObject(eventJson ["payload"].str);

            ProfileEvents.OnLoginStarted(provider, ProfilePayload.GetUserPayload(payloadJSON));
        }
Ejemplo n.º 3
0
        /// <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); }
                    );
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes the SOOMLA Profile Module.
        ///
        /// NOTE: This function must be called before any of the class methods can be used.
        /// </summary>
        public static void Initialize()
        {
            Dictionary <Provider, Dictionary <string, string> > customParams = GetCustomParamsDict();

            instance._initialize(GetCustomParamsJson(customParams));             //add parameters

#if SOOMLA_FACEBOOK
            unreadyProviders++;
            providers.Add(Provider.FACEBOOK, new FBSocialProvider());
#endif
#if SOOMLA_GOOGLE
            unreadyProviders++;
            providers.Add(Provider.GOOGLE, new GPSocialProvider());
#endif
#if SOOMLA_TWITTER
            unreadyProviders++;
            providers.Add(Provider.TWITTER, new TwitterSocialProvider());
#endif

            // pass params to non-native providers
            foreach (KeyValuePair <Provider, SocialProvider> entry in providers)
            {
                if (!entry.Value.IsNativelyImplemented())
                {
                    entry.Value.Configure(customParams[entry.Key]);
                }
            }

            ProfileEvents.OnSoomlaProfileInitialized += () => {
                // auto login non-native providers
                foreach (KeyValuePair <Provider, SocialProvider> entry in providers)
                {
                    if (!entry.Value.IsNativelyImplemented())
                    {
                        if (entry.Value.IsAutoLogin())
                        {
                            Provider provider = entry.Key;
                            if (wasLoggedInWithProvider(provider))
                            {
                                string payload = "";
                                Reward reward  = null;
                                if (entry.Value.IsLoggedIn())
                                {
                                    entry.Value.GetUserProfile((UserProfile userProfile) => {
                                        setLoggedInForProvider(provider, false);
                                        ProfileEvents.OnLoginStarted(provider, payload);
                                        StoreUserProfile(userProfile);
                                        setLoggedInForProvider(provider, true);
                                        ProfileEvents.OnLoginFinished(userProfile, payload);
                                        if (reward != null)
                                        {
                                            reward.Give();
                                        }
                                    }, (string message) => {
                                        ProfileEvents.OnLoginFailed(provider, message, payload);
                                    });
                                }
                                else
                                {
                                    Login(provider, payload, reward);
                                }
                            }
                        }
                    }
                }
            };

            #if UNITY_EDITOR
            TryFireProfileInitialized();
            #endif
        }