Exemplo n.º 1
0
        public static async void SendUri()
        {
            var localSettings = ApplicationData.Current.LocalSettings;

            try
            {
                Dictionary <string, string> pairs = new Dictionary <string, string>();
                pairs.Add("ChannelUri", channel.Uri.ToString());
                pairs.Add("check_uri", "true");
                Windows.Web.Http.HttpFormUrlEncodedContent formContent = new Windows.Web.Http.HttpFormUrlEncodedContent(pairs);
                Windows.Web.Http.HttpClient          client            = new Windows.Web.Http.HttpClient();
                Windows.Web.Http.HttpResponseMessage response          = await client.PostAsync(new Uri("http://" + backendUrl + "notifications/wns/wns.php" + finalUrl, UriKind.Absolute), formContent);

                string result = await response.Content.ReadAsStringAsync();

                JsonObject json       = JsonObject.Parse(result);
                bool       uri_exists = json.GetNamedBoolean("uri_exists");
                if (!uri_exists)
                {
                    localSettings.Values["ChannelUri"] = channel.Uri.ToString();
                }
            }
            catch
            {
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Converts a dictionary of key/value pairs into a query string.
 /// </summary>
 /// <param name="parameters">Key/value pairs of parameters.</param>
 /// <returns>Query string from all the key/value pair data supplied in the dictionary.</returns>
 public static string CreateQuerystring(IDictionary <string, string> parameters)
 {
     if (parameters == null || parameters.Count == 0)
     {
         return(null);
     }
     else
     {
         var contents = new Windows.Web.Http.HttpFormUrlEncodedContent(parameters);
         return(contents.ReadAsStringAsync().AsTask().Result);
     }
 }
Exemplo n.º 3
0
        private async void Authenticate()
        {
            var SpotifyUrl = $"https://accounts.google.com/o/oauth2/auth?client_id={this.clientId}&redirect_uri={Uri.EscapeDataString(this.redirectURI)}&response_type=code&scope={Uri.EscapeDataString(this.scope)}";
            var StartUri   = new Uri(SpotifyUrl);
            var EndUri     = new Uri(redirectURI);

            WebAuthenticationResult WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, StartUri, EndUri);

            if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
            {
                var decoder = new WwwFormUrlDecoder(new Uri(WebAuthenticationResult.ResponseData).Query);
                if (decoder[0].Name != "code")
                {
                    System.Diagnostics.Debug.WriteLine($"OAuth authorization error: {decoder.GetFirstValueByName("error")}.");
                    return;
                }

                var autorizationCode = decoder.GetFirstValueByName("code");

                var pairs = new Dictionary <string, string>();
                pairs.Add("code", autorizationCode);
                pairs.Add("client_id", this.clientId);
                pairs.Add("client_secret", this.clientSecret);
                pairs.Add("redirect_uri", this.redirectURI);
                pairs.Add("grant_type", "authorization_code");

                var formContent = new Windows.Web.Http.HttpFormUrlEncodedContent(pairs);

                var client = new Windows.Web.Http.HttpClient();
                var httpResponseMessage = await client.PostAsync(new Uri("https://www.googleapis.com/oauth2/v4/token"), formContent);

                if (!httpResponseMessage.IsSuccessStatusCode)
                {
                    System.Diagnostics.Debug.WriteLine($"OAuth authorization error: {httpResponseMessage.StatusCode}.");
                    return;
                }

                string jsonString = await httpResponseMessage.Content.ReadAsStringAsync();

                var jsonObject  = Windows.Data.Json.JsonObject.Parse(jsonString);
                var accessToken = jsonObject["access_token"].GetString();
                this.accessToken = accessToken;

                this.gotAccessToken = true;

                this.GMailServices = new GmailServices(this.accessToken);
                this.GMailServices.LatestEmailsEvent += (sender, status) => { this.LatestEmailsEvent?.Invoke(this, status); };

                this.CalendarServices = new CalendarServices(this.accessToken);
                this.CalendarServices.LatestCalendarEvent += (sender, status) => { this.LatestCalendarEvent?.Invoke(this, status); };
            }
        }
        private async void SendData()
        {
            if (!password1.Password.Equals(password2.Password))
            {
                var dialog = new MessageDialog("Passwords do not match", "Error");
                await dialog.ShowAsync();
            }
            else if (!Regex.IsMatch(email.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
            {
                var dialog = new MessageDialog("E-mail is not valid", "Error");
                await dialog.ShowAsync();
            }
            else
            {
                pairs.Clear();
                pairs.Add("email", email.Text);
                pairs.Add("password", password1.Password);
                Windows.Web.Http.HttpFormUrlEncodedContent formContent = new Windows.Web.Http.HttpFormUrlEncodedContent(pairs);
                await clientOb.PostAsync(connectionUri, formContent);

                Windows.Web.Http.HttpResponseMessage response = await clientOb.PostAsync(connectionUri, formContent);

                if (!response.IsSuccessStatusCode)
                {
                    var dialog = new MessageDialog("Error while logging in", "Error");
                    await dialog.ShowAsync();
                }
                else
                {
                    responseBodyAsText = await response.Content.ReadAsStringAsync();

                    responseBodyAsText = responseBodyAsText.Replace("<br>", Environment.NewLine); // Insert new lines
                    if (responseBodyAsText.Substring(13, 2).Equals("ko"))
                    {
                        var dialog = new MessageDialog("Error in registration", "Error");
                        await dialog.ShowAsync();
                    }
                    else
                    {
                        {
                            var dialog = new MessageDialog("registred", "Registred");
                            await dialog.ShowAsync();

                            this.Frame.Navigate(typeof(MainPage));
                        }
                    }
                }
            }
        }
        private async void SendData()
        {
            if (!password1.Password.Equals(password2.Password))
            {
                var dialog = new MessageDialog("Passwords do not match", "Error");
                await dialog.ShowAsync();
            }
            else if (!Regex.IsMatch(email.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
            {
                var dialog = new MessageDialog("E-mail is not valid", "Error");
                await dialog.ShowAsync();
            }
            else
            {
                pairs.Clear();
                pairs.Add("email", email.Text);
                pairs.Add("password", password1.Password);
                Windows.Web.Http.HttpFormUrlEncodedContent formContent = new Windows.Web.Http.HttpFormUrlEncodedContent(pairs);
                await clientOb.PostAsync(connectionUri, formContent);

                Windows.Web.Http.HttpResponseMessage response = await clientOb.PostAsync(connectionUri, formContent);

                if (!response.IsSuccessStatusCode)
                {
                    var dialog = new MessageDialog("Error while logging in", "Error");
                    await dialog.ShowAsync();
                }
                else
                {

                    responseBodyAsText = await response.Content.ReadAsStringAsync();
                    responseBodyAsText = responseBodyAsText.Replace("<br>", Environment.NewLine); // Insert new lines
                    if (responseBodyAsText.Substring(13, 2).Equals("ko"))
                    {
                        var dialog = new MessageDialog("Error in registration", "Error");
                        await dialog.ShowAsync();
                    }
                    else
                    {
                        {
                            var dialog = new MessageDialog("registred", "Registred");
                            await dialog.ShowAsync();
                            this.Frame.Navigate(typeof(MainPage));
                        }
                    }

                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Converts a dictionary of key/value pairs into a query string.
 /// </summary>
 /// <param name="parameters">Key/value pairs of parameters.</param>
 /// <returns>Query string from all the key/value pair data supplied in the dictionary.</returns>
 public static string CreateQuerystring(IDictionary<string, string> parameters)
 {
     if (parameters == null || parameters.Count == 0)
         return null;
     else
     {
         var contents = new Windows.Web.Http.HttpFormUrlEncodedContent(parameters);
         return contents.ReadAsStringAsync().AsTask().Result;
     }
 }