Login avec connexion (fake)

pull/22/head
lebeaulato 3 months ago
parent 6c95137bf8
commit c7ba93c33b

@ -2,23 +2,19 @@
{ {
public class UserLogin public class UserLogin
{ {
public int Id { get; set; }
public string Image { get; set; } public string Image { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Email { get; set; }
public DateTime DateCreation { get; set; }
public Boolean IsAdmin { get; set; } public Boolean IsAdmin { get; set; }
public List<Commentary> Comments { get; set; }
public string Mdp { 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.Image = image;
this.Name = name; this.Name = name;
this.Email = email;
this.DateCreation = dateCreation;
this.IsAdmin = isAdmin; this.IsAdmin = isAdmin;
this.Mdp = mdp; this.Mdp = mdp;
} }

@ -1,4 +1,6 @@
@page "/" @page "/"
@using WF_WebAdmin.Model
@inject UserLogin uLogin
<h1>▶ Connexion ◀</h1> <h1>▶ Connexion ◀</h1>
<div class="login"> <div class="login">
@ -8,18 +10,16 @@
<label for="name"><strong>Identifiant *</strong></label> <label for="name"><strong>Identifiant *</strong></label>
<InputText @bind-Value="userLogin.Name" id="name" placeholder="Entrez votre pseudo" class="connexion" required /> <InputText @bind-Value="userLogin.Name" id="name" placeholder="Entrez votre pseudo" class="connexion" required />
<label for="mdp"><strong>Mot de passe*</strong></label> <label for="mdp"><strong>Mot de passe*</strong></label>
<InputText @bind-Value="@userLogin.Mdp" type="password" placeholder="Password" class="connexion" required />
@* <p> <strong> Mot de passe *</strong></p>
<input type="password" class="connexion" name="mdp" id="mdp" placeholder="Entrez votre mdp" required /> *@
<div class="buttonSubmitDiv"> <div class="buttonSubmitDiv">
<button class="buttonSudmite"type="submit">Se Connecter</button> <button class="buttonSudmite"type="submit">Se Connecter</button>
</div> </div>
<p>@TestConnexion</p> <p class="ErrorMsg"><i>@ErrorConnexion</i></p>
</EditForm> </EditForm>
</div> </div>

@ -10,7 +10,7 @@ namespace WF_WebAdmin.Pages
{ {
private UserLogin userLogin = new UserLogin(); private UserLogin userLogin = new UserLogin();
private string TestConnexion = "Pas connexion"; private string ErrorConnexion;
private List<UserLogin> usersConnexion; private List<UserLogin> usersConnexion;
[Inject] [Inject]
@ -21,28 +21,34 @@ namespace WF_WebAdmin.Pages
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
usersConnexion = await Http.GetFromJsonAsync<List<UserLogin>>($"{NavigationManager.BaseUri}fake-dataUserLogin.json"); usersConnexion = await Http.GetFromJsonAsync<List<UserLogin>>($"{NavigationManager.BaseUri}fake-dataUsers.json");
} }
public void validlogin() public void validlogin()
{ {
if (!string.IsNullOrEmpty(userLogin.Name)) if (!string.IsNullOrEmpty(userLogin.Name) || !string.IsNullOrEmpty(userLogin.Mdp))
{ {
foreach (var user in usersConnexion) foreach (var user in usersConnexion)
{ {
if(userLogin.Name == user.Name) if(userLogin.Name == user.Name && userLogin.Mdp == user.Mdp)
{ {
if(user.IsAdmin) 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 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";
}
} }
} }

@ -4,6 +4,7 @@ using Blazorise.Icons.FontAwesome;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web;
using WF_WebAdmin.Data; using WF_WebAdmin.Data;
using WF_WebAdmin.Model;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -13,7 +14,7 @@ builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>(); builder.Services.AddSingleton<WeatherForecastService>();
builder.Services.AddHttpClient(); builder.Services.AddHttpClient();
builder.Services.AddSingleton<UserLogin>();
builder.Services builder.Services
.AddBlazorise() .AddBlazorise()

@ -1,4 +1,6 @@
@inherits LayoutComponentBase @using WF_WebAdmin.Model
@inherits LayoutComponentBase
@inject UserLogin uLogin
<PageTitle>WF-WebAdmin</PageTitle> <PageTitle>WF-WebAdmin</PageTitle>
@ -9,9 +11,13 @@
<main> <main>
<div class="top-row px-4"> <div class="top-row px-4">
@if(usersConnexion != null) @if (!string.IsNullOrEmpty(uLogin.Name))
{ {
<img class="imageProfil" src="@usersConnexion[2].Image" /> <img class="imageProfil" src="@uLogin.Image" />
}
else
{
<img class="imageProfil" src="https://cdn-icons-png.flaticon.com/512/61/61205.png"/>
} }
</div> </div>
<article class="content px-4"> <article class="content px-4">

@ -1,21 +1,25 @@
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System;
using WF_WebAdmin.Model; using WF_WebAdmin.Model;
namespace WF_WebAdmin.Shared namespace WF_WebAdmin.Shared
{ {
public partial class MainLayout public partial class MainLayout
{ {
private List<User> usersConnexion; //private List<User> usersConnexion;
[Inject]
public HttpClient Http { get; set; } //[Inject]
//public HttpClient Http { get; set; }
//[Inject]
//public NavigationManager NavigationManager { get; set; }
[Inject] //protected override async Task OnInitializedAsync()
public NavigationManager NavigationManager { get; set; } //{
protected override async Task OnInitializedAsync() // usersConnexion = await Http.GetFromJsonAsync<List<User>>($"{NavigationManager.BaseUri}fake-dataUsers.json");
{ //}
usersConnexion = await Http.GetFromJsonAsync<List<User>>($"{NavigationManager.BaseUri}fake-dataUsers.json");
}
} }
} }

@ -174,3 +174,10 @@ p {
border: none; border: none;
font-size: 15px; font-size: 15px;
} }
.ErrorMsg {
color: red;
}

@ -3,153 +3,14 @@
"Id": 1, "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", "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", "Name": "Admin",
"Email": "admin@gmail.com",
"DateCreation": "2024-12-12",
"IsAdmin": true, "IsAdmin": true,
"Mdp" : "test" "Mdp" : "passwd"
}, },
{ {
"Id": 2, "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", "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", "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"
}
]
},
{
"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, "IsAdmin": false,
"Comments": [ "Mdp": "passwd"
{
"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,
"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
} }
] ]

@ -15,7 +15,8 @@
"Text": "Commentaire 2", "Text": "Commentaire 2",
"DateCreation": "2024-11-12" "DateCreation": "2024-11-12"
} }
] ],
"Mdp": "passwd"
}, },
{ {
"Id": 2, "Id": 2,
@ -23,7 +24,8 @@
"Name": "exploit", "Name": "exploit",
"Email": "exploit@gmail.com", "Email": "exploit@gmail.com",
"DateCreation": "2024-11-12", "DateCreation": "2024-11-12",
"IsAdmin": true "IsAdmin": false,
"Mdp": "passwd"
}, },
{ {
"Id": 3, "Id": 3,

Loading…
Cancel
Save