1.0.5 Manueller Login
This commit is contained in:
@@ -44,8 +44,8 @@
|
|||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-maccatalyst|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-maccatalyst|AnyCPU'">
|
||||||
<ApplicationId>com.companyname.jugenddienststunden</ApplicationId>
|
<ApplicationId>com.companyname.jugenddienststunden</ApplicationId>
|
||||||
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
|
<ApplicationDisplayVersion>1.0.5</ApplicationDisplayVersion>
|
||||||
<ApplicationVersion>5</ApplicationVersion>
|
<ApplicationVersion>6</ApplicationVersion>
|
||||||
<Optimize>False</Optimize>
|
<Optimize>False</Optimize>
|
||||||
<Deterministic>True</Deterministic>
|
<Deterministic>True</Deterministic>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -53,8 +53,8 @@
|
|||||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-maccatalyst|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-maccatalyst|AnyCPU'">
|
||||||
<Optimize>False</Optimize>
|
<Optimize>False</Optimize>
|
||||||
<ApplicationId>com.companyname.jugenddienststunden</ApplicationId>
|
<ApplicationId>com.companyname.jugenddienststunden</ApplicationId>
|
||||||
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
|
<ApplicationDisplayVersion>1.0.5</ApplicationDisplayVersion>
|
||||||
<ApplicationVersion>5</ApplicationVersion>
|
<ApplicationVersion>6</ApplicationVersion>
|
||||||
<Deterministic>True</Deterministic>
|
<Deterministic>True</Deterministic>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@@ -64,8 +64,8 @@
|
|||||||
<DebugSymbols>True</DebugSymbols>
|
<DebugSymbols>True</DebugSymbols>
|
||||||
<Optimize>False</Optimize>
|
<Optimize>False</Optimize>
|
||||||
<Deterministic>True</Deterministic>
|
<Deterministic>True</Deterministic>
|
||||||
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
|
<ApplicationDisplayVersion>1.0.5</ApplicationDisplayVersion>
|
||||||
<ApplicationVersion>5</ApplicationVersion>
|
<ApplicationVersion>6</ApplicationVersion>
|
||||||
<AndroidKeyStore>False</AndroidKeyStore>
|
<AndroidKeyStore>False</AndroidKeyStore>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@@ -75,8 +75,8 @@
|
|||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-windows10.0.26100.0|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-windows10.0.26100.0|AnyCPU'">
|
||||||
<ApplicationId>com.companyname.jugenddienststunden</ApplicationId>
|
<ApplicationId>com.companyname.jugenddienststunden</ApplicationId>
|
||||||
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
|
<ApplicationDisplayVersion>1.0.5</ApplicationDisplayVersion>
|
||||||
<ApplicationVersion>5</ApplicationVersion>
|
<ApplicationVersion>6</ApplicationVersion>
|
||||||
<DefineConstants>$(DefineConstants);DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION</DefineConstants>
|
<DefineConstants>$(DefineConstants);DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION</DefineConstants>
|
||||||
<Deterministic>True</Deterministic>
|
<Deterministic>True</Deterministic>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -87,8 +87,8 @@
|
|||||||
<DebugSymbols>False</DebugSymbols>
|
<DebugSymbols>False</DebugSymbols>
|
||||||
<Optimize>False</Optimize>
|
<Optimize>False</Optimize>
|
||||||
<Deterministic>True</Deterministic>
|
<Deterministic>True</Deterministic>
|
||||||
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
|
<ApplicationDisplayVersion>1.0.5</ApplicationDisplayVersion>
|
||||||
<ApplicationVersion>5</ApplicationVersion>
|
<ApplicationVersion>6</ApplicationVersion>
|
||||||
<RunAOTCompilation>False</RunAOTCompilation>
|
<RunAOTCompilation>False</RunAOTCompilation>
|
||||||
<PublishTrimmed>False</PublishTrimmed>
|
<PublishTrimmed>False</PublishTrimmed>
|
||||||
<AndroidKeyStore>False</AndroidKeyStore>
|
<AndroidKeyStore>False</AndroidKeyStore>
|
||||||
@@ -96,8 +96,8 @@
|
|||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-windows10.0.26100.0|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-windows10.0.26100.0|AnyCPU'">
|
||||||
<ApplicationId>com.companyname.jugenddienststunden</ApplicationId>
|
<ApplicationId>com.companyname.jugenddienststunden</ApplicationId>
|
||||||
<ApplicationDisplayVersion>1.0.4</ApplicationDisplayVersion>
|
<ApplicationDisplayVersion>1.0.5</ApplicationDisplayVersion>
|
||||||
<ApplicationVersion>5</ApplicationVersion>
|
<ApplicationVersion>6</ApplicationVersion>
|
||||||
<Optimize>False</Optimize>
|
<Optimize>False</Optimize>
|
||||||
<Deterministic>True</Deterministic>
|
<Deterministic>True</Deterministic>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -162,12 +162,12 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
|
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
|
||||||
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.80">
|
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.91">
|
||||||
<TreatAsUsed>true</TreatAsUsed>
|
<TreatAsUsed>true</TreatAsUsed>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.80" />
|
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.91" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
|
||||||
<PackageReference Include="Microsoft.Maui.Graphics" Version="8.0.80" />
|
<PackageReference Include="Microsoft.Maui.Graphics" Version="8.0.91" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="ZXing.Net.Maui.Controls" Version="0.4.0" />
|
<PackageReference Include="ZXing.Net.Maui.Controls" Version="0.4.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
using System.Diagnostics;
|
using Jugenddienst_Stunden.Types;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Jugenddienst_Stunden.Types;
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Models;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
13
Jugenddienst Stunden/Types/User.cs
Normal file
13
Jugenddienst Stunden/Types/User.cs
Normal file
@@ -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; }
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
<ContentPage.BindingContext>
|
<ContentPage.BindingContext>
|
||||||
<models:LoginViewModel />
|
<models:LoginViewModel />
|
||||||
</ContentPage.BindingContext>
|
</ContentPage.BindingContext>
|
||||||
|
<ScrollView>
|
||||||
<VerticalStackLayout Spacing="10" Margin="15">
|
<VerticalStackLayout Spacing="10" Margin="15">
|
||||||
<HorizontalStackLayout Spacing="10">
|
<HorizontalStackLayout Spacing="10">
|
||||||
<Label FontSize="22" FontAttributes="Bold" Text="{Binding AppTitle}" VerticalOptions="End" />
|
<Label FontSize="22" FontAttributes="Bold" Text="{Binding AppTitle}" VerticalOptions="End" />
|
||||||
@@ -18,14 +18,37 @@
|
|||||||
|
|
||||||
|
|
||||||
<Label Text="{Binding Message}" HeightRequest="40" />
|
<Label Text="{Binding Message}" HeightRequest="40" />
|
||||||
<Label x:Name="ServerLabel" Text="{Binding Server}" HeightRequest="40" Margin="0,0,0,40" />
|
<Label x:Name="ServerLabel" Text="{Binding Server}" HeightRequest="25" Margin="0,0,0,10" />
|
||||||
|
|
||||||
|
<Frame HeightRequest="300" Padding="0" CornerRadius="0">
|
||||||
<zxing:CameraBarcodeReaderView x:Name="barcodeScannerView"
|
<zxing:CameraBarcodeReaderView x:Name="barcodeScannerView"
|
||||||
BarcodesDetected="BarcodesDetected"
|
BarcodesDetected="BarcodesDetected"
|
||||||
HorizontalOptions="FillAndExpand"
|
HorizontalOptions="FillAndExpand"
|
||||||
VerticalOptions="FillAndExpand"/>
|
VerticalOptions="FillAndExpand"/>
|
||||||
</VerticalStackLayout>
|
</Frame>
|
||||||
|
|
||||||
|
<VerticalStackLayout Padding="30" Spacing="15">
|
||||||
|
<Label Text="Manueller Login"
|
||||||
|
FontSize="32"
|
||||||
|
HorizontalOptions="Start" />
|
||||||
|
|
||||||
|
<Entry x:Name="UsernameEntry"
|
||||||
|
Placeholder="Benutzername"
|
||||||
|
Keyboard="Email" />
|
||||||
|
|
||||||
|
<Entry x:Name="PasswordEntry"
|
||||||
|
Placeholder="Passwort"
|
||||||
|
IsPassword="True" />
|
||||||
|
|
||||||
|
<Entry x:Name="ServerEntry"
|
||||||
|
Placeholder="Server"
|
||||||
|
Keyboard="Url" />
|
||||||
|
|
||||||
|
<Button Text="Login" Clicked="OnLoginButtonClicked" />
|
||||||
|
|
||||||
|
</VerticalStackLayout>
|
||||||
|
</VerticalStackLayout>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
|
||||||
</ContentPage>
|
</ContentPage>
|
||||||
@@ -4,6 +4,11 @@ using Jugenddienst_Stunden.ViewModels;
|
|||||||
using Microsoft.Maui.Controls;
|
using Microsoft.Maui.Controls;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using ZXing.Net.Maui;
|
using ZXing.Net.Maui;
|
||||||
|
using Microsoft.Maui.Devices;
|
||||||
|
using static Microsoft.Maui.ApplicationModel.Permissions;
|
||||||
|
using ZXing.Net.Maui.Controls;
|
||||||
|
using ZXing.QrCode.Internal;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Jugenddienst_Stunden.Views;
|
namespace Jugenddienst_Stunden.Views;
|
||||||
|
|
||||||
@@ -14,6 +19,7 @@ public partial class LoginPage : ContentPage {
|
|||||||
|
|
||||||
private DateTime _lastDetectionTime;
|
private DateTime _lastDetectionTime;
|
||||||
private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(5);
|
private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(5);
|
||||||
|
private bool hasCamera = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CTOR
|
/// CTOR
|
||||||
@@ -27,15 +33,18 @@ public partial class LoginPage : ContentPage {
|
|||||||
// vm.MsgEvent += Vm_MsgEvent;
|
// vm.MsgEvent += Vm_MsgEvent;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
barcodeScannerView.Options = new ZXing.Net.Maui.BarcodeReaderOptions {
|
barcodeScannerView.Options = new BarcodeReaderOptions {
|
||||||
Formats = ZXing.Net.Maui.BarcodeFormat.QrCode,
|
Formats = BarcodeFormat.QrCode,
|
||||||
AutoRotate = true,
|
AutoRotate = true,
|
||||||
Multiple = false
|
Multiple = false
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void BarcodesDetected(object sender, ZXing.Net.Maui.BarcodeDetectionEventArgs e) {
|
|
||||||
|
private void BarcodesDetected(object sender, BarcodeDetectionEventArgs e) {
|
||||||
|
|
||||||
var currentTime = DateTime.Now;
|
var currentTime = DateTime.Now;
|
||||||
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
|
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
|
||||||
_lastDetectionTime = currentTime;
|
_lastDetectionTime = currentTime;
|
||||||
@@ -81,6 +90,7 @@ public partial class LoginPage : ContentPage {
|
|||||||
|
|
||||||
protected override void OnDisappearing() {
|
protected override void OnDisappearing() {
|
||||||
base.OnDisappearing();
|
base.OnDisappearing();
|
||||||
|
|
||||||
barcodeScannerView.CameraLocation = CameraLocation.Front;
|
barcodeScannerView.CameraLocation = CameraLocation.Front;
|
||||||
barcodeScannerView.IsDetecting = false;
|
barcodeScannerView.IsDetecting = false;
|
||||||
|
|
||||||
@@ -91,6 +101,49 @@ public partial class LoginPage : ContentPage {
|
|||||||
|
|
||||||
barcodeScannerView.IsDetecting = true;
|
barcodeScannerView.IsDetecting = true;
|
||||||
barcodeScannerView.CameraLocation = CameraLocation.Rear;
|
barcodeScannerView.CameraLocation = CameraLocation.Rear;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsCameraAvailable() {
|
||||||
|
var status = Permissions.CheckStatusAsync<Permissions.Camera>().Result;
|
||||||
|
if (status != PermissionStatus.Granted) {
|
||||||
|
status = Permissions.RequestAsync<Permissions.Camera>().Result;
|
||||||
|
}
|
||||||
|
return status != PermissionStatus.Granted;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnLoginButtonClicked(object sender, EventArgs e) {
|
||||||
|
var username = UsernameEntry.Text;
|
||||||
|
var password = PasswordEntry.Text;
|
||||||
|
var server = ServerEntry.Text;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(server)) {
|
||||||
|
await DisplayAlert("Fehler", "Bitte alle Felder ausf<73>llen", "OK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Types.User response = await Auth.AuthUserPass(username, password, server);
|
||||||
|
|
||||||
|
var tokendata = new TokenData(response.token);
|
||||||
|
var op = await Models.Operator.LoadData(response.token);
|
||||||
|
Models.Stunde.apiKey = response.token;
|
||||||
|
Models.Stunde.name = op.name;
|
||||||
|
Models.Stunde.surname = op.surname;
|
||||||
|
Models.Stunde.EmployeeId = int.Parse(op.id);
|
||||||
|
Title = op.name + " " + op.surname;
|
||||||
|
ServerLabel.Text = "Server: " + tokendata.url.Replace("/appapi", "").Replace("https://", "").Replace("http://", "");
|
||||||
|
|
||||||
|
Preferences.Default.Set("apiKey", response.token);
|
||||||
|
Preferences.Default.Set("name", op.name);
|
||||||
|
Preferences.Default.Set("surname", op.surname);
|
||||||
|
Preferences.Default.Set("EmployeeId", int.Parse(op.id));
|
||||||
|
|
||||||
|
await DisplayAlert("Login erfolgreich", op.name + " " + op.surname, "OK");
|
||||||
|
if (Navigation.NavigationStack.Count > 1)
|
||||||
|
await Navigation.PopAsync();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
await DisplayAlert("Fehler", ex.Message, "OK");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//private void Vm_AlertEvent(object? sender, string e) {
|
//private void Vm_AlertEvent(object? sender, string e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user