Skip to content

Commit

Permalink
Added partner slider
Browse files Browse the repository at this point in the history
  • Loading branch information
Firewolf1337 committed May 27, 2024
1 parent 9825359 commit 0745caf
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 92 deletions.
80 changes: 58 additions & 22 deletions RCRPlanner/FetchData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class FetchData

//string iracingSeriesImages = "https://images-static.iracing.com/img/logos/series/";

readonly string partnerLink = "https://api.npoint.io/6cef9bfd30441a01c8c9";

private CookieContainer cookie = new CookieContainer();
public HttpClientHandler handler = new HttpClientHandler();
public static HttpClient client = new HttpClient();
Expand All @@ -63,9 +65,15 @@ public async Task<int> Login_API(byte[] Email, byte[] Password, bool forcelogin)
{
HttpResponseMessage response;

List<Cookie> cookies = new List<Cookie>();
foreach (Cookie cookie in cookie.GetCookies(new Uri("https://iracing.com")))
{
if (cookie.Name == "authtoken_members" && cookie.Expires > DateTime.Now.AddMinutes(10) && forcelogin == false)
cookies.Add(cookie);
}
int theCookie = cookies.FindIndex(c => c.Name == "authtoken_members");
if (theCookie != -1)
{
if (cookies[theCookie].Expires > (DateTime.Now.AddMinutes(10)) && forcelogin == false)
{
try
{
Expand All @@ -82,34 +90,37 @@ public async Task<int> Login_API(byte[] Email, byte[] Password, bool forcelogin)
}
}
}
if (handler.CookieContainer.Count == 0 || forcelogin)
else
{
try
{
handler = new HttpClientHandler
// if (handler.CookieContainer.Count == 0 || forcelogin)
// {
try
{
CookieContainer = cookie
};
client = new HttpClient(handler);
string loginHash = EncryptPW(Email, Password);
string postBody = "{\"email\": \"" + Encoding.Default.GetString(Email) + "\",\"password\": \"" + loginHash + "\"}";
var content = new StringContent(postBody, Encoding.UTF8, "application/json");

response = await client.PostAsync(iracingAuthUrl, content);
response = await client.GetAsync(iracingDataDoc);
return Convert.ToInt32(response.StatusCode);
}
catch (Exception ex)
{
if (ex.InnerException != null)
handler = new HttpClientHandler
{
CookieContainer = cookie
};
client = new HttpClient(handler);
string loginHash = EncryptPW(Email, Password);
string postBody = "{\"email\": \"" + Encoding.Default.GetString(Email) + "\",\"password\": \"" + loginHash + "\"}";
var content = new StringContent(postBody, Encoding.UTF8, "application/json");

response = await client.PostAsync(iracingAuthUrl, content);
response = await client.GetAsync(iracingDataDoc);
return Convert.ToInt32(response.StatusCode);
}
catch (Exception ex)
{
MessageBox.Show("Connection:" + ex.InnerException.Message, "Something went wrong.", MessageBoxButton.OK, MessageBoxImage.Error);
if (ex.InnerException != null)
{
MessageBox.Show("Connection:" + ex.InnerException.Message, "Something went wrong.", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
// }
return 0;

}

public async Task<string> getLink(string url)
{
var response = await client.GetAsync(url);
Expand Down Expand Up @@ -470,5 +481,30 @@ public bool EnsureVersionCompatibility()
var responseObject = Newtonsoft.Json.JsonConvert.DeserializeObject<githubLatestRelease.Root>(contents, settings);
return responseObject;
}

public async Task<List<partner>> getPartner()
{
var response = await client.GetAsync(partnerLink);

response.EnsureSuccessStatusCode();
var contents = await response.Content.ReadAsStringAsync();
var responseObject = new List<partner>();
try
{
responseObject = Newtonsoft.Json.JsonConvert.DeserializeObject<List<partner>>(contents, settings);
}
catch (Exception ex)
{
if (ex.InnerException != null)
{
MessageBox.Show("Partner download:" + ex.InnerException.Message, "Something went wrong.", MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
MessageBox.Show("Partner download:" + ex.Message, "Something went wrong.", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
return responseObject;
}
}
}
Loading

0 comments on commit 0745caf

Please sign in to comment.