NFC azonosítás is beállítva

This commit is contained in:
2025-04-06 14:41:36 +02:00
parent 71a5850d65
commit dc3e6e2f7b
8 changed files with 157 additions and 17 deletions
@@ -3,12 +3,29 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WorkFlowCheck.MAUI.Pages.NFC.NFCWaiter"
Title="Várakozás NFC olvasásra"
BackgroundColor="Black">
<VerticalStackLayout Padding="20" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="Tartsa a készülékhez az NFC tag-et..."
TextColor="White"
BackgroundColor="#f0f0f0">
<Frame BackgroundColor="White"
BorderColor="#cccccc"
CornerRadius="20"
Padding="30"
HasShadow="True"
HorizontalOptions="Center"
VerticalOptions="Center"
WidthRequest="{OnPlatform Android=450, iOS=350, WinUI=400, MacCatalyst=400}"
MaximumWidthRequest="500">
<VerticalStackLayout Spacing="20" Padding="20" HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="Tartsa a készülékhez az NFC tag-et..."
TextColor="Black"
FontSize="20"
HorizontalOptions="Center" />
<ActivityIndicator IsRunning="True" Color="White" />
</VerticalStackLayout>
<ActivityIndicator IsRunning="True" />
<Button x:Name="CancelButton"
Text="Mégse"
FontSize="18"
TextColor="White"
HorizontalOptions="Center"
Clicked="OnCancelButtonClicked" />
</VerticalStackLayout>
</Frame>
</ContentPage>
@@ -56,7 +56,7 @@ public partial class NFCWaiter : ContentPage
Finish(tagId);
}
private async void Finish(string tagId)
private async Task Finish(string tagId)
{
#if ANDROID
if (Platform.CurrentActivity is Android.App.Activity activity && activity is MainActivity mainActivity)
@@ -79,8 +79,12 @@ public partial class NFCWaiter : ContentPage
}
private async void OnCancelButtonClicked(object sender, EventArgs e)
{
await Finish("");
}
@@ -48,15 +48,27 @@
BackgroundColor="#f9f9f9"
HeightRequest="50"
Margin="0" />
<HorizontalStackLayout Spacing="20" HorizontalOptions="Center">
<RadioButton x:Name="ProdOption" Content="PROD" GroupName="Environment" />
<RadioButton x:Name="UatOption" Content="UAT" GroupName="Environment" />
</HorizontalStackLayout>
<Button x:Name="LoginBtn"
Text="Bejelentkezés"
FontSize="18"
HeightRequest="50"
CornerRadius="10"
BackgroundColor="#007aff"
TextColor="White"
Clicked="OnLoginClicked" />
<Button x:Name="LoginNFCBtn"
Text="NFC azonosítás"
FontSize="18"
HeightRequest="50"
CornerRadius="10"
TextColor="White"
Clicked="OnLoginNFCClicked" />
<ActivityIndicator x:Name="LoadingIndicator"
IsRunning="False"
@@ -1,6 +1,7 @@
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Core;
using System.Drawing;
using WorkFlowCheck.MAUI.Pages.NFC;
using WorkFlowCheck.MAUI.Services.Interfaces;
namespace WorkFlowCheck.MAUI.Pages.Security;
@@ -29,7 +30,7 @@ public partial class LoginPage : ContentPage
if (response != null && response.IsSuccess)
{
_userService.SetCurrentUser(response.Data);
//await _syncService.SyncDatas();
var wFCUser = Newtonsoft.Json.JsonConvert.SerializeObject(response.Data);
@@ -40,14 +41,14 @@ public partial class LoginPage : ContentPage
}
else
{
var visualOptions = new SnackbarOptions
{
ActionButtonTextColor = Colors.Yellow,
CornerRadius = new CornerRadius(10),
Font = Microsoft.Maui.Font.SystemFontOfSize(16),
BackgroundColor = Microsoft.Maui.Graphics.Color.Parse("Red"),
TextColor=Colors.Yellow
TextColor = Colors.Yellow
};
var snackbar = Snackbar.Make(
@@ -77,4 +78,71 @@ public partial class LoginPage : ContentPage
}
}
private async void OnLoginNFCClicked(object sender, EventArgs e)
{
LoadingIndicator.IsRunning = true;
LoadingIndicator.IsVisible = true;
LoginBtn.IsEnabled = false;
LoginNFCBtn.IsEnabled = false;
UsernameEntry.IsEnabled = false;
PasswordEntry.IsEnabled = false;
try
{
var nFCCode = await NFCWaiter.ShowModalAsync();
if (!string.IsNullOrEmpty(nFCCode))
{
var response = await _userService.AuthenticateNFC(nFCCode);
if (response != null && response.IsSuccess)
{
_userService.SetCurrentUser(response.Data);
//await _syncService.SyncDatas();
var wFCUser = Newtonsoft.Json.JsonConvert.SerializeObject(response.Data);
await SecureStorage.Default.SetAsync("WFCUser", "wFCUser");
await SecureStorage.Default.SetAsync("AuthToken", response.Data.JwtToken);
await Shell.Current.GoToAsync("//SyncPage");
}
else
{
var visualOptions = new SnackbarOptions
{
ActionButtonTextColor = Colors.Yellow,
CornerRadius = new CornerRadius(10),
Font = Microsoft.Maui.Font.SystemFontOfSize(16),
BackgroundColor = Microsoft.Maui.Graphics.Color.Parse("Red"),
TextColor = Colors.Yellow
};
var snackbar = Snackbar.Make(
"Invalid login credentials.",
duration: TimeSpan.FromSeconds(10),
action: () => Console.WriteLine("Snackbar dismissed"),
actionButtonText: "OK",
visualOptions: visualOptions
);
await snackbar.Show();
}
}
}
catch (Exception)
{
throw;
}
finally
{
LoginBtn.IsEnabled = true;
LoadingIndicator.IsRunning = false;
LoadingIndicator.IsVisible = false;
UsernameEntry.IsEnabled = true;
PasswordEntry.IsEnabled = true;
LoginNFCBtn.IsEnabled = true;
}
}
}
@@ -35,7 +35,7 @@ public partial class UsersPage : ContentPage
{
IsRefreshing = true;
//await _syncService.SyncDatas();
UsersList.ItemsSource = await _userService.GetAllUsers();
//UsersList.ItemsSource = await _userService.GetAllUserAsync().Result.Data;
IsRefreshing = false;
OnPropertyChanged(nameof(IsRefreshing));
}
@@ -51,8 +51,8 @@ public partial class UsersPage : ContentPage
}
if (UserDTO != null)
{
UserDTO.Code = UserCode;
await _baseStockService.UpdateUser(UserDTO);
//UserDTO.Code = UserCode;
//await _baseStockService.UpdateUser(UserDTO);
await LoadUsers();
}
}
@@ -13,6 +13,7 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces
Task<ApiResponseDTO<UserDTO>> GetUserAsync(int id);
Task<ApiResponseDTO<List<UserDTO>>> GetAllUserAsync();
Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password);
Task<ApiResponseDTO<UserDTO>> AuthenticateNFC(string NFCCode);
Task<ApiResponseDTO<string>> SyncUsers_Up(Action<double, string> reportProgress);
void SetCurrentUser(UserDTO user);
}
+39 -1
View File
@@ -109,6 +109,44 @@ namespace WorkFlowCheck.MAUI.Services
};
}
}
public async Task<ApiResponseDTO<UserDTO>> AuthenticateNFC(string NFCCode)
{
try
{
// Az API végpont meghatározása
string endpoint = $"{_httpClient.BaseAddress}api/user/authenticatenfc";
var userSimpleDTO = new UserSimpleDTO()
{
UserName = NFCCode,
Password = NFCCode,
};
// HTTP POST kérés küldése
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, userSimpleDTO))
{
httpResponseMessage.EnsureSuccessStatusCode();
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<ApiResponseDTO<UserDTO>>(jsonString);
return response ?? new ApiResponseDTO<UserDTO>
{
IsSuccess = false,
};
}
}
catch (Exception ex)
{
// Hiba visszaadása
return new ApiResponseDTO<UserDTO>
{
IsSuccess = false
};
}
}
public async Task<ApiResponseDTO<string>> SyncUsers_Up(Action<double, string> reportProgress)
{
var retVal = new ApiResponseDTO<string>();
@@ -116,7 +154,7 @@ namespace WorkFlowCheck.MAUI.Services
{
await PrepareAuthenticatedRequestAsync();
var userList = await _dbContext.Users.ToListAsync();
var userList = await _dbContext.MobileUsers.ToListAsync();
var userListDTO = _mapper.Map<List<UserDTO>>(userList);
var endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateAllUser";