From 143a8c2f8a3eec10950e920d30969e69c8d542b5 Mon Sep 17 00:00:00 2001 From: lebeaulato Date: Wed, 8 Jan 2025 17:32:39 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Ajout=20de=20la=20fonctionnalit=C3=A9,=20ad?= =?UTF-8?q?d=20Admin=20et=20delete=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WF-WebAdmin/WF-WebAdmin/Model/Commentary.cs | 10 ++ WF-WebAdmin/WF-WebAdmin/Model/User.cs | 3 + .../WF-WebAdmin/Pages/DeleteUser.razor | 47 +++++- .../WF-WebAdmin/Pages/DeleteUser.razor.cs | 37 ++++- .../WF-WebAdmin/Pages/ValidQuote.razor.cs | 2 +- .../WF-WebAdmin/wwwroot/fake-dataUser.json | 147 +++++++++++++++++- 6 files changed, 234 insertions(+), 12 deletions(-) create mode 100644 WF-WebAdmin/WF-WebAdmin/Model/Commentary.cs diff --git a/WF-WebAdmin/WF-WebAdmin/Model/Commentary.cs b/WF-WebAdmin/WF-WebAdmin/Model/Commentary.cs new file mode 100644 index 0000000..c3251c3 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Model/Commentary.cs @@ -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; } + } +} diff --git a/WF-WebAdmin/WF-WebAdmin/Model/User.cs b/WF-WebAdmin/WF-WebAdmin/Model/User.cs index d599e5b..05671ab 100644 --- a/WF-WebAdmin/WF-WebAdmin/Model/User.cs +++ b/WF-WebAdmin/WF-WebAdmin/Model/User.cs @@ -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 Comments { get; set; } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor index 47af991..fe1c3fa 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor @@ -14,13 +14,44 @@

Identifiant d'utilisateur : @user.Id

-

Nom d'utilisateur : @user.Name

+ @if (user.IsAdmin) + { +

Nom d'utilisateur : @user.Name (Administrateur)

+ } + else + { +

Nom d'utilisateur : @user.Name

+ } +

Email de l'utilisateur : @user.Email

Date de création de l'utilisateur : @user.DateCreation.ToShortDateString()

+ + @if(user.Comments != null) + { + @foreach (var comment in user.Comments) + { +

Commentaire (@comment.) : @comment.Text

+ } + } + else + { +

Aucun commentaires

+ } + + + @if (!user.IsAdmin) + { + + } + else + { + + } +
} - + @if (showPopup) {
@@ -32,6 +63,18 @@
} + + @if (showPopupAdmin) + { +
+
+

Êtes-vous sûr de vouloir changer le rôle de cet utilisateur ?

+ + +
+
+ } + } else diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs index 0743f27..8c8a98f 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs @@ -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; + } + + } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs index a42112a..5e061c5 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs @@ -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 quotes; diff --git a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataUser.json b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataUser.json index 60632fc..519f6ca 100644 --- a/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataUser.json +++ b/WF-WebAdmin/WF-WebAdmin/wwwroot/fake-dataUser.json @@ -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 } ] \ No newline at end of file From 59a06339be22988b760b4fa09ea6901872b44550 Mon Sep 17 00:00:00 2001 From: lebeaulato Date: Thu, 9 Jan 2025 08:33:55 +0100 Subject: [PATCH 2/2] =?UTF-8?q?fusion=20de=20fonction=20pour=20la=20modif?= =?UTF-8?q?=20du=20r=C3=B4le?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WF-WebAdmin/Pages/DeleteUser.razor | 24 +++++++++---------- .../WF-WebAdmin/Pages/DeleteUser.razor.cs | 23 +++++++----------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor index fe1c3fa..6c180ac 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor @@ -4,9 +4,12 @@

Gestion des utilisateurs

+@if(users == null) +{ +

Aucun utilisateur présent sur le site

+} - -@if (users != null) +else {

Utilisateurs présents:

@foreach (var user in users) @@ -24,7 +27,7 @@ }

Email de l'utilisateur : @user.Email

-

Date de création de l'utilisateur : @user.DateCreation.ToShortDateString()

+

Date de création du compte : @user.DateCreation.ToShortDateString()

@if(user.Comments != null) { @@ -35,7 +38,7 @@ } else { -

Aucun commentaires

+

Aucun commentaire sur le site

} @@ -51,8 +54,8 @@ } - - @if (showPopup) + + @if (showPopupDelete) {
@@ -63,24 +66,21 @@
} - + @if (showPopupAdmin) {

Êtes-vous sûr de vouloir changer le rôle de cet utilisateur ?

- +
} } -else -{ -

Aucun utilisateurs présents sur le site

-} + @code { diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs index 8c8a98f..e2d86dc 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs @@ -9,7 +9,7 @@ namespace WF_WebAdmin.Pages private List users; - private bool showPopup = false; + private bool showPopupDelete = false; private User userToDelete = null; private bool showPopupAdmin = false; @@ -27,11 +27,11 @@ namespace WF_WebAdmin.Pages - + // ------- Popup remove user ------- private void ShowConfirmation(User user) { userToDelete = user; - showPopup = true; + showPopupDelete = true; } @@ -47,13 +47,12 @@ namespace WF_WebAdmin.Pages private void ClosePopup() { - showPopup = false; + showPopupDelete = false; + showPopupAdmin = false; } - - - + // ------- Popup admin ------- private void ShowConfirmationAdmin(User user) { userToAdmin = user; @@ -67,21 +66,15 @@ namespace WF_WebAdmin.Pages if (!userToAdmin.IsAdmin) { userToAdmin.IsAdmin = true; - ClosePopupAdmin(); + ClosePopup(); } else { userToAdmin.IsAdmin = false; - ClosePopupAdmin(); + ClosePopup(); } } - private void ClosePopupAdmin() - { - showPopupAdmin = false; - } - - } }