public async Task<JSONStatusResponse> ChangePasswordAsync(string newPassword, string newPasswortRepeated, string language = "en") { var parameters = new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_HASH"), ((_recoveryHash == null) ? "" : _recoveryHash)), new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_NEW_PWD"), ((newPassword == null) ? "" : newPassword)), new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_NEW_PWD_REPEAT"), ((newPasswortRepeated == null) ? "" : newPasswortRepeated)), new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_LANGUAGE"), ((language == null) ? "" : language)) }; HttpContent postParameters = new FormUrlEncodedContent(parameters); using (var httpClient = new HttpClient()) { //httpClient.BaseAddress = new Uri(ApplicationResourcesHelper.Get("POCEKTCODE_BASE_ADDRESS); httpClient.BaseAddress = new Uri("https://catroid-test.catrob.at"); JSONStatusResponse statusResponse = null; try { HttpResponseMessage httpResponse = await httpClient.PostAsync(ApplicationResourcesHelper.Get("CATROWEB_CHANGE_PWD"), postParameters); httpResponse.EnsureSuccessStatusCode(); string jsonResult = await httpResponse.Content.ReadAsStringAsync(); statusResponse = JsonConvert.DeserializeObject<JSONStatusResponse>(jsonResult); } catch (HttpRequestException) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.HTTPRequestFailed; } catch (Newtonsoft.Json.JsonSerializationException) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.JSONSerializationFailed; } catch (Exception) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.UnknownError; } return statusResponse; } }
public async Task<JSONStatusResponse> ReportAsInappropriateAsync(string programId, string flagReason, string language = "en") { var parameters = new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_PROJECTID"), ((programId == null) ? "" : programId)), new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_FLAG_REASON"), ((flagReason == null) ? "" : flagReason)), new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_LANGUAGE"), ((language == null) ? "" : language)) }; HttpContent postParameters = new FormUrlEncodedContent(parameters); using (var httpClient = new HttpClient()) { //httpClient.BaseAddress = new Uri(ApplicationResourcesHelper.Get("POCEKTCODE_BASE_ADDRESS); httpClient.BaseAddress = new Uri("https://catroid-test.catrob.at"); JSONStatusResponse statusResponse = null; try { HttpResponseMessage httpResponse = await httpClient.PostAsync(ApplicationResourcesHelper.Get("CATROWEB_REPORT_AS_INAPPROPRIATE"), postParameters); httpResponse.EnsureSuccessStatusCode(); string jsonResult = await httpResponse.Content.ReadAsStringAsync(); statusResponse = JsonConvert.DeserializeObject<JSONStatusResponse>(jsonResult); } catch (HttpRequestException) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.HTTPRequestFailed; } catch (Newtonsoft.Json.JsonSerializationException) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.JSONSerializationFailed; } catch (Exception) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.UnknownError; } return statusResponse; } }
public async Task<JSONStatusResponse> LoginOrRegisterAsync(string username, string password, string userEmail, string language = "en", string country = "AT") { var parameters = new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_REG_USERNAME"), ((username == null) ? "" : username)), new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_REG_PASSWORD"), ((password == null) ? "" : password)), new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_REG_EMAIL"), ((userEmail == null) ? "" : userEmail)), new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_REG_COUNTRY"), ((country == null) ? "" : country)), new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_LANGUAGE"), ((language == null) ? "" : language)) }; HttpContent postParameters = new FormUrlEncodedContent(parameters); using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri(ApplicationResourcesHelper.Get("API_BASE_ADDRESS")); JSONStatusResponse statusResponse = null; try { HttpResponseMessage httpResponse = await httpClient.PostAsync(ApplicationResourcesHelper.Get("API_LOGIN_REGISTER"), postParameters); httpResponse.EnsureSuccessStatusCode(); string jsonResult = await httpResponse.Content.ReadAsStringAsync(); statusResponse = JsonConvert.DeserializeObject<JSONStatusResponse>(jsonResult); } catch (HttpRequestException) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.HTTPRequestFailed; } catch (Newtonsoft.Json.JsonSerializationException) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.JSONSerializationFailed; } catch (Exception) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.UnknownError; } return statusResponse; } }
public async Task<JSONStatusResponse> UploadProgramAsync(string programTitle, string username, string token, CancellationToken taskCancellationToken, string language = "en") { var parameters = new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_USERNAME"), ((username == null) ? "" : username)), new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_TOKEN"), ((token == null) ? "" : token)), new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_LANGUAGE"), ((language == null) ? "" : language)) }; using (var postParameters = new MultipartFormDataContent()) { using (var storage = StorageSystem.GetStorage()) { JSONStatusResponse statusResponse = null; try { _uploadCounter++; byte[] programData; using (var stream = await storage.OpenFileAsync(Path.Combine(StorageConstants.TempProgramExportZipPath, programTitle + ApplicationResourcesHelper.Get("EXTENSION")), StorageFileMode.Open, StorageFileAccess.Read)) { var memoryStream = new MemoryStream(); await stream.CopyToAsync(memoryStream); programData = memoryStream.ToArray(); } parameters.Add(new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_CHECKSUM"), UtilTokenHelper.ToHex(MD5Core.GetHash(programData)))); // store parameters as MultipartFormDataContent StringContent content = null; foreach (var keyValuePair in parameters) { content = new StringContent(keyValuePair.Value); content.Headers.Remove("Content-Type"); postParameters.Add(content, String.Format("\"{0}\"", keyValuePair.Key)); } ByteArrayContent fileContent = new ByteArrayContent(programData); fileContent.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/zip"); postParameters.Add(fileContent, String.Format("\"{0}\"", ApplicationResourcesHelper.Get("API_PARAM_UPLOAD")), String.Format("\"{0}\"", programTitle + ApplicationResourcesHelper.Get("EXTENSION"))); using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri(ApplicationResourcesHelper.Get("API_BASE_ADDRESS")); HttpResponseMessage httpResponse = await httpClient.PostAsync(ApplicationResourcesHelper.Get("API_UPLOAD"), postParameters, taskCancellationToken); httpResponse.EnsureSuccessStatusCode(); string jsonResult = await httpResponse.Content.ReadAsStringAsync(); statusResponse = JsonConvert.DeserializeObject<JSONStatusResponse>(jsonResult); } } catch (HttpRequestException) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.HTTPRequestFailed; } catch (Newtonsoft.Json.JsonSerializationException) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.JSONSerializationFailed; } catch (Exception) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.UnknownError; } finally { _uploadCounter--; } return statusResponse; } } }
public async Task<JSONStatusResponse> CheckTokenAsync(string username, string token, string language = "en") { var parameters = new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_USERNAME"), ((username == null) ? "" : username)), new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_TOKEN"), ((token == null) ? "" : token)), new KeyValuePair<string, string>(ApplicationResourcesHelper.Get("API_PARAM_LANGUAGE"), ((language == null) ? "" : language)) }; HttpContent postParameters = new FormUrlEncodedContent(parameters); using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri(ApplicationResourcesHelper.Get("API_BASE_ADDRESS")); JSONStatusResponse statusResponse = null; try { HttpResponseMessage httpResponse = await httpClient.PostAsync(ApplicationResourcesHelper.Get("API_CHECK_TOKEN"), postParameters); httpResponse.EnsureSuccessStatusCode(); string jsonResult = await httpResponse.Content.ReadAsStringAsync(); statusResponse = JsonConvert.DeserializeObject<JSONStatusResponse>(jsonResult); } catch (HttpRequestException) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.HTTPRequestFailed; } catch (Newtonsoft.Json.JsonSerializationException) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.JSONSerializationFailed; } catch (Exception) { statusResponse = new JSONStatusResponse(); statusResponse.statusCode = StatusCodes.UnknownError; } return statusResponse; } }