1.0.5 Manueller Login
This commit is contained in:
@@ -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}">
|
||||
|
||||
|
||||
<ContentPage.BindingContext>
|
||||
<models:LoginViewModel />
|
||||
</ContentPage.BindingContext>
|
||||
|
||||
<VerticalStackLayout Spacing="10" Margin="15">
|
||||
<HorizontalStackLayout Spacing="10">
|
||||
<Label FontSize="22" FontAttributes="Bold" Text="{Binding AppTitle}" VerticalOptions="End" />
|
||||
<Label FontSize="22" Text="{Binding Version}" VerticalOptions="End" />
|
||||
</HorizontalStackLayout>
|
||||
<ScrollView>
|
||||
<VerticalStackLayout Spacing="10" Margin="15">
|
||||
<HorizontalStackLayout Spacing="10">
|
||||
<Label FontSize="22" FontAttributes="Bold" Text="{Binding AppTitle}" VerticalOptions="End" />
|
||||
<Label FontSize="22" Text="{Binding Version}" VerticalOptions="End" />
|
||||
</HorizontalStackLayout>
|
||||
|
||||
|
||||
<Label Text="{Binding Message}" HeightRequest="40" />
|
||||
<Label x:Name="ServerLabel" Text="{Binding Server}" HeightRequest="40" Margin="0,0,0,40" />
|
||||
<Label Text="{Binding Message}" HeightRequest="40" />
|
||||
<Label x:Name="ServerLabel" Text="{Binding Server}" HeightRequest="25" Margin="0,0,0,10" />
|
||||
|
||||
<zxing:CameraBarcodeReaderView x:Name="barcodeScannerView"
|
||||
<Frame HeightRequest="300" Padding="0" CornerRadius="0">
|
||||
<zxing:CameraBarcodeReaderView x:Name="barcodeScannerView"
|
||||
BarcodesDetected="BarcodesDetected"
|
||||
HorizontalOptions="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>
|
||||
@@ -4,6 +4,11 @@ using Jugenddienst_Stunden.ViewModels;
|
||||
using Microsoft.Maui.Controls;
|
||||
using System.Collections.Generic;
|
||||
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;
|
||||
|
||||
@@ -14,6 +19,7 @@ public partial class LoginPage : ContentPage {
|
||||
|
||||
private DateTime _lastDetectionTime;
|
||||
private readonly TimeSpan _detectionInterval = TimeSpan.FromSeconds(5);
|
||||
private bool hasCamera = false;
|
||||
|
||||
/// <summary>
|
||||
/// CTOR
|
||||
@@ -27,15 +33,18 @@ public partial class LoginPage : ContentPage {
|
||||
// vm.MsgEvent += Vm_MsgEvent;
|
||||
//}
|
||||
|
||||
barcodeScannerView.Options = new ZXing.Net.Maui.BarcodeReaderOptions {
|
||||
Formats = ZXing.Net.Maui.BarcodeFormat.QrCode,
|
||||
barcodeScannerView.Options = new BarcodeReaderOptions {
|
||||
Formats = BarcodeFormat.QrCode,
|
||||
AutoRotate = true,
|
||||
Multiple = false
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void BarcodesDetected(object sender, ZXing.Net.Maui.BarcodeDetectionEventArgs e) {
|
||||
|
||||
private void BarcodesDetected(object sender, BarcodeDetectionEventArgs e) {
|
||||
|
||||
var currentTime = DateTime.Now;
|
||||
if ((currentTime - _lastDetectionTime) > _detectionInterval) {
|
||||
_lastDetectionTime = currentTime;
|
||||
@@ -81,6 +90,7 @@ public partial class LoginPage : ContentPage {
|
||||
|
||||
protected override void OnDisappearing() {
|
||||
base.OnDisappearing();
|
||||
|
||||
barcodeScannerView.CameraLocation = CameraLocation.Front;
|
||||
barcodeScannerView.IsDetecting = false;
|
||||
|
||||
@@ -91,6 +101,49 @@ public partial class LoginPage : ContentPage {
|
||||
|
||||
barcodeScannerView.IsDetecting = true;
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user