Ajout de la fonctionnalité, add Admin et delete admin

pull/10/head
lebeaulato 4 months ago
parent af07002098
commit 143a8c2f8a

@ -0,0 +1,10 @@
namespace WF_WebAdmin.Model
{
public class Commentary
{
public int Id { get; set; }
public int IdUser { get; set; }
public string Text { get; set; }
public DateTime DateCreation { get; set; }
}
}

@ -3,10 +3,13 @@
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 List<Commentary> Comments { get; set; }
}
}

@ -14,13 +14,44 @@
<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>
}
else
{
<p class="pseudo"><strong>Nom d'utilisateur :</strong> @user.Name</p>
}
<p class="mail"><strong>Email de l'utilisateur :</strong> @user.Email</p>
<p class="dateCrea"><strong>Date de création de l'utilisateur :</strong> @user.DateCreation.ToShortDateString()</p>
@if(user.Comments != null)
{
@foreach (var comment in user.Comments)
{
<p class="commentaire"><strong>Commentaire (@comment.) :</strong> @comment.Text</p>
}
}
else
{
<p>Aucun commentaires</p>
}
<button id="DeleteButton" @onclick="() => ShowConfirmation(user)">Supprimer l'utilisateur</button>
@if (!user.IsAdmin)
{
<button id="AdminButton" @onclick="() => ShowConfirmationAdmin(user)">Ajouter en tant qu'administrateur</button>
}
else
{
<button id="AdminButton" @onclick="() => ShowConfirmationAdmin(user)">Retirer en tant qu'administrateur</button>
}
</div>
}
<!-- Fenêtre de confirmation -->
<!-- Fenêtre de confirmation de suppression -->
@if (showPopup)
{
<div class="divPopup">
@ -32,6 +63,18 @@
</div>
}
<!-- Fenêtre de confirmation d'ajout admin-->
@if (showPopupAdmin)
{
<div class="divPopup">
<div class="contentPopup">
<p>Êtes-vous sûr de vouloir changer le rôle de cet utilisateur ?</p>
<button @onclick="() => Admin()">Confirmer</button>
<button @onclick="ClosePopupAdmin">Annuler</button>
</div>
</div>
}
}
else

@ -11,6 +11,9 @@ namespace WF_WebAdmin.Pages
private bool showPopup = false;
private User userToDelete = null;
private bool showPopupAdmin = false;
private User userToAdmin = null;
[Inject]
public HttpClient Http { get; set; }
@ -27,7 +30,6 @@ namespace WF_WebAdmin.Pages
private void ShowConfirmation(User user)
{
// Afficher la modale et mémoriser l'utilisateur à supprimer
userToDelete = user;
showPopup = true;
}
@ -47,6 +49,39 @@ namespace WF_WebAdmin.Pages
{
showPopup = false;
}
private void ShowConfirmationAdmin(User user)
{
userToAdmin = user;
showPopupAdmin = true;
}
private async Task Admin()
{
if (!userToAdmin.IsAdmin)
{
userToAdmin.IsAdmin = true;
ClosePopupAdmin();
}
else
{
userToAdmin.IsAdmin = false;
ClosePopupAdmin();
}
}
private void ClosePopupAdmin()
{
showPopupAdmin = false;
}
}
}

@ -13,7 +13,7 @@ namespace WF_WebAdmin.Pages
{
// Chaîne de connexion à adapter
private const string connectionString =
"Host=localhost;Port=5432;Database=wikifantasy3;Username=postgres;Password=postgres";
"Host=londres;Port=5432;Database=dbkentin;Username=kentin;Password=passwd";
private List<Quote> quotes;

@ -2,30 +2,161 @@
{
"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": "Demo",
"Email": "demo@gmail.com",
"DateCreation": "2024-12-12"
"Name": "Admin",
"Email": "admin@gmail.com",
"DateCreation": "2024-12-12",
"IsAdmin": true
},
{
"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"
"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"
"DateCreation": "2024-08-02",
"IsAdmin": false
},
{
"Id": 4,
"Image": "https://tse2.mm.bing.net/th/id/OIP.3vXkEUJ9J8s-GsnBC6I3KAHaF0?w=185&h=180&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": "dev",
"Email": "dev@gmail.com",
"DateCreation": "2024-10-10"
"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
},
{
"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
},
{
"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
},
{
"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
},
{
"Id": 17,
"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_olivia",
"Email": "support.olivia@gmail.com",
"DateCreation": "2024-07-30",
"IsAdmin": false
},
{
"Id": 18,
"Image": "https://tse2.mm.bing.net/th/id/OIP.MMpXBB5RDRYQm05FJmevGAHaKl?w=137&h=195&c=7&r=0&o=5&pid=1.7",
"Name": "assistant_jack",
"Email": "assistant.jack@gmail.com",
"DateCreation": "2024-10-03",
"IsAdmin": false
},
{
"Id": 19,
"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_bob",
"Email": "developer.bob@gmail.com",
"DateCreation": "2024-06-01",
"IsAdmin": false
},
{
"Id": 20,
"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_sophie",
"Email": "admin.sophie@gmail.com",
"DateCreation": "2024-12-05",
"IsAdmin": true
}
]
Loading…
Cancel
Save