Exemplo n.º 1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            webBrowser1.BringToFront();
            //If Sucessfully Logged in already and pressing Login again, show menu
            if (userAuthenticated)
            {
                CurrentUser.LogEvent(null, null, "Login", "User Logged into OpenWorld", "Congratulations, you have sucessfully logged in to for openworld on " + DateTime.Now.ToString());
                Repository.Save(CurrentUser);
                DialogResult = DialogResult.OK;
            }

            string[] extendedPermissions = new[] { "publish_stream", "offline_access" };
            var      parameters          = new Dictionary <string, object>

            {
                { "display", "popup" },
                { "response_type", "token" },
                { "redirect_uri", hostConstants.redirectURI },
                { "scope", "email,public_profile,publish_actions" }
            };

            /**
             * result = fb.Get("oauth/access_token", new
             * {
             *  client_id = appId,
             *  client_secret = appSecret,
             *  grant_type = "client_credentials"
             * });
             **/

            Debug.Print("F**k this");
            Debug.Print("fb:" + fb.ToString());
            //SetMessage("result:" + result.ToString());

            //SetMessage("AccessToken:" + fb.AccessToken.ToString());
            fb.AppId     = hostConstants.appId;
            fb.AppSecret = hostConstants.appSecret;


            var loginURL = fb.GetLoginUrl(parameters);

            Debug.Print("loginURL:" + loginURL);
            webBrowser1.Navigate(loginURL);
        }
Exemplo n.º 2
0
        private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            FacebookOAuthResult authResult;

            string OWUsername = "******";
            bool   userUnique;

            if (fb.TryParseOAuthCallbackUrl(e.Url, out authResult))
            {
                if (authResult.IsSuccess)
                {
                    //System.Windows.Forms.MessageBox.Show("Logged In");
                    SetMessage("Access Token" + authResult.AccessToken);
                    //fb.AccessToken = authResult.AccessToken;

                    var accesstoken = authResult.AccessToken;
                    fbuser         = new FacebookClient(accesstoken);
                    fb.AccessToken = accesstoken;

                    var results = (IDictionary <string, object>)fb.Get("/me");
                    fbRecord = sysFacebook.ParseResponse(results, authResult);

                    if (fbRecord == null)
                    {
                        System.Windows.Forms.MessageBox.Show("Failed to Parse Response");
                    }
                    else
                    {
                        SetMessage("LOGON via FB Sucess");
                        SetMessage(fbRecord.LongDesc());
                    }

                    CurrentUser = sysFacebook.UserExists(sess, fbRecord);
                    if (CurrentUser != null)
                    {
                        SetMessage("User Found:" + CurrentUser.LongName);
                        if (CurrentUser.fbAccessToken != fbRecord.AccessToken)
                        {
                            SetMessage("Refreshing token");
                            CurrentUser.fbAccessToken  = fbRecord.AccessToken;
                            CurrentUser.fbTokenExpires = fbRecord.Expires;
                            sess.SaveOrUpdate(CurrentUser);
                            sess.Flush();
                        }
                        //System.Windows.Forms.MessageBox.Show("Welcome Back : "+CurrentUser.LongName, "User Login");
                        //Ok to proceed
                        SetOkToProceed();
                    }
                    else
                    {
                        //Register new
                        if (System.Windows.Forms.MessageBox.Show("User not registered, Register now?", "User Registration", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                        {
                            //Register
                            userUnique = false;
                            while (userUnique == false)
                            {
                                OWUsername  = Microsoft.VisualBasic.Interaction.InputBox("Register Username", "Enter  A unique username for OpenWorld to be Associated with this FaceBook Account", "Name", 200, 400);
                                CurrentUser = sysFacebook.FindByUserName(sess, OWUsername);
                                userUnique  = (CurrentUser == null);
                                if (!userUnique)
                                {
                                    SetMessage("Username " + OWUsername + " is taken, please choose another");
                                }
                            }
                            //Create new
                            SetMessage("Creating new user:"******"Registered", "User Registered with OpenWorld", "Congratulations, you have sucessfully registered for openworld");
                            repo.Save(CurrentUser);
                            SetOkToProceed();
                        }
                    }
                }
                else  //Auth Failed
                {
                    SetMessage("FBAuth failed;" + authResult.ErrorDescription);
                }
            }
        }