2024-07-03 15:58:51 +02:00
|
|
|
|
using bib_talk.Repository;
|
2024-08-28 12:01:03 +02:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
2024-07-03 15:58:51 +02:00
|
|
|
|
|
|
|
|
|
namespace bib_talk.Business
|
|
|
|
|
{
|
|
|
|
|
public class LoginManager
|
|
|
|
|
{
|
|
|
|
|
private LoginDatabase loginDatabase;
|
|
|
|
|
|
|
|
|
|
public LoginManager(Login loginWindow)
|
|
|
|
|
{
|
|
|
|
|
loginDatabase = new LoginDatabase(loginWindow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async void Login()
|
|
|
|
|
{
|
|
|
|
|
await loginDatabase.LoginServer();
|
|
|
|
|
}
|
2024-08-28 12:01:03 +02:00
|
|
|
|
|
|
|
|
|
public async Task LoginBots(string username, string password)
|
|
|
|
|
{
|
|
|
|
|
var loginData = new { Username = username, Password = password, Email = "", Birthday = "", IsOnline = "" };
|
|
|
|
|
string json = JsonConvert.SerializeObject(loginData);
|
|
|
|
|
|
|
|
|
|
using (var client = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
|
|
|
|
var response = await client.PostAsync("http://daddypig.dns.navy:5114/api/users/login", content);
|
|
|
|
|
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
var responseContent = await response.Content.ReadAsStringAsync();
|
|
|
|
|
var responseData = JsonConvert.DeserializeObject<dynamic>(responseContent);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var responseContent = await response.Content.ReadAsStringAsync();
|
|
|
|
|
MessageBox.Show($"Login failed: {responseContent}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-03 15:58:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|