diff --git a/WF-WebAdmin/WF-WebAdmin/Model/UserLogin.cs b/WF-WebAdmin/WF-WebAdmin/Model/UserLogin.cs index 52748e0..a2e9bb7 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/UserLogin.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/UserLogin.cs @@ -2,23 +2,19 @@ { public class UserLogin { + public int Id { get; set; } public string Image { get; set; } public string Name { get; set; } - public string Email { get; set; } - public DateTime DateCreation { get; set; } public Boolean IsAdmin { get; set; } - public List Comments { get; set; } - public string Mdp { get; set; } - public UserLogin(string image, string name, string email, DateTime dateCreation, bool isAdmin, string mdp) + public UserLogin(int id,string image, string name, bool isAdmin, string mdp) { + Id = id; this.Image = image; this.Name = name; - this.Email = email; - this.DateCreation = dateCreation; this.IsAdmin = isAdmin; this.Mdp = mdp; } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor index 37073ca..908ce74 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor @@ -1,4 +1,6 @@ @page "/" +@using WF_WebAdmin.Model +@inject UserLogin uLogin

▶ Connexion ◀

@@ -8,18 +10,16 @@ - + + - @*

Mot de passe *

- *@ -
-

@TestConnexion

+

@ErrorConnexion

diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor.cs index 79cb348..6f6c59f 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor.cs @@ -10,7 +10,7 @@ namespace WF_WebAdmin.Pages { private UserLogin userLogin = new UserLogin(); - private string TestConnexion = "Pas connexion"; + private string ErrorConnexion; private List usersConnexion; [Inject] @@ -21,27 +21,33 @@ namespace WF_WebAdmin.Pages protected override async Task OnInitializedAsync() { - usersConnexion = await Http.GetFromJsonAsync>($"{NavigationManager.BaseUri}fake-dataUserLogin.json"); + usersConnexion = await Http.GetFromJsonAsync>($"{NavigationManager.BaseUri}fake-dataUsers.json"); } public void validlogin() { - if (!string.IsNullOrEmpty(userLogin.Name)) + if (!string.IsNullOrEmpty(userLogin.Name) || !string.IsNullOrEmpty(userLogin.Mdp)) { foreach (var user in usersConnexion) { - if(userLogin.Name == user.Name) + if(userLogin.Name == user.Name && userLogin.Mdp == user.Mdp) { if(user.IsAdmin) { - TestConnexion = $"Connecté en tant que {user.Name}"; + ErrorConnexion = $"Connecté en tant que {user.Name} (Ca doit disparaitre dans le futur)"; + uLogin.Id = user.Id; + break; } else { - TestConnexion = "Connexion échouée, pas admin"; + ErrorConnexion = "Connexion échouée, le nom ou le mot de passe sont incorrectes"; } - + + } + else + { + ErrorConnexion = "Connexion échouée, le nom ou le mot de passe sont incorrectes"; } } diff --git a/WF-WebAdmin/WF-WebAdmin/Program.cs b/WF-WebAdmin/WF-WebAdmin/Program.cs index d106ef6..aa99ff6 100644 --- a/WF-WebAdmin/WF-WebAdmin/Program.cs +++ b/WF-WebAdmin/WF-WebAdmin/Program.cs @@ -4,6 +4,7 @@ using Blazorise.Icons.FontAwesome; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; using WF_WebAdmin.Data; +using WF_WebAdmin.Model; var builder = WebApplication.CreateBuilder(args); @@ -13,7 +14,7 @@ builder.Services.AddServerSideBlazor(); builder.Services.AddSingleton(); builder.Services.AddHttpClient(); - +builder.Services.AddSingleton(); builder.Services .AddBlazorise() diff --git a/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor b/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor index dbc4566..942b447 100644 --- a/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor +++ b/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor @@ -1,5 +1,7 @@ -@inherits LayoutComponentBase - +@using WF_WebAdmin.Model +@inherits LayoutComponentBase +@inject UserLogin uLogin + WF-WebAdmin
@@ -8,10 +10,14 @@
-
- @if(usersConnexion != null) - { - +
+ @if (!string.IsNullOrEmpty(uLogin.Name)) + { + + } + else + { + }
diff --git a/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor.cs b/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor.cs index 56a4e6c..f7cb295 100644 --- a/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Shared/MainLayout.razor.cs @@ -1,21 +1,25 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Mvc; +using System; using WF_WebAdmin.Model; + namespace WF_WebAdmin.Shared { public partial class MainLayout { - private List usersConnexion; - [Inject] - public HttpClient Http { get; set; } + //private List usersConnexion; + + //[Inject] + //public HttpClient Http { get; set; } - [Inject] - public NavigationManager NavigationManager { get; set; } + //[Inject] + //public NavigationManager NavigationManager { get; set; } - protected override async Task OnInitializedAsync() - { - usersConnexion = await Http.GetFromJsonAsync>($"{NavigationManager.BaseUri}fake-dataUsers.json"); - } + //protected override async Task OnInitializedAsync() + //{ + + // usersConnexion = await Http.GetFromJsonAsync>($"{NavigationManager.BaseUri}fake-dataUsers.json"); + //} } } diff --git a/WF-WebAdmin/WF-WebAdmin/wwwroot/css/site.css b/WF-WebAdmin/WF-WebAdmin/wwwroot/css/site.css index ec81895..721ef6a 100644 --- a/WF-WebAdmin/WF-WebAdmin/wwwroot/css/site.css +++ b/WF-WebAdmin/WF-WebAdmin/wwwroot/css/site.css @@ -174,3 +174,10 @@ p { border: none; font-size: 15px; } + + + + +.ErrorMsg { + color: red; +} \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataUserLogin.json b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataUserLogin.json index ed4c598..241a266 100644 --- a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataUserLogin.json +++ b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataUserLogin.json @@ -3,153 +3,14 @@ "Id": 1, "Image": "https://tse4.mm.bing.net/th/id/OIP.fc5TQflh0cbxB1GUeOdk6gHaK8?w=123&h=180&c=7&r=0&o=5&pid=1.7", "Name": "Admin", - "Email": "admin@gmail.com", - "DateCreation": "2024-12-12", "IsAdmin": true, - "Mdp" : "test" - }, - { - "Id": 2, - "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "exploit", - "Email": "exploit@gmail.com", - "DateCreation": "2024-11-12", - "IsAdmin": true - }, - { - "Id": 3, - "Image": "https://tse4.mm.bing.net/th/id/OIP.XNQPKwc1OUfvnSO9MsxDYgHaE7?w=202&h=180&c=7&r=0&o=5&pid=1.7", - "Name": "testeur", - "Email": "testeur@gmail.com", - "DateCreation": "2024-08-02", - "IsAdmin": false, - "Comments": [ - { - "Text": "Premier test effectué, tout semble OK.", - "DateCreation": "2024-08-02" - } - ] - }, - { - "Id": 4, - "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "dev", - "Email": "dev@gmail.com", - "DateCreation": "2024-10-10", - "IsAdmin": false - }, - { - "Id": 5, - "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "jean_doe", - "Email": "jean.doe@gmail.com", - "DateCreation": "2024-06-25", - "IsAdmin": false, - "Comments": [ - { - "Text": "Utilisateur très actif, peut être un peu trop intrusif.", - "DateCreation": "2024-06-25" - } - ] + "Mdp" : "passwd" }, { - "Id": 6, - "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "jane_smith", - "Email": "jane.smith@gmail.com", - "DateCreation": "2024-07-15", - "IsAdmin": false - }, - { - "Id": 7, - "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "admin_joe", - "Email": "admin.joe@gmail.com", - "DateCreation": "2024-05-30", - "IsAdmin": true - }, - { - "Id": 8, - "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "dev_anna", - "Email": "dev.anna@gmail.com", - "DateCreation": "2024-09-05", - "IsAdmin": false - }, - { - "Id": 9, - "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "support_mark", - "Email": "support.mark@gmail.com", - "DateCreation": "2024-11-20", - "IsAdmin": false, - "Comments": [ - { - "Text": "Support rapide et efficace, mais manquant un peu de détails.", - "DateCreation": "2024-11-20" - } - ] - }, - { - "Id": 10, - "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "dev_susan", - "Email": "dev.susan@gmail.com", - "DateCreation": "2024-08-12", - "IsAdmin": false - }, - { - "Id": 11, - "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "designer_steve", - "Email": "designer.steve@gmail.com", - "DateCreation": "2024-07-01", - "IsAdmin": false, - "Comments": [ - { - "Text": "Le design doit être retravaillé pour plus de clarté.", - "DateCreation": "2024-07-01" - } - ] - }, - { - "Id": 12, - "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "admin_lucas", - "Email": "admin.lucas@gmail.com", - "DateCreation": "2024-09-22", - "IsAdmin": true - }, - { - "Id": 13, - "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "manager_anna", - "Email": "manager.anna@gmail.com", - "DateCreation": "2024-05-01", - "IsAdmin": false - }, - { - "Id": 14, - "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "developer_mike", - "Email": "developer.mike@gmail.com", - "DateCreation": "2024-11-02", - "IsAdmin": false - }, - { - "Id": 15, - "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "test_user_01", - "Email": "test.user01@gmail.com", - "DateCreation": "2024-06-10", - "IsAdmin": false - }, - { - "Id": 16, + "Id": 2, "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", - "Name": "admin_kate", - "Email": "admin.kate@gmail.com", - "DateCreation": "2024-04-16", - "IsAdmin": true + "Name": "exploit", + "IsAdmin": false, + "Mdp": "passwd" } ] \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataUsers.json b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataUsers.json index ec07099..d995d42 100644 --- a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataUsers.json +++ b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataUsers.json @@ -5,25 +5,27 @@ "Name": "Admin", "Email": "admin@gmail.com", "DateCreation": "2024-12-12", - "IsAdmin": true, - "Comments": [ - { - "Text": "Commentaire 1", - "DateCreation": "2024-12-12" - }, - { - "Text": "Commentaire 2", - "DateCreation": "2024-11-12" - } - ] - }, - { + "IsAdmin": true, + "Comments": [ + { + "Text": "Commentaire 1", + "DateCreation": "2024-12-12" + }, + { + "Text": "Commentaire 2", + "DateCreation": "2024-11-12" + } + ], + "Mdp": "passwd" + }, + { "Id": 2, "Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7", "Name": "exploit", "Email": "exploit@gmail.com", "DateCreation": "2024-11-12", - "IsAdmin": true + "IsAdmin": false, + "Mdp": "passwd" }, { "Id": 3,