private static async Task <WeatherResponse> GetResponse(Uri m_uri) { dynamic client = new RestSharp.Portable.HttpClient.RestClient { Proxy = Config.getWebProxy(), BaseUrl = m_uri }; dynamic request = new RestSharp.Portable.RestRequest(); dynamic response = await client.Execute <WeatherResponse>(request); if (response.StatusCode == HttpStatusCode.OK) { WeatherResponse weatherResponse = response.Data; if (weatherResponse.response.error != null) { throw new WUndergroundException(weatherResponse.response.error.description); } return(weatherResponse); } else { throw new WUndergroundException(response.Content); } }
private async void button1_Click(object sender, RoutedEventArgs e) { var request = new RestRequest("http://localhost:3000/oauth/token", Method.POST); var client = new RestSharp.Portable.HttpClient.RestClient("http://localhost:3000/"); client.IgnoreResponseStatusCode = true; request.AddBody(new { client_id = "484635247e3c19981631ce647990334627ea514586be5fa42f5fee80cbf8bca2", client_secret = "e8a4103368c08631bb8cafcd431c75c2ca99bb35fa3dd75f08bc2eaa5376d75e", grant_type = "password", password = passwordBox.Password, username = textBox3.Text }); var response = await client.Execute(request).ConfigureAwait(true); HttpStatusCode statusCode = response.StatusCode; int numericStatusCode = (int)statusCode; if (numericStatusCode == 200) { JsonDeserializer deserial = new JsonDeserializer(); Token token = deserial.Deserialize <Token>(response); ApplicationState.CurrentToken = token; var dialog = new Windows.UI.Popups.MessageDialog("Zalogowano poprawnie, nastąpi przekierowanie do strony głównej"); dialog.Commands.Add(new Windows.UI.Popups.UICommand("Ok") { Id = 0 }); dialog.CancelCommandIndex = 0; var result = await dialog.ShowAsync(); var btn = sender as Button; btn.Content = $"Result: {result.Label} ({result.Id})"; Frame.Navigate(typeof(MainPage), null); } if (numericStatusCode == 401) { var dialog = new Windows.UI.Popups.MessageDialog("Niepoprawna nazwa użytkownika lub hasło"); dialog.Commands.Add(new Windows.UI.Popups.UICommand("Ok") { Id = 0 }); dialog.CancelCommandIndex = 0; var result = await dialog.ShowAsync(); var btn = sender as Button; //btn.Content = $"Result: {result.Label} ({result.Id})"; passwordBox.Password = ""; } }
public async Task <SignupResponseEnum> SignupAsync(string email, string password, UserProfile userProfile) { try { var profile = await _userProfileRepository.GetByEmailAsync(email); if (profile == null) { var client = new RestSharp.Portable.HttpClient.RestClient( $"{_externalLoginConfigurationService.Auth0DbConnections}{_externalLoginConfigurationService.Auth0DbConnectionsSignUp}"); var request = new RestRequest(Method.POST); client.IgnoreResponseStatusCode = true; var root = new SignUpAuth0User(email, password, _externalLoginConfigurationService.Auth0ClientId, "Username-Password-Authentication" ); string json = JsonConvert.SerializeObject(root); request.AddHeader("Accept", "application/json"); request.AddHeader("content-type", "application/json"); request.AddJsonBody(root); var response = await client.Execute(request); if (response.IsSuccess) { var identityResponse = await this._identityService.RegisterAsync(userProfile); return(SignupResponseEnum.NeedEmailConfirmation); } else { var error = JsonConvert.DeserializeObject <ResponseError>(response.Content); if (error.Error == "invalid_user_password" || error.Error == "invalid_request") { return(SignupResponseEnum.EmailExist); } //if (error.Error == "unauthorized") // return SignupResponseEnum.NeedEmailConfirmation; } return(SignupResponseEnum.Registered | SignupResponseEnum.NeedEmailConfirmation); } else { return(SignupResponseEnum.EmailExist); } } catch (Exception ex) { await _loggerService.LogErrorAsync(ex); throw; } }
public async Task <LoginResponseEnum> LoguinAsync(string email, string password) { try { var client = new RestSharp.Portable.HttpClient.RestClient( $"{_externalLoginConfigurationService.Auth0DbConnections}{_externalLoginConfigurationService.Auth0DbConnectionsLogin}"); var request = new RestRequest(Method.POST); client.IgnoreResponseStatusCode = true; var root = new LoginAuth0User { UserName = email, Password = password, ClientId = _externalLoginConfigurationService.Auth0ClientId, Connection = "Username-Password-Authentication" }; string json = JsonConvert.SerializeObject(root); request.AddHeader("Accept", "application/json"); request.AddHeader("content-type", "application/json"); request.AddJsonBody(root); var response = await client.Execute(request); if (response.IsSuccess) { var identityResponse = await this._identityService.LoginByEmailAsync(email); return(LoginResponseEnum.Ok); } else { var error = JsonConvert.DeserializeObject <ResponseError>(response.Content); if (error.Error == "invalid_user_password" || error.Error == "invalid_request") { return(LoginResponseEnum.VerifyData); } if (error.Error == "unauthorized") { return(LoginResponseEnum.NeedEmailConfirmation); } } } catch (Exception e) { await _loggerService.LogErrorAsync(e); throw; } return(LoginResponseEnum.Error); }
private static async Task<Quote> GetQuoteRestSharp() { var uri = new Uri("https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies"); using (var client = new RestSharp.Portable.HttpClient.RestClient(uri)) { var request = new RestRequest(Method.POST); request.AddHeader("X-Mashape-Key", "SVRrKUoLRBmshZ7IANqnF4kmkxt7p1kYcMNjsnWxDGnoyCOUwh"); //request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddHeader("Accept", "application/json"); var response = await client.Execute<Quote>(request); var quote = await Task.Run(() => new JsonDeserializer().Deserialize<Quote>(response)); return quote; } }
public async Task SignupDummysync() { try { var clientJson = new RestSharp.Portable.HttpClient.RestClient( $"http://beta.json-generator.com/api/json/get/Nk1dgANsf"); var requestJson = new RestRequest(Method.GET); clientJson.IgnoreResponseStatusCode = true; var responseJson = await clientJson.Execute(requestJson); var responseParse = JsonConvert.DeserializeObject <List <UserProfile> >(responseJson.Content); foreach (var userProfile in responseParse) { var client = new RestSharp.Portable.HttpClient.RestClient( $"{_externalLoginConfigurationService.Auth0DbConnections}{_externalLoginConfigurationService.Auth0DbConnectionsSignUp}"); var request = new RestRequest(Method.POST); client.IgnoreResponseStatusCode = true; var root = new SignUpAuth0User(userProfile.Email, "Password", _externalLoginConfigurationService.Auth0ClientId, "Username-Password-Authentication" ); string json = JsonConvert.SerializeObject(root); request.AddHeader("Accept", "application/json"); request.AddHeader("content-type", "application/json"); request.AddJsonBody(root); var response = await client.Execute(request); if (response.IsSuccess) { var identityResponse = await this._identityService.RegisterAsync(userProfile); } } } catch (Exception ex) { await _loggerService.LogErrorAsync(ex); throw; } }
private async void button_Click(object sender, RoutedEventArgs e) { var client = new RestSharp.Portable.HttpClient.RestClient("http://localhost:3000/"); var request = new RestRequest("http://localhost:3000/api/v1/users/sign_up", Method.POST); client.IgnoreResponseStatusCode = true; request.AddBody(new { first_name = textBox.Text, last_name = textBox1.Text, profile_name = textBox2.Text, email = textBox3.Text, password = passwordBox.Password, password_confirmation = passwordBox1.Password }); var response = await client.Execute(request).ConfigureAwait(true); HttpStatusCode statusCode = response.StatusCode; int numericStatusCode = (int)statusCode; if (numericStatusCode == 200) { var dialog = new Windows.UI.Popups.MessageDialog("Zarejestrowano poprawnie, nastąpi przekierowanie do strony głównej"); dialog.Commands.Add(new Windows.UI.Popups.UICommand("Ok") { Id = 0 }); dialog.CancelCommandIndex = 0; var result = await dialog.ShowAsync(); var btn = sender as Button; btn.Content = $"Result: {result.Label} ({result.Id})"; Frame.Navigate(typeof(MainPage), null); } /* * if (numericStatusCode== <nr response, email already taken >){ * * var dialog = new Windows.UI.Popups.MessageDialog("email jest zajęty, podaj inny email lub zaloguj się"); * dialog.Commands.Add(new Windows.UI.Popups.UICommand("Ok") { Id = 0 }); * dialog.CancelCommandIndex = 0; * * var result = await dialog.ShowAsync(); * * var btn = sender as Button; * btn.Content = $"Result: {result.Label} ({result.Id})"; * } */ /* * if (numericStatusCode== <nr response, username already taken >){ * * var dialog = new Windows.UI.Popups.MessageDialog("username jest zajęty, podaj inny username"); * dialog.Commands.Add(new Windows.UI.Popups.UICommand("Ok") { Id = 0 }); * dialog.CancelCommandIndex = 0; * * var result = await dialog.ShowAsync(); * * var btn = sender as Button; * btn.Content = $"Result: {result.Label} ({result.Id})"; * } */ }