Login #22

Merged
leni.beaulaton merged 3 commits from Login into master 3 months ago

@ -1,16 +1,20 @@
namespace WF_WebAdmin.Converter
using WF_WebAdmin.Model;
namespace WF_WebAdmin.Converter
{
public class UserDTO
{
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 UserDTO(int id, string image, string name, string email, DateTime dateCreation)
public Boolean IsAdmin { get; set; }
public List<Commentary> Comments { get; set; }
public UserDTO(string image, string name, string email, DateTime dateCreation)
{
this.Id = id;
this.Image = image;
this.Name = name;
this.Email = email;

@ -6,13 +6,13 @@ namespace WF_WebAdmin.Converter
{
public User UserToDTO(UserDTO u)
{
User user = new User(u.Id, u.Image, u.Name, u.Email, u.DateCreation);
User user = new User(u.Image, u.Name, u.Email, u.DateCreation,u.IsAdmin);
return user;
}
public UserDTO DTOToUser(User u)
{
UserDTO user = new UserDTO(u.Id, u.Image, u.Name, u.Email, u.DateCreation);
UserDTO user = new UserDTO(u.Image, u.Name, u.Email, u.DateCreation);
return user;
}
}

@ -2,20 +2,24 @@
{
public class User
{
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 User(int id, string image, string name, string email, DateTime dateCreation)
public List<Commentary> Comments { get; set; }
public User(string image, string name, string email, DateTime dateCreation, bool isAdmin)
{
this.Id = id;
this.Image = image;
this.Name = name;
this.Email = email;
this.DateCreation = dateCreation;
IsAdmin = isAdmin;
}
public User() { }
}
}

@ -0,0 +1,24 @@
namespace WF_WebAdmin.Model
{
public class UserLogin
{
public int Id { get; set; }
public string Image { get; set; }
public string Name { get; set; }
public Boolean IsAdmin { get; set; }
public string Mdp { get; set; }
public UserLogin(int id,string image, string name, bool isAdmin, string mdp)
{
Id = id;
this.Image = image;
this.Name = name;
this.IsAdmin = isAdmin;
this.Mdp = mdp;
}
public UserLogin() { }
}
}

@ -16,7 +16,6 @@ else
{
<div class="userDiv">
<img class="imgProfil" src="@user.Image" />
<p class="idUser"><strong>Identifiant d'utilisateur :</strong> @user.Id</p>
@if (user.IsAdmin)
{
<p class="pseudo"><strong>Nom d'utilisateur :</strong> @user.Name <strong>(Administrateur)</strong></p>
@ -39,7 +38,7 @@ else
}
else
{
<p>Aucun commentaire sur le site</p>
<p><i>Aucun commentaire sur le site</i></p>
}
<button id="DeleteButton" @onclick="() => ShowConfirmation(user)">Supprimer l'utilisateur</button>

@ -40,7 +40,7 @@ namespace WF_WebAdmin.Pages
{
if (userToDelete != null)
{
users.RemoveAll(u => u.Id == userToDelete.Id);
users.RemoveAll(u => u.Name == userToDelete.Name);
ClosePopup();
}
}

@ -1,28 +1,29 @@
@page "/"
@using WF_WebAdmin.Model
@inject UserLogin uLogin
<h1>▶ Connexion ◀</h1>
<div class="login">
@* <form method="post" action="{{ racine }}/validlogin"> *@
<p> <strong>Identifiant *</strong></p>
<input type="text" class="connexion" name="pseudo" id="pseudo" placeholder="Entrez votre pseudo" required />
<EditForm Model="userLogin" OnValidSubmit="validlogin">
<DataAnnotationsValidator />
<ValidationSummary />
<p> <strong> Mot de passe *</strong></p>
<input type="password" class="connexion" name="mdp" id="mdp" placeholder="Entrez votre mdp" required />
<label for="name"><strong>Identifiant *</strong></label>
<InputText @bind-Value="userLogin.Name" id="name" placeholder="Entrez votre pseudo" class="connexion" required />
<label for="mdp"><strong>Mot de passe*</strong></label>
<InputText @bind-Value="@userLogin.Mdp" type="password" placeholder="Password" class="connexion" required />
<div class="buttonSubmitDiv">
<button class="buttonSudmite">Se Connecter</button>
<button class="buttonSudmite"type="submit">Se Connecter</button>
</div>
@* </form> *@
<p class="ErrorMsg"><i>@ErrorConnexion</i></p>
</EditForm>
</div>
@code {
private void ShowFullSite()
{
// Code pour afficher l'ensemble du menu
// Cela peut être un appel à une méthode ou un service qui change l'état de la visibilité du menu
}
}

@ -8,6 +8,51 @@ namespace WF_WebAdmin.Pages
{
public partial class Login
{
private UserLogin userLogin = new UserLogin();
private string ErrorConnexion;
private List<UserLogin> usersConnexion;
[Inject]
public HttpClient Http { get; set; }
[Inject]
public NavigationManager NavigationManager { get; set; }
protected override async Task OnInitializedAsync()
{
usersConnexion = await Http.GetFromJsonAsync<List<UserLogin>>($"{NavigationManager.BaseUri}fake-dataUsers.json");
}
public void validlogin()
{
if (!string.IsNullOrEmpty(userLogin.Name) || !string.IsNullOrEmpty(userLogin.Mdp))
{
foreach (var user in usersConnexion)
{
if(userLogin.Name == user.Name && userLogin.Mdp == user.Mdp)
{
if(user.IsAdmin)
{
ErrorConnexion = $"Connecté en tant que {user.Name} (Ca doit disparaitre dans le futur)";
uLogin.Id = user.Id;
break;
}
else
{
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";
}
}
}
}
}
}

@ -7,10 +7,10 @@
{
<p>Chargement des citations...</p>
}
else if (quotes.Count == 0)
@* else if (quotes.Count == 0)
{
<p>Aucune citation en attente de validation.</p>
}
} *@
else
{
<p>Citations en attente de validation :</p>
@ -28,8 +28,8 @@ else
<p><strong>Date de source :</strong> @quote.DateSrc.ToShortDateString()</p>
<p><strong>Utilisateur :</strong> @quote.UserProposition</p>
<button @onclick="() => ValiderQuote(quote.Id)">Valider</button>
<button @onclick="() => RejeterQuote(quote.Id)">Rejeter</button>
@* <button @onclick="() => ValiderQuote(quote.Id)">Valider</button>
<button @onclick="() => RejeterQuote(quote.Id)">Rejeter</button> *@
</div>
}
}

@ -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<WeatherForecastService>();
builder.Services.AddHttpClient();
builder.Services.AddSingleton<UserLogin>();
builder.Services
.AddBlazorise()

@ -1,5 +1,7 @@
@inherits LayoutComponentBase
@using WF_WebAdmin.Model
@inherits LayoutComponentBase
@inject UserLogin uLogin
<PageTitle>WF-WebAdmin</PageTitle>
<div class="page">
@ -8,11 +10,27 @@
</div>
<main>
<div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
<div class="top-row px-4">
@if (!string.IsNullOrEmpty(uLogin.Name))
{
<img class="imageProfil" src="@uLogin.Image" />
}
else
{
<img class="imageProfil" src="https://cdn-icons-png.flaticon.com/512/61/61205.png"/>
}
</div>
<article class="content px-4">
@Body
</article>
</main>
</div>
<style>
.imageProfil{
height:auto;
width : 30px;
border-radius:45%;
}
</style>

@ -0,0 +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<User> usersConnexion;
//[Inject]
//public HttpClient Http { get; set; }
//[Inject]
//public NavigationManager NavigationManager { get; set; }
//protected override async Task OnInitializedAsync()
//{
// usersConnexion = await Http.GetFromJsonAsync<List<User>>($"{NavigationManager.BaseUri}fake-dataUsers.json");
//}
}
}

@ -1,4 +1,5 @@
@import url('open-iconic/font/css/open-iconic-bootstrap.min.css');
@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap');
html, body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
@ -161,13 +162,13 @@ h1 {
text-align: center;
font-size: 32px;
margin-top: 10%;
font-family: "Roboto", serif;
}
p {
margin-top: 6%;
margin-bottom: 2%;
font-size: 20px;
font-family: "Lemon", serif;
font-family: "Roboto", serif;
}
.login {
@ -189,6 +190,7 @@ p {
width: 50%;
font-size: 1.25em;
background-color: white;
font-family: "Roboto", serif;
}
.connexion {
@ -203,6 +205,11 @@ p {
}
.ErrorMsg {
color: red;
}
table {
border-collapse: collapse;
width: 100%;

@ -0,0 +1,16 @@
[
{
"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",
"IsAdmin": true,
"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",
"IsAdmin": false,
"Mdp": "passwd"
}
]

@ -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,

Loading…
Cancel
Save