3 Schichten Model
3 Schichten Model umgesetzt
This commit is contained in:
51
bibtalk/bib-talk/Repository/LoginDatabase.cs
Normal file
51
bibtalk/bib-talk/Repository/LoginDatabase.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows;
|
||||
|
||||
namespace bib_talk.Repository
|
||||
{
|
||||
public class LoginDatabase
|
||||
{
|
||||
Login loginWindow;
|
||||
|
||||
public LoginDatabase(Login loginWindow)
|
||||
{
|
||||
this.loginWindow = loginWindow;
|
||||
}
|
||||
|
||||
public async Task LoginServer()
|
||||
{
|
||||
string username = loginWindow.usernbox.Text;
|
||||
string password = loginWindow.passwordbox.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);
|
||||
string loggedInUsername = responseData.username;
|
||||
MainWindow mainWindow = new MainWindow(loggedInUsername);
|
||||
mainWindow.Show();
|
||||
loginWindow.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
MessageBox.Show($"Login failed: {responseContent}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user