1.0.5 Manueller Login
This commit is contained in:
@@ -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<User> AuthUserPass(string user, string pass, string url) {
|
||||
|
||||
var values = new Dictionary<string, string>
|
||||
{
|
||||
{ "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<User>(responseData) ?? throw new Exception("Fehler beim Deserialisieren der Daten");
|
||||
return userData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user