Barcodes speichern
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZXing.QrCode.Internal;
|
||||
|
||||
namespace Jugenddienst_Stunden.Models
|
||||
{
|
||||
@@ -14,6 +15,8 @@ namespace Jugenddienst_Stunden.Models
|
||||
public static async Task<string> GetApiDataWithAuthAsync(string url, string token) {
|
||||
using (HttpClient client = new HttpClient()) {
|
||||
try {
|
||||
client.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
|
||||
// Hinzufügen des Bearer-Tokens zum Authorization-Header
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Jugenddienst_Stunden.Models {
|
||||
public Dictionary<int,NominalWeek> nominal_week_api;
|
||||
//public List<string> time_line;
|
||||
public string zeit_total;
|
||||
public Dictionary<int,decimal> zeit_total_daily;
|
||||
public Dictionary<int,decimal>? zeit_total_daily;
|
||||
//public List<string> wochensumme;
|
||||
public string overtime_month;
|
||||
public string overtime;
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text;
|
||||
|
||||
namespace Jugenddienst_Stunden.Models {
|
||||
public class Operator {
|
||||
public class Operator : ObservableObject {
|
||||
public string id;
|
||||
public string name;
|
||||
public string surname;
|
||||
@@ -23,5 +27,29 @@ namespace Jugenddienst_Stunden.Models {
|
||||
public string year;
|
||||
//public List<int>? timetable;
|
||||
|
||||
|
||||
|
||||
|
||||
public static async Task<Operator> LoadData(string apiKey) {
|
||||
//var apiKey = Preferences.Default.Get("apiKey", "");
|
||||
Operator OperatorVar = new Operator();
|
||||
//Operator operator = new Operator();
|
||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
|
||||
await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
|
||||
"Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
|
||||
"OK");
|
||||
//throw new Exception("Keine Internetverbindung");
|
||||
} else {
|
||||
var tokendata = new TokenData(apiKey);
|
||||
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url, tokendata.apiKey);
|
||||
if (data != null) {
|
||||
OperatorVar = Newtonsoft.Json.JsonConvert.DeserializeObject<Operator>(data);
|
||||
Preferences.Default.Set("name", OperatorVar.name);
|
||||
Preferences.Default.Set("surname", OperatorVar.surname);
|
||||
}
|
||||
|
||||
}
|
||||
return OperatorVar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,35 +2,48 @@
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.Maui.Networking;
|
||||
using Microsoft.Maui.Controls;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace Jugenddienst_Stunden.Models {
|
||||
internal class Stunde : ObservableObject {
|
||||
|
||||
private static readonly string BaseAddress = "http://hours.dauni.mine.nu:81";
|
||||
//private static readonly string apiKey = "MTQzfEFlMVRjQXdZMnI4RmpxZ0FSY3A0VEN2bVZYVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk="; //Christine
|
||||
public static string apiKey = "MTU0fGpkQUNYTGkvcjMvVk4rNkMyK0dDQkJmMkFwVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk="; //Damian
|
||||
private static readonly string requestUrl = $"{BaseAddress}/appapi?hours";
|
||||
//Katharina
|
||||
public static string apiKey = Preferences.Default.Get("apiKey", "MTAyfEJZZnB1L3VwcnhoVms0dDlLZENPZWtUVy85b3xodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
|
||||
|
||||
//Damian
|
||||
//public static string apiKey = Preferences.Default.Get("apiKey", "MTU0fGpkQUNYTGkvcjMvVk4rNkMyK0dDQkJmMkFwVXxodHRwOi8vaG91cnMuZGF1bmkubWluZS5udTo4MS9hcHBhcGk=");
|
||||
|
||||
//private static readonly string requestUrl = $"{BaseAddress}/appapi?hours";
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
|
||||
|
||||
public static async Task<Hours> LoadData() {
|
||||
|
||||
public static async Task<Hours> LoadData() {
|
||||
|
||||
Hours hours = new Hours();
|
||||
|
||||
if (Connectivity.Current.NetworkAccess == NetworkAccess.None) {
|
||||
await App.Current.MainPage.DisplayAlert("Keine Internetverbindung",
|
||||
"Bitte überprüfen Sie Ihre Internetverbindung und versuchen Sie es erneut.",
|
||||
"OK");
|
||||
//throw new Exception("Keine Internetverbindung");
|
||||
} else {
|
||||
string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey);
|
||||
var tokendata = new TokenData(apiKey);
|
||||
|
||||
//string data = await Auth.GetApiDataWithAuthAsync(requestUrl, apiKey);
|
||||
string data = await Auth.GetApiDataWithAuthAsync(tokendata.url + "?hours", tokendata.apiKey);
|
||||
|
||||
if (data == null) {
|
||||
throw new Exception("Keine Daten erhalten");
|
||||
}
|
||||
|
||||
hours = JsonConvert.DeserializeObject<Hours>(data);
|
||||
//Preferences.Default.Set("name", hours.operator_api.name);
|
||||
//Preferences.Default.Set("surname", hours.operator_api.surname);
|
||||
|
||||
|
||||
}
|
||||
return hours;
|
||||
|
||||
23
Jugenddienst Stunden/Models/TokenData.cs
Normal file
23
Jugenddienst Stunden/Models/TokenData.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace Jugenddienst_Stunden.Models {
|
||||
class TokenData {
|
||||
public string token { get; set; }
|
||||
public string apiKey { get; set; }
|
||||
public string url { get; set; }
|
||||
public string operator_id { get; set; }
|
||||
|
||||
public TokenData(string apiKey) {
|
||||
string dat = Encoding.UTF8.GetString(System.Convert.FromBase64String(apiKey));
|
||||
this.token = dat.Split('|')[1]; ;
|
||||
this.url = dat.Split('|')[2]; ;
|
||||
this.operator_id = dat.Split('|')[0]; ;
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user