private void InitialPage_LayoutUpdated(object sender, EventArgs e) { this.LayoutUpdated -= InitialPage_LayoutUpdated; if (ConsentManager.HasConsented) { if (!(App.Current as App).JustLoggedOut) { TombstoneData data = TombstoneManager.Load(); if (data != null) { TinderSession activeSession = TinderSession.FromTombstoneData(data); (App.Current as App).RightSideBar.DataContext = activeSession.Matches; TopBarViewModel.ShowTopButtons = System.Windows.Visibility.Visible; NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); App.RootFrame.RemoveBackEntry(); return; } } else { LoginButtonBorder.Visibility = System.Windows.Visibility.Visible; } } if (!(App.Current as App).JustLoggedOut) { Open.Begin(); } }
private async System.Threading.Tasks.Task Authenticate(string accessToken, string fbid) { ProfilePhoto.Background = new ImageBrush() { ImageSource = new BitmapImage(new Uri(String.Format("https://graph.facebook.com/me/picture?access_token={0}&height=100&width=100", accessToken))) }; FacebookSessionInfo sessionInfo = new FacebookSessionInfo(); sessionInfo.FacebookToken = accessToken; sessionInfo.FacebookID = fbid; Geolocator location = new Geolocator(); location.DesiredAccuracy = PositionAccuracy.Default; var usrLocation = await location.GetGeopositionAsync(); TinderSession activeSession = TinderSession.CreateNewSession(sessionInfo, new Position() { Latitude = usrLocation.Coordinate.Latitude, Longitude = usrLocation.Coordinate.Longitude }); if (await activeSession.Authenticate()) { (App.Current as App).RightSideBar.DataContext = activeSession.Matches; TopBarViewModel.ShowTopButtons = System.Windows.Visibility.Visible; NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); App.RootFrame.RemoveBackEntry(); } }
private void PhoneApplicationService_Activated(object sender, Microsoft.Phone.Shell.ActivatedEventArgs e) { if (!e.IsApplicationInstancePreserved) { TombstoneData data = TombstoneManager.Load(); if (data != null) { TinderSession.FromTombstoneData(data); } } }
//private async System.Threading.Tasks.Task Authenticate(string accessToken, string fbid) //{ // ProfilePhoto.Background = new ImageBrush() { ImageSource = new BitmapImage(new Uri(String.Format("https://graph.facebook.com/me/picture?access_token={0}&height=100&width=100", accessToken))) }; // FacebookSessionInfo sessionInfo = new FacebookSessionInfo(); // sessionInfo.FacebookToken = accessToken; // sessionInfo.FacebookID = fbid; // Geolocator location = new Geolocator(); // location.DesiredAccuracy = PositionAccuracy.Default; // var usrLocation = await location.GetGeopositionAsync(); // TinderSession activeSession = TinderSession.CreateNewSession(sessionInfo, new GeographicalCordinates() { Latitude = usrLocation.Coordinate.Latitude, Longitude = usrLocation.Coordinate.Longitude }); // if (await activeSession.Authenticate()) // { // (App.Current as App).RightSideBar.DataContext = activeSession.Matches; // TopBarViewModel.ShowTopButtons = System.Windows.Visibility.Visible; // NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); // App.RootFrame.RemoveBackEntry(); // } //} private async System.Threading.Tasks.Task Authenticate(string accessToken, string lkId) { // INICIO string _requestPeopleUrl = "http://api.linkedin.com/v1/people/~"; //string _requestPeopleUrl = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline)"; string nonce = oAuthUtil.GetNonce(); string timeStamp = oAuthUtil.GetTimeStamp(); try { System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient(); httpClient.MaxResponseContentBufferSize = int.MaxValue; httpClient.DefaultRequestHeaders.ExpectContinue = false; System.Net.Http.HttpRequestMessage requestMsg = new System.Net.Http.HttpRequestMessage(); requestMsg.Method = new System.Net.Http.HttpMethod("GET"); requestMsg.RequestUri = new Uri(_requestPeopleUrl, UriKind.Absolute); requestMsg.Headers.Add("x-li-format", "json"); string sigBaseStringParams = "oauth_consumer_key=" + _consumerKey; sigBaseStringParams += "&" + "oauth_nonce=" + nonce; sigBaseStringParams += "&" + "oauth_signature_method=" + "HMAC-SHA1"; sigBaseStringParams += "&" + "oauth_timestamp=" + timeStamp; sigBaseStringParams += "&" + "oauth_token=" + _accessToken; sigBaseStringParams += "&" + "oauth_verifier=" + _oAuthVerifier; sigBaseStringParams += "&" + "oauth_version=1.0"; string sigBaseString = "GET&"; sigBaseString += Uri.EscapeDataString(_requestPeopleUrl) + "&" + Uri.EscapeDataString(sigBaseStringParams); // LinkedIn requires both consumer secret and request token secret string signature = oAuthUtil.GetSignature(sigBaseString, _consumerSecretKey, _accessTokenSecretKey); string data = "realm=\"http://api.linkedin.com/\", oauth_consumer_key=\"" + _consumerKey + "\", oauth_token=\"" + _accessToken + "\", oauth_verifier=\"" + _oAuthVerifier + "\", oauth_nonce=\"" + nonce + "\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"" + timeStamp + "\", oauth_version=\"1.0\", oauth_signature=\"" + Uri.EscapeDataString(signature) + "\""; requestMsg.Headers.Authorization = new AuthenticationHeaderValue("OAuth", data); var response = await httpClient.SendAsync(requestMsg); var text = response.Content.ReadAsStringAsync(); _linkedInProfile = await text; } catch (Exception Err) { throw; } //<?xml version="1.0" encoding="UTF-8" standalone="yes"?> //<person> // <first-name>Felipe</first-name> // <last-name>Cembranelli</last-name> // <headline>Manager at CI&T</headline> // <site-standard-profile-request> // <url>https://www.linkedin.com/profile/view?id=3770090&authType=name&authToken=moVF&trk=api*a3576543*s3647743*</url> // </site-standard-profile-request> //</person> var linkedinUser = JsonConvert.DeserializeObject <LinkedinUser>(_linkedInProfile); // FIM //ProfilePhoto.Background = new ImageBrush() { ImageSource = new BitmapImage(new Uri(String.Format("https://graph.facebook.com/me/picture?access_token={0}&height=100&width=100", accessToken))) }; LinkedInSessionInfo sessionInfo = new LinkedInSessionInfo(); sessionInfo.AcessToken = accessToken; sessionInfo.LinkedInID = linkedinUser.FirstName; sessionInfo.LinkedinUser = linkedinUser; //Geolocator location = new Geolocator(); //location.DesiredAccuracy = PositionAccuracy.Default; //var usrLocation = await location.GetGeopositionAsync(); //TinderSession activeSession = TinderSession.CreateNewSession(sessionInfo, new GeographicalCordinates() { Latitude = usrLocation.Coordinate.Latitude, Longitude = usrLocation.Coordinate.Longitude }); TinderSession activeSession = TinderSession.CreateNewSession(sessionInfo); if (await activeSession.Authenticate(_consumerKey, _accessToken, _oAuthVerifier, _consumerSecretKey, _accessTokenSecretKey)) { (App.Current as App).RightSideBar.DataContext = activeSession.Matches; TopBarViewModel.ShowTopButtons = System.Windows.Visibility.Visible; NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); App.RootFrame.RemoveBackEntry(); } }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <Message> Post([FromBody] Message message) { if (message.Type == "Message") { var reply = message.CreateReplyMessage(); if (message.BotUserData != null) { if (ReadyToTalk) { var keys = App.TinderSessions.Keys.ToList <string>(); if (keys.IndexOf(message.BotUserData.ToString()) >= 0) { TinderSession = App.TinderSessions[message.BotUserData.ToString()]; if (TinderSession.FbSessionInfo == null) { BotSessionSetup = 1; ReadyToTalk = false; } else { BotSessionSetup = 6; switch (message.Text.ToLower()) { case "list": reply = ListMatches(message); break; case "start": this.feedTimer = GetFeedTimer(message.BotUserData.ToString()); if (this.feedTimer != null) { this.feedTimer.Start(); reply.Text = "Hitch bot has started to talk with your matches"; } break; case "stop": this.feedTimer = GetFeedTimer(message.BotUserData.ToString()); if (this.feedTimer != null) { this.feedTimer.Stop(); reply.Text = "Hitch bot has stopped to talk with your matches"; } break; } } } else { reply.Text = MSG_ADD_BOT; BotSessionSetup = 0; ReadyToTalk = false; } } else { while (reply.Text == string.Empty && BotSessionSetup <= 4) { if (FacebookID == string.Empty) { if (BotSessionSetup == 0) { BotSessionSetup = 1; reply.Text = "Add your Facebook ID"; } else { FacebookID = message.Text; } } else if (FacebookToken == string.Empty) { if (BotSessionSetup == 1) { BotSessionSetup = 2; reply.Text = "Add your Facebook Token"; } else { FacebookToken = message.Text; } } else if (Latitude == 0) { if (BotSessionSetup == 2) { BotSessionSetup = 3; reply.Text = "Add your Latitude"; } else { try { Latitude = double.Parse(message.Text); if (Latitude < -85 || Latitude > 85) { reply.Text = "The latitude is out of range, please try enter it again number between -85 and 85"; } } catch { reply.Text = "An Error has occurred during the latitude parsing, please try enter it again"; } } } else { if (BotSessionSetup == 3) { BotSessionSetup = 4; reply.Text = "Add your Longitude"; } else { try { Longitude = double.Parse(message.Text); if (Longitude < -180 || Longitude > 180) { reply.Text = "The longitude is out of range, please try enter it again number between -180 and 180"; } else { BotSessionSetup = 5; } } catch { reply.Text = "An Error has occurred during the longitude parsing, please try enter it again"; } } } } if (BotSessionSetup == 5) { var fbsession = new FacebookSessionInfo(); fbsession.FacebookID = FacebookID; fbsession.FacebookToken = FacebookToken; Position location = new Position(); location.Latitude = Latitude; location.Longitude = Longitude; this.TinderSession = TinderSession.CreateNewSession(fbsession, location); try { //This method besides the authentication, sets the location, calls the update and checks for recommendations await this.TinderSession.Authenticate(); BotSessionSetup = 6; ReadyToTalk = true; reply.Text = $"Your Tinder account is connected to HitchBot! \r\n You have {this.TinderSession.Matches.Count} Matches"; //Update Match status and upload the data do AzureTable await ProcessMatches(); } catch (Exception ex) { reply.Text = $"Some error has occurred: { ex.Message }. Please try adding your facebook and location again"; BotSessionSetup = 1; FacebookID = string.Empty; FacebookToken = string.Empty; Longitude = 0; Latitude = 0; ReadyToTalk = false; } try { App.TinderSessions.Add(message.BotUserData.ToString(), this.TinderSession); } catch (ArgumentException) { //There is an element using the same key, so just update the object and you are okay to go App.TinderSessions[message.BotUserData.ToString()] = this.TinderSession; } } } } else { reply.Text = MessagesController.MSG_ADD_BOT; BotSessionSetup = 0; } return(reply); } else { return(HandleSystemMessage(message)); } }