Ejemplo n.º 1
0
        /// <summary>
        /// This will request a user's login status.  If the user is not logged in, Newgrounds Passport will be loaded in a new browser.
        /// Note: Due to security sandbox settings, WebGL players will see a prompt asking them if they want to load passport.
        /// </summary>
        public void requestLogin(Action onLoggedIn = null, Action onLoginFailed = null, Action onLoginCancelled = null)
        {
            SessionLoader sl = getSessionLoader();

            _waiting_for_login = false;

            // first, check any existing sessions we may have saved
            sl.checkSession((SessionResult r1) => {
                if (onLoggedIn != null)
                {
                    this.onLoggedIn(onLoggedIn);
                }
                if (onLoginFailed != null)
                {
                    this.onLoginFailed(onLoginFailed);
                }
                if (onLoginCancelled != null)
                {
                    this.onLoginCancelled(onLoginCancelled);
                }

                if (r1.getStatus() == SessionResult.USER_LOADED)
                {
                    // if we get here, the user has a valid, saved session
                    _loginSuccess(r1);
                }
                else
                {
                    // if we get here we need to start a new session
                    sl.startSession((SessionResult r2) =>
                    {
                        // this shouldn't ever happen unless there's a server issue.
                        if (r2.getStatus() == SessionResult.SESSION_EXPIRED)
                        {
                            _loginFailed(r2);
                        }

                        // if the user is already considered logged in, we're good to go
                        else if (r2.getStatus() == SessionResult.USER_LOADED)
                        {
                            _loginSuccess(r2);
                        }

                        // make a note that we are waiting for the user to log in now (see Update() method)
                        else
                        {
                            sl.loadPassport();
                            _waiting_for_login = true;
                        }
                    });
                }
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks any current login status.
        /// </summary>
        /// <param name="callback">An optional callback. Will be sent a true/false value indicating the user's login status.</param>
        /// <param name="silent">If true, callbacks set via onLoggedIn, onLoginFailed and onLoginCancelled will not be executed.</param>
        public void checkLogin(Action <bool> callback = null)
        {
            SessionLoader sl = getSessionLoader();

            sl.checkSession((SessionResult r) => {
                bool logged_in = (r.getStatus() == SessionResult.USER_LOADED) ? true : false;
                if (callback != null)
                {
                    callback(logged_in);
                }
            });
        }