private void btnSave_Click(object sender, EventArgs e) { SetMessage("Starting User Save"); foreach (hostUser user in bs_hostUser.List) { repo.Save(user); SetMessage("Saved " + user.LongName); } }
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); } } }