diff --git a/Jugenddienst Stunden/Jugenddienst Stunden.csproj b/Jugenddienst Stunden/Jugenddienst Stunden.csproj index 5adcc5d..3a6c4c1 100644 --- a/Jugenddienst Stunden/Jugenddienst Stunden.csproj +++ b/Jugenddienst Stunden/Jugenddienst Stunden.csproj @@ -44,8 +44,8 @@ com.companyname.jugenddienststunden - 1.0.4 - 5 + 1.0.5 + 6 False True @@ -53,8 +53,8 @@ False com.companyname.jugenddienststunden - 1.0.4 - 5 + 1.0.5 + 6 True @@ -64,8 +64,8 @@ True False True - 1.0.4 - 5 + 1.0.5 + 6 False @@ -75,8 +75,8 @@ com.companyname.jugenddienststunden - 1.0.4 - 5 + 1.0.5 + 6 $(DefineConstants);DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION True @@ -87,8 +87,8 @@ False False True - 1.0.4 - 5 + 1.0.5 + 6 False False False @@ -96,8 +96,8 @@ com.companyname.jugenddienststunden - 1.0.4 - 5 + 1.0.5 + 6 False True @@ -162,12 +162,12 @@ - + true - - - + + + diff --git a/Jugenddienst Stunden/Models/Auth.cs b/Jugenddienst Stunden/Models/Auth.cs index c31d19f..696aa2e 100644 --- a/Jugenddienst Stunden/Models/Auth.cs +++ b/Jugenddienst Stunden/Models/Auth.cs @@ -1,8 +1,7 @@ -using System.Diagnostics; +using Jugenddienst_Stunden.Types; +using System.Diagnostics; using System.Text; -using Jugenddienst_Stunden.Types; using System.Text.Json; -using static System.Runtime.InteropServices.JavaScript.JSType; namespace Jugenddienst_Stunden.Models; @@ -94,5 +93,37 @@ class Auth { //} } + public static async Task AuthUserPass(string user, string pass, string url) { + + var values = new Dictionary + { + { "user", user }, + { "pass", pass } + }; + + var content = new FormUrlEncodedContent(values); + + using (HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }) { + + client.DefaultRequestHeaders.Add("Accept", "application/json"); + + // Senden der Anfrage und Abrufen der Antwort + using (HttpResponseMessage HttpResponseMessage = await client.PostAsync(url, content).ConfigureAwait(false)) { + // Überprüfen, ob die Anfrage erfolgreich war + if (HttpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK) { + using (HttpContent HttpContent = HttpResponseMessage.Content) { + // Lesen und Rückgabe der Antwort als String + + string responseData = await HttpContent.ReadAsStringAsync(); + User userData = System.Text.Json.JsonSerializer.Deserialize(responseData) ?? throw new Exception("Fehler beim Deserialisieren der Daten"); + return userData; + } + } + } + + } + return null; + } + } diff --git a/Jugenddienst Stunden/Types/User.cs b/Jugenddienst Stunden/Types/User.cs new file mode 100644 index 0000000..271e0fb --- /dev/null +++ b/Jugenddienst Stunden/Types/User.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Jugenddienst_Stunden.Types; +public class User { + public int id { get; set; } + public string name { get; set; } + public string surname { get; set; } + public string token { get; set; } +} diff --git a/Jugenddienst Stunden/Views/LoginPage.xaml b/Jugenddienst Stunden/Views/LoginPage.xaml index 3029e1f..66e60f9 100644 --- a/Jugenddienst Stunden/Views/LoginPage.xaml +++ b/Jugenddienst Stunden/Views/LoginPage.xaml @@ -5,27 +5,50 @@ xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI.Controls" x:Class="Jugenddienst_Stunden.Views.LoginPage" Title="{Binding Title}"> - + - - - - + + + + - + + + +