Example #1
0
        /// <summary>
        /// Displays an integrated browser to allow the user to log on to the
        /// Facebook web page.
        /// </summary>
        public bool ConnectToFacebook(bool forceLogin)
        {
            if ((!IsSessionActive() && IsDesktopApplication) || forceLogin)
            {
                DialogResult result;

                //Generate State GUID for preventing CSRF
                _stateVerification = Guid.NewGuid().ToString();

                var formLogin = new FacebookAuthentication(LoginUrl, _stateVerification, this);

                result = formLogin.ShowDialog();

                if (result == DialogResult.Cancel)
                {
                    formLogin.Dispose();
                    return(false);
                }

                int loggedInUserId;

                if (int.TryParse(GetLoggedInUser(), out loggedInUserId))
                {
                    if (loggedInUserId > 0)
                    {
                        formLogin.Dispose();
                        return(true);
                    }
                    else
                    {
                        formLogin.Dispose();
                        return(false);
                    }
                }
                else
                {
                    formLogin.Dispose();
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Displays an integrated browser to allow the user to log on to the
        /// Facebook web page.
        /// </summary>
        public void ConnectToFacebook()
        {
            if (!IsSessionActive() && IsDesktopApplication)
            {
                DialogResult result;
                SetAuthenticationToken();

                using (var formLogin = new FacebookAuthentication(LoginUrl))
                {
                    result = formLogin.ShowDialog();
                }
                if (result == DialogResult.OK)
                {
                    CreateSession();
                }
                else
                {
                    throw new Exception("Login attempt failed");
                }
            }
        }