From f321677447c8da337a4e0c9a80dc5df31c93496d Mon Sep 17 00:00:00 2001 From: Piotr Kus Date: Sat, 1 Mar 2025 06:35:28 +0100 Subject: [PATCH] * Turned off Login as it is not working --- FaKrosnoApi/Controllers/ErrorLogController.cs | 1 - .../Controllers/ScheduleOrdersController.cs | 1 - .../Controllers/UserRolesController.cs | 2 ++ FaKrosnoApi/Program.cs | 30 ++++++++-------- OrdersManagement/Components/App.razor | 15 -------- .../Components/Layout/MainLayout.razor | 34 +++++++++---------- .../Components/Pages/Admin/Scheduler.razor | 20 +++++------ .../Components/Pages/Admin/UsersManager.razor | 20 +++++------ .../Components/Pages/CustomerOrder.razor | 22 ++++++------ .../Components/Pages/CustomerOrders.razor | 20 +++++------ .../Components/Pages/EdiCustomerOrder.razor | 21 ++++++------ .../Components/Pages/EdiCustomerOrders.razor | 22 ++++++------ OrdersManagement/Components/Pages/Login.razor | 4 +-- OrdersManagement/Components/Pages/Main.razor | 3 +- .../Components/Pages/ScheduleOrder.razor | 19 +++++------ .../Components/Pages/ScheduleOrders.razor | 22 ++++++------ .../Pages/Shared/ScheduleOrdersGrid.razor | 2 +- .../Components/Pages/Unauthorized.razor | 4 +-- OrdersManagement/Services/ServiceBase.cs | 14 ++++---- 19 files changed, 122 insertions(+), 154 deletions(-) diff --git a/FaKrosnoApi/Controllers/ErrorLogController.cs b/FaKrosnoApi/Controllers/ErrorLogController.cs index ce15be4..3e13a00 100644 --- a/FaKrosnoApi/Controllers/ErrorLogController.cs +++ b/FaKrosnoApi/Controllers/ErrorLogController.cs @@ -7,7 +7,6 @@ namespace FaKrosnoApi.Controllers { [ApiController] [Route("api/[controller]")] - [Authorize] public class ErrorLogController(IErrorLogService service) : Controller { [HttpGet] diff --git a/FaKrosnoApi/Controllers/ScheduleOrdersController.cs b/FaKrosnoApi/Controllers/ScheduleOrdersController.cs index 0106e1a..5185da8 100644 --- a/FaKrosnoApi/Controllers/ScheduleOrdersController.cs +++ b/FaKrosnoApi/Controllers/ScheduleOrdersController.cs @@ -7,7 +7,6 @@ namespace FaKrosnoApi.Controllers { [ApiController] [Route("api/[controller]")] - [Authorize] public class ScheduleOrdersController(IScheduleOrderService service) : Controller { [HttpGet] diff --git a/FaKrosnoApi/Controllers/UserRolesController.cs b/FaKrosnoApi/Controllers/UserRolesController.cs index 3edf5fc..2164191 100644 --- a/FaKrosnoApi/Controllers/UserRolesController.cs +++ b/FaKrosnoApi/Controllers/UserRolesController.cs @@ -4,6 +4,8 @@ using OrdersManagementDataModel.Services; namespace FaKrosnoApi.Controllers; +[ApiController] +[Route("api/[controller]")] public class UserRolesController(IUserRoleService service) : Controller { [HttpGet] diff --git a/FaKrosnoApi/Program.cs b/FaKrosnoApi/Program.cs index d051a14..81b4787 100644 --- a/FaKrosnoApi/Program.cs +++ b/FaKrosnoApi/Program.cs @@ -32,21 +32,21 @@ builder.Services.Configure(builder.Configuration.GetSection("J builder.WebHost.UseUrls("http://*:5001"); -builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) - .AddJwtBearer(options => - { - options.TokenValidationParameters = new TokenValidationParameters - { - ValidateIssuer = true, - ValidateAudience = true, - ValidateLifetime = true, - ValidateIssuerSigningKey = true, - ValidIssuer = builder.Configuration["Jwt:Issuer"], - ValidAudience = builder.Configuration["Jwt:Audience"], - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"] ?? string.Empty)), - NameClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier" - }; - }); +// builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) +// .AddJwtBearer(options => +// { +// options.TokenValidationParameters = new TokenValidationParameters +// { +// ValidateIssuer = true, +// ValidateAudience = true, +// ValidateLifetime = true, +// ValidateIssuerSigningKey = true, +// ValidIssuer = builder.Configuration["Jwt:Issuer"], +// ValidAudience = builder.Configuration["Jwt:Audience"], +// IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"] ?? string.Empty)), +// NameClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier" +// }; +// }); builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); diff --git a/OrdersManagement/Components/App.razor b/OrdersManagement/Components/App.razor index 3459ba0..fbd6994 100644 --- a/OrdersManagement/Components/App.razor +++ b/OrdersManagement/Components/App.razor @@ -20,21 +20,6 @@ - - - - - -

Brak autoryzacji

-

Zaloguj się

-
-
-
- -

Strona nie znaleziona.

-
-
-
diff --git a/OrdersManagement/Components/Layout/MainLayout.razor b/OrdersManagement/Components/Layout/MainLayout.razor index a300bcd..3c2fc04 100644 --- a/OrdersManagement/Components/Layout/MainLayout.razor +++ b/OrdersManagement/Components/Layout/MainLayout.razor @@ -16,23 +16,23 @@ Icon

FA Krosno Manager

-
- @if (IsAuthenticated) - { - Jesteś zalogowany jako @UserName - Wyloguj - } - else - { - Zaloguj - } -
+ @*
*@ + @* @if (IsAuthenticated) *@ + @* { *@ + @* Jesteś zalogowany jako @UserName *@ + @* Wyloguj *@ + @* } *@ + @* else *@ + @* { *@ + @* Zaloguj *@ + @* } *@ + @*
*@
- + @if (UserName == "pkus") @@ -64,11 +64,11 @@ protected override void OnInitialized() { - ClaimsPrincipal currentUser = AuthenticationStateProvider.GetCurrentUser(); - IsAuthenticated = currentUser.Identity?.IsAuthenticated == true; - UserName = currentUser.Identity?.Name ?? "Nieznany użytkownik"; - - AuthenticationStateProvider.AuthenticationStateChanged += OnAuthenticationStateChanged; + // ClaimsPrincipal currentUser = AuthenticationStateProvider.GetCurrentUser(); + // IsAuthenticated = currentUser.Identity?.IsAuthenticated == true; + // UserName = currentUser.Identity?.Name ?? "Nieznany użytkownik"; + // + // AuthenticationStateProvider.AuthenticationStateChanged += OnAuthenticationStateChanged; } private async void OnAuthenticationStateChanged(Task task) diff --git a/OrdersManagement/Components/Pages/Admin/Scheduler.razor b/OrdersManagement/Components/Pages/Admin/Scheduler.razor index d2d8fd9..72e25c5 100644 --- a/OrdersManagement/Components/Pages/Admin/Scheduler.razor +++ b/OrdersManagement/Components/Pages/Admin/Scheduler.razor @@ -1,7 +1,5 @@ @page "/Admin/Scheduler" -@attribute [Authorize] - @using System.Security.Claims @using Microsoft.AspNetCore.Authorization @using OrdersManagementDataModel.Dtos @@ -60,17 +58,17 @@ { if (firstRender) { - ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); - - if (currentUser.Identity?.IsAuthenticated == false || currentUser.Identity?.Name != "pkus") - { - NavigationManager.NavigateTo("/Unauthorized"); - } - else - { + // ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + // + // if (currentUser.Identity?.IsAuthenticated == false || currentUser.Identity?.Name != "pkus") + // { + // NavigationManager.NavigateTo("/Unauthorized"); + // } + // else + // { await LoadTasks(); StateHasChanged(); - } + // } } } diff --git a/OrdersManagement/Components/Pages/Admin/UsersManager.razor b/OrdersManagement/Components/Pages/Admin/UsersManager.razor index 9bfb8d7..7262b2d 100644 --- a/OrdersManagement/Components/Pages/Admin/UsersManager.razor +++ b/OrdersManagement/Components/Pages/Admin/UsersManager.razor @@ -1,7 +1,5 @@ @page "/admin/UsersManager" -@attribute [Authorize] - @using System.Security.Claims @using Microsoft.AspNetCore.Authorization @using OrdersManagementDataModel.Dtos @@ -136,19 +134,19 @@ if (firstRender) { Visibility = false; - ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); - - if (currentUser.Identity?.IsAuthenticated == false || currentUser.Identity?.Name != "pkus") - { - NavigationManager.NavigateTo("/Unauthorized"); - } - else - { + // ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + // + // if (currentUser.Identity?.IsAuthenticated == false || currentUser.Identity?.Name != "pkus") + // { + // NavigationManager.NavigateTo("/Unauthorized"); + // } + // else + // { await LoadUsers(); await LoadRoles(); //await LoadFunctions(); StateHasChanged(); - } + // } } } diff --git a/OrdersManagement/Components/Pages/CustomerOrder.razor b/OrdersManagement/Components/Pages/CustomerOrder.razor index bfb8c35..1e1464a 100644 --- a/OrdersManagement/Components/Pages/CustomerOrder.razor +++ b/OrdersManagement/Components/Pages/CustomerOrder.razor @@ -1,7 +1,5 @@ @page "/CustomerOrder/{CustomerOrderId:guid}" -@attribute [Authorize] - @inject CustomerOrderService CustomerOrderService @inject ScheduleOrderService ScheduleOrderService @inject NavigationManager NavigationManager @@ -224,14 +222,14 @@ StateHasChanged(); _isVisible = false; - ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); - - if (currentUser.Identity?.IsAuthenticated == false) - { - NavigationManager.NavigateTo("/Unauthorized"); - } - else - { + // ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + // + // if (currentUser.Identity?.IsAuthenticated == false) + // { + // NavigationManager.NavigateTo("/Unauthorized"); + // } + // else + // { CustomerOrderDto? customerOrder = await CustomerOrderService.GetCustomerOrderAsync(CustomerOrderId); if (customerOrder != null) @@ -239,7 +237,9 @@ CustomerOrderDto = customerOrder; _customerOrderLines = CustomerOrderDto.CustomerOrderLines.ToList() ?? []; } - } + + StateHasChanged(); + // } } } diff --git a/OrdersManagement/Components/Pages/CustomerOrders.razor b/OrdersManagement/Components/Pages/CustomerOrders.razor index 6ac06dd..2ea4343 100644 --- a/OrdersManagement/Components/Pages/CustomerOrders.razor +++ b/OrdersManagement/Components/Pages/CustomerOrders.razor @@ -1,7 +1,5 @@ @page "/CustomerOrders" -@attribute [Authorize] - @inject CustomerOrderService CustomerOrderService @inject NavigationManager NavigationManager @inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider @@ -91,19 +89,19 @@ { if (firstRender) { - ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); - - if (currentUser.Identity?.IsAuthenticated == false) - { - NavigationManager.NavigateTo("/Unauthorized"); - } - else - { + // ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + // + // if (currentUser.Identity?.IsAuthenticated == false) + // { + // NavigationManager.NavigateTo("/Unauthorized"); + // } + // else + // { _customerOrders = await CustomerOrderService.GetCustomerOrdersAsync() ?? new List(); _customerOrders = _customerOrders.OrderByDescending(x => x.CreateDate).ToList(); StateHasChanged(); - } + // } } } diff --git a/OrdersManagement/Components/Pages/EdiCustomerOrder.razor b/OrdersManagement/Components/Pages/EdiCustomerOrder.razor index 76ba82b..d2f444f 100644 --- a/OrdersManagement/Components/Pages/EdiCustomerOrder.razor +++ b/OrdersManagement/Components/Pages/EdiCustomerOrder.razor @@ -1,7 +1,5 @@ @page "/EdiCustomerOrder/{CustomerOrderId:guid}" -@attribute [Authorize] - @inject EdiCustomerOrderService EdiCustomerOrderService @inject NavigationManager NavigationManager @inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider @@ -197,19 +195,20 @@ { if (firstRender) { - ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); - - if (currentUser.Identity?.IsAuthenticated == false) - { - NavigationManager.NavigateTo("/Unauthorized"); - } - else - { + // ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + // + // if (currentUser.Identity?.IsAuthenticated == false) + // { + // NavigationManager.NavigateTo("/Unauthorized"); + // } + // else + // { EdiCustomerOrderDto? ediCustomerOrder = await EdiCustomerOrderService.GetEdiCustomerOrderAsync(CustomerOrderId); EdiCustomerOrderDto = ediCustomerOrder; _ediCustomerOrderLines = ediCustomerOrder?.EdiCustomerOrderLines.ToList() ?? []; - } + StateHasChanged(); + // } } } diff --git a/OrdersManagement/Components/Pages/EdiCustomerOrders.razor b/OrdersManagement/Components/Pages/EdiCustomerOrders.razor index 2f50c8a..e5289c5 100644 --- a/OrdersManagement/Components/Pages/EdiCustomerOrders.razor +++ b/OrdersManagement/Components/Pages/EdiCustomerOrders.razor @@ -1,7 +1,5 @@ @page "/EdiCustomerOrders" -@attribute [Authorize] - @inject EdiCustomerOrderService EdiCustomerOrderService @inject NavigationManager NavigationManager @inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider @@ -34,7 +32,7 @@ {
- @_text + @_text
} @@ -146,16 +144,16 @@ { if (firstRender) { - ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); - - if (currentUser.Identity?.IsAuthenticated == false) - { - NavigationManager.NavigateTo("/Unauthorized"); - } - else - { + // ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + // + // if (currentUser.Identity?.IsAuthenticated == false) + // { + // NavigationManager.NavigateTo("/Unauthorized"); + // } + // else + // { await LoadData(); - } + // } } } diff --git a/OrdersManagement/Components/Pages/Login.razor b/OrdersManagement/Components/Pages/Login.razor index b852641..01040db 100644 --- a/OrdersManagement/Components/Pages/Login.razor +++ b/OrdersManagement/Components/Pages/Login.razor @@ -1,7 +1,5 @@ @page "/login" -@attribute [AllowAnonymous] - @using Microsoft.AspNetCore.Authorization @using OrdersManagement.Models @using Syncfusion.Blazor.Inputs @@ -79,7 +77,7 @@ } - Orders Management System © @(DateTime.Now.Year) + FA Krosno Manager © @(DateTime.Now.Year)
diff --git a/OrdersManagement/Components/Pages/Main.razor b/OrdersManagement/Components/Pages/Main.razor index 44ae64f..3a90b11 100644 --- a/OrdersManagement/Components/Pages/Main.razor +++ b/OrdersManagement/Components/Pages/Main.razor @@ -1,7 +1,6 @@ -@page "/" +@page "/Main" @using Microsoft.AspNetCore.Authorization -@attribute [AllowAnonymous] @inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider @inject NavigationManager NavigationManager diff --git a/OrdersManagement/Components/Pages/ScheduleOrder.razor b/OrdersManagement/Components/Pages/ScheduleOrder.razor index 943336a..0488fc9 100644 --- a/OrdersManagement/Components/Pages/ScheduleOrder.razor +++ b/OrdersManagement/Components/Pages/ScheduleOrder.razor @@ -1,5 +1,4 @@ @page "/ScheduleOrder/{ScheduleOrderId:int}" -@attribute [Authorize] @using System.Security.Claims @using Microsoft.AspNetCore.Authorization @@ -128,14 +127,14 @@ { if (firstRender) { - ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); - - if (currentUser.Identity?.IsAuthenticated == false) - { - NavigationManager.NavigateTo("/Unauthorized"); - } - else - { + // ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + // + // if (currentUser.Identity?.IsAuthenticated == false) + // { + // NavigationManager.NavigateTo("/Unauthorized"); + // } + // else + // { ScheduleOrderDto = await ScheduleOrderService.GetScheduleOrderAsync(ScheduleOrderId); _scheduleOrderDetails = ScheduleOrderDto?.ScheduleOrderDetails; @@ -149,7 +148,7 @@ scheduleOrderDetailDto.RecipientName = ScheduleOrderDto?.RecipientName; scheduleOrderDetailDto.PurchaserName = ScheduleOrderDto?.PurchaserCode; } - } + // } StateHasChanged(); } diff --git a/OrdersManagement/Components/Pages/ScheduleOrders.razor b/OrdersManagement/Components/Pages/ScheduleOrders.razor index 551dfc0..f4c564d 100644 --- a/OrdersManagement/Components/Pages/ScheduleOrders.razor +++ b/OrdersManagement/Components/Pages/ScheduleOrders.razor @@ -1,6 +1,4 @@ -@page "/ScheduleOrders" - -@attribute [Authorize] +@page "/" @using System.Security.Claims @using Microsoft.AspNetCore.Authorization @@ -20,17 +18,17 @@ { if (firstRender) { - ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); - - if (currentUser.Identity?.IsAuthenticated == false) - { - NavigationManager.NavigateTo("/Unauthorized"); - } - else - { + // ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser(); + // + // if (currentUser.Identity?.IsAuthenticated == false) + // { + // NavigationManager.NavigateTo("/Unauthorized"); + // } + // else + // { _scheduleOrders = await FetchScheduleOrdersAsync(); StateHasChanged(); - } + // } } } diff --git a/OrdersManagement/Components/Pages/Shared/ScheduleOrdersGrid.razor b/OrdersManagement/Components/Pages/Shared/ScheduleOrdersGrid.razor index 1523abe..615599c 100644 --- a/OrdersManagement/Components/Pages/Shared/ScheduleOrdersGrid.razor +++ b/OrdersManagement/Components/Pages/Shared/ScheduleOrdersGrid.razor @@ -95,7 +95,7 @@ - Orders Management System © @(DateTime.Now.Year) + FA Krosno Manager © @(DateTime.Now.Year)
diff --git a/OrdersManagement/Components/Pages/Unauthorized.razor b/OrdersManagement/Components/Pages/Unauthorized.razor index 78bdb97..38426cd 100644 --- a/OrdersManagement/Components/Pages/Unauthorized.razor +++ b/OrdersManagement/Components/Pages/Unauthorized.razor @@ -1,8 +1,6 @@ @page "/Unauthorized" @using Microsoft.AspNetCore.Authorization -@attribute [AllowAnonymous] - @using Syncfusion.Blazor.Cards @using Syncfusion.Blazor.Buttons @@ -22,7 +20,7 @@ - Orders Management System © @(DateTime.Now.Year) + FA Krosno Manager © @(DateTime.Now.Year) diff --git a/OrdersManagement/Services/ServiceBase.cs b/OrdersManagement/Services/ServiceBase.cs index 1d83dec..772209f 100644 --- a/OrdersManagement/Services/ServiceBase.cs +++ b/OrdersManagement/Services/ServiceBase.cs @@ -15,7 +15,7 @@ public class ServiceBase where T : class protected async Task?> GetListAsync(string request) { - Configure(); + //Configure(); var response = await _httpClient.GetAsync(request); response.EnsureSuccessStatusCode(); @@ -24,7 +24,7 @@ public class ServiceBase where T : class protected async Task GetEntityAsync(string request) { - Configure(); + //Configure(); var response = await _httpClient.GetAsync(request); response.EnsureSuccessStatusCode(); @@ -33,7 +33,7 @@ public class ServiceBase where T : class protected async Task PostAsync(string request) { - Configure(); + //Configure(); var response = await _httpClient.PostAsync(request, null); response.EnsureSuccessStatusCode(); @@ -42,7 +42,7 @@ public class ServiceBase where T : class protected async Task PostAsJsonAsync(string request, T obj) { - Configure(); + //Configure(); var response = await _httpClient.PostAsJsonAsync(request, obj); response.EnsureSuccessStatusCode(); @@ -51,7 +51,7 @@ public class ServiceBase where T : class protected async Task PostAsJsonAsync(string request, object obj) { - Configure(); + //Configure(); var response = await _httpClient.PostAsJsonAsync(request, obj); response.EnsureSuccessStatusCode(); @@ -60,7 +60,7 @@ public class ServiceBase where T : class protected async Task PutAsJsonAsync(string request, T obj) { - Configure(); + //Configure(); var response = await _httpClient.PutAsJsonAsync(request, obj); response.EnsureSuccessStatusCode(); @@ -69,7 +69,7 @@ public class ServiceBase where T : class protected async Task DeleteAsync(string request) { - Configure(); + //Configure(); var response = await _httpClient.DeleteAsync(request); response.EnsureSuccessStatusCode();