瀏覽代碼

fix pb authen

WebUI
Guillaume TOPENOT 6 天之前
父節點
當前提交
1246e63bc8
共有 7 個檔案被更改,包括 50 行新增13 行删除
  1. +7
    -0
      WebUI/ReAct_PME.Api/Controllers/custom/ChatRoomController.cs
  2. +4
    -3
      WebUI/ReAct_PME.Api/appsettings.Production.json
  3. +4
    -3
      WebUI/ReAct_PME.Api/appsettings.json
  4. +18
    -4
      WebUI/ReAct_PME.WebUI/Layout/MainLayout.razor
  5. +7
    -1
      WebUI/ReAct_PME.WebUI/Layout/NavMenu.razor
  6. +1
    -1
      WebUI/ReAct_PME.WebUI/Pages/ChatRoom/ChatRoom_base.razor.cs
  7. +9
    -1
      WebUI/ReAct_PME.WebUI/Pages/PagesInitializer.cs

+ 7
- 0
WebUI/ReAct_PME.Api/Controllers/custom/ChatRoomController.cs 查看文件

@@ -9,6 +9,13 @@ namespace ReAct_PME_API.Controllers
[ApiController]
public class ChatRoomController(IChatRoomService service, IDT_CONVERSATIONService dt_conversationService, IDT_CONVERSATION_LIGNEService dt_conversation_ligneService, IDT_WORK_FORCEService dt_work_forceService) : ControllerBase
{
[HttpGet("llm/test")]
public async Task<ActionResult> TestRequest()
{
await Task.Delay(1);
return Ok(true);
}

[HttpPost("llm")]
public async Task<ActionResult> EnvoiRequete([FromBody] List<string> requete)
{

+ 4
- 3
WebUI/ReAct_PME.Api/appsettings.Production.json 查看文件

@@ -11,9 +11,10 @@
"DefaultConnection": "Server=SERVER_NAME;Database=ReAct_PME;Trusted_Connection=True;TrustServerCertificate=True"
},
"Jwt": {
"Issuer": "http://192.168.4.3:7008", // METTRE URL de l'API du SERVEUR
"Audience": "http://192.168.4.3:7286", // METTRE URL du WebUI du SERVEUR
"ExpireMinutes": 60
"SecretKey": "5357f3ec-0c27-49f6-b68e-28f5c2b260a5",
"Issuer": "http://192.168.4.3:7008", // METTRE URL de l'API du SERVEUR
"Audience": "http://192.168.4.3:7286", // METTRE URL du WebUI du SERVEUR
"ExpireMinutes": 60
},
"Cors": {
"AllowedOrigins": [

+ 4
- 3
WebUI/ReAct_PME.Api/appsettings.json 查看文件

@@ -11,9 +11,10 @@
"DefaultConnection": "Server=AIT_GTO_OMEN;Database=ReAct_PME;Trusted_Connection=True;TrustServerCertificate=True"
},
"Jwt": {
"Issuer": "ReAct_PMEAPI",
"Audience": "ReAct_PMEClient",
"ExpireMinutes": 60
"SecretKey": "5357f3ec-0c27-49f6-b68e-28f5c2b260a5",
"Issuer": "ReAct_PMEAPI",
"Audience": "ReAct_PMEClient",
"ExpireMinutes": 60
},
"Cors": {
"AllowedOrigins": [

+ 18
- 4
WebUI/ReAct_PME.WebUI/Layout/MainLayout.razor 查看文件

@@ -2,6 +2,12 @@
@inject Blazored.Modal.Services.IModalService ModalService
@inject AuthenticationStateProvider AuthenticationStateProvider
@using Microsoft.AspNetCore.Components.Authorization
@inject HttpClient Http
@inject ReAct_PME.WebUI.ServicesUI.AuthService AuthService
@inject NavigationManager Navigation
@inject IToastService ToastService


<BlazoredToasts />

<div class="page">
@@ -153,12 +159,20 @@


@code {
private AuthenticationState? authState;
private System.Security.Claims.ClaimsPrincipal? user;
/*
//private AuthenticationState? authState;
//private System.Security.Claims.ClaimsPrincipal? user;

protected override async Task OnInitializedAsync()
{
authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
user = authState.User;
var tok = await PagesInitializer.VerifConnexionAndRules(AuthenticationStateProvider, Navigation, Http, ToastService, "api/ChatRoom/llm/test");
if (tok == null || tok.Length == 0)
return;
else
AuthService.SetToken(tok);

//authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
//user = authState.User;
}
*/
}

+ 7
- 1
WebUI/ReAct_PME.WebUI/Layout/NavMenu.razor 查看文件

@@ -5,6 +5,7 @@
@inject AuthService AuthService
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject NavigationManager Navigation
@inject IToastService ToastService

<div class="sidebar @(IsCollapsed ? "collapsed" : "")">
<div class="sidebar-header">
@@ -187,7 +188,12 @@

protected override async Task OnInitializedAsync()
{
var id = AuthService.ID;
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;

var tok = await PagesInitializer.VerifConnexionAndRules(AuthenticationStateProvider, Navigation, Http, ToastService, "api/ChatRoom/llm/test");
if (!(tok == null || tok.Length == 0))
AuthService.SetToken(tok);

await LoadChatConversations();


+ 1
- 1
WebUI/ReAct_PME.WebUI/Pages/ChatRoom/ChatRoom_base.razor.cs 查看文件

@@ -57,7 +57,7 @@ namespace ReAct_PME.WebUI.Pages.ChatRoom
{
#region Vérification si utilisateur est connecté et s'il a les droits

var tok = await PagesInitializer.VerifConnexionAndRules(AuthenticationStateProvider, Navigation, Http, ToastService, "/api/ChatRoom/rag/listeDomaines");
var tok = await PagesInitializer.VerifConnexionAndRules(AuthenticationStateProvider, Navigation, Http, ToastService, "/api/ChatRoom/llm/test");
if (tok == null || tok.Length == 0)
return;
else

+ 9
- 1
WebUI/ReAct_PME.WebUI/Pages/PagesInitializer.cs 查看文件

@@ -67,6 +67,13 @@ namespace ReAct_PME.WebUI
{
// Vérification si utilisateur est connecté
var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateprov;
if (customAuthStateProvider.User == null)
{
//navigation.NavigateTo("/login");
return "";
}


if (!customAuthStateProvider.User!.Identity!.IsAuthenticated)
{
navigation.NavigateTo("/login");
@@ -94,8 +101,9 @@ namespace ReAct_PME.WebUI
return token;
}

catch
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
navigation.NavigateTo("/login");
return "";
}

Loading…
取消
儲存