Id | -Content | -Charactére | -Title Source | -Like | -Langue | -Date Source | -
---|---|---|---|---|---|---|
@quote.Id | -@quote.Content | -@quote.Charac | -@quote.TitleSrc | -@quote.Like | -@quote.Langue | -@quote.DateSrc.ToShortDateString() | -
@quote.Content
+ +Personnage : @quote.Charac
+Source : @quote.TitleSrc
+ +Aucune citation du jour
+} + +($"{NavigationManager.BaseUri}fake-dataQuote.json"); + Dailyquote = await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-dataDailyQuote.json"); + } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor index d586324..24155f1 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor @@ -5,22 +5,58 @@Gestion des utilisateurs
-@if (users != null) +@if(users == null) +{ +Aucun utilisateur présent sur le site
+} + +else {Utilisateurs présents:
@foreach (var user in users) {} - @if (showDeletePopup) + + @if (showPopupDelete) {-
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) + { +▶ Commentaire(s) posté(s) par @user.Name :
+ @foreach (var comment in user.Comments) + { +@comment.DateCreation.ToShortDateString() - @comment.Text
+ } + } + else + { +Aucun commentaire sur le site
+ } + + + + @if (!user.IsAdmin) + { + + } + else + { + + } +} } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs index a42112a..95b04d5 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor.cs @@ -10,130 +10,18 @@ using System.Linq; namespace WF_WebAdmin.Pages { public partial class ValidQuote - { - // Chaîne de connexion à adapter - private const string connectionString = - "Host=localhost;Port=5432;Database=wikifantasy3;Username=postgres;Password=postgres"; + { + private Quote[] quotes; - private List@@ -47,7 +83,18 @@} } -else -{ -Aucun utilisateurs présents sur le site
+ + + @if (showPopupAdmin) + { +++ } + + } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs index bca070f..7dc042d 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs +++ b/WF-WebAdmin/WF-WebAdmin/Pages/DeleteUser.razor.cs @@ -10,8 +10,11 @@ namespace WF_WebAdmin.Pages private bool showDeletePopup = false; private bool showModifyPopup = false; private User userToDelete = null; - private User selectedUser; - + private User selectedUser; + private bool showPopupDelete = false; + private bool showPopupAdmin = false; + private User userToAdmin = null; + [Inject] public HttpClient Http { get; set; } @@ -23,15 +26,20 @@ namespace WF_WebAdmin.Pages protected override async Task OnInitializedAsync() { - userService = new UserServiceStub($"fake-dataUser.json"); + userService = new UserServiceStub($"fake-dataUsers.json"); users = await userService.GetUsersJson(); } private void ShowDeleteConfirmation(User user) + { + + } + + // ------- Popup remove user ------- + private void ShowConfirmation(User user) { - // Afficher la modale et mémoriser l'utilisateur à supprimer userToDelete = user; - showDeletePopup = true; + showPopupDelete = true; } private void ShowModifyConfirmation(User user) @@ -45,7 +53,7 @@ namespace WF_WebAdmin.Pages { if (userToDelete != null) { - userService = new UserServiceStub($"fake-dataUser.json"); + userService = new UserServiceStub($"fake-dataUsers.json"); await userService.DeleteUserJson(userToDelete.Id); ClosePopup(); } @@ -53,7 +61,7 @@ namespace WF_WebAdmin.Pages private async Task ModifyUser() { - userService = new UserServiceStub($"fake-dataUser.json"); + userService = new UserServiceStub($"fake-dataUsers.json"); await userService.UpdateUserJson(selectedUser); ClosePopup(); } @@ -62,7 +70,33 @@ namespace WF_WebAdmin.Pages { showDeletePopup = false; showModifyPopup = false; + showPopupDelete = false; + showPopupAdmin = false; + } + + + // ------- Popup admin ------- + private void ShowConfirmationAdmin(User user) + { + userToAdmin = user; + showPopupAdmin = true; } - } + + + private async Task Admin() + { + if (!userToAdmin.IsAdmin) + { + userToAdmin.IsAdmin = true; + ClosePopup(); + } + else + { + userToAdmin.IsAdmin = false; + ClosePopup(); + } + } + + } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor new file mode 100644 index 0000000..411b655 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor @@ -0,0 +1,29 @@ +@page "/" +@using WF_WebAdmin.Model + +++Êtes-vous sûr de vouloir changer le rôle de cet utilisateur ?
+ + +▶ Connexion ◀
+ ++++ ++ + + + + + + + + + + @ErrorConnexion
+Indice de connexion : admin / admin
+ + +@code { + +} \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor.cs new file mode 100644 index 0000000..0fbc64d --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/Login.razor.cs @@ -0,0 +1,67 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Configuration.UserSecrets; +using WF_WebAdmin.Model; + + + +namespace WF_WebAdmin.Pages +{ + public partial class Login + { + + private UserLogin userLogin = new UserLogin(); + + [Inject] + public UserLogin uLogin { get; set; } + + private string ErrorConnexion; + + private ListusersConnexion; + [Inject] + public HttpClient Http { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + protected override async Task OnInitializedAsync() + { + usersConnexion = await Http.GetFromJsonAsync >($"{NavigationManager.BaseUri}fake-dataUserLogin.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) + { + uLogin.Id = userLogin.Id; + uLogin.Name = user.Name; + uLogin.Image = user.Image; + + NavigationManager.NavigateTo(NavigationManager.BaseUri + "/accueil"); + return; + + } + 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"; + } + } + + } + + } + } +} \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor index ca2883e..cb8f955 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ModifQuote.razor @@ -3,7 +3,7 @@
Corection des citation -Corection des citation
+Correction des citations
Ajouter une recherche
diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/Quiz.razor b/WF-WebAdmin/WF-WebAdmin/Pages/Quiz.razor deleted file mode 100644 index 4a38264..0000000 --- a/WF-WebAdmin/WF-WebAdmin/Pages/Quiz.razor +++ /dev/null @@ -1,4 +0,0 @@ -@page "/Quiz" - - -Quiz
diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor new file mode 100644 index 0000000..db4c5ef --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor @@ -0,0 +1,54 @@ +@page "/ValidQuiz" +@using System.Dynamic +@using WF_WebAdmin.Model + +Quiz à valider
+ +@if (quizzes == null) +{ +Chargement des quiz ...
+} +else +{ +Quizs en attente de validation :
+ ++ +
+ +} \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs new file mode 100644 index 0000000..d907e84 --- /dev/null +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuiz.razor.cs @@ -0,0 +1,43 @@ +using Blazorise.DataGrid; +using Microsoft.AspNetCore.Components; +using WF_WebAdmin.Model; + +namespace WF_WebAdmin.Pages +{ + public partial class ValidQuiz + { + private Quiz[] quizzes; + private int totalQuizzes; + + [Inject] + public HttpClient Http { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + protected override async Task OnInitializedAsync() + { + quizzes = await Http.GetFromJsonAsync+ + + + @foreach (var quiz in quizzes) + { +# +Question +Réponse A +Réponse B +Réponse C +Réponse D +Réponse Correcte +Utilisateur +Actions ++ + } + +@quiz.Id +@quiz.Question +@quiz.AnswerA +@quiz.AnswerB +@quiz.AnswerC +@quiz.AnswerD +@quiz.CAnswer +@quiz.UserProposition ++ + ++($"{NavigationManager.BaseUri}fake-dataQuiz.json"); + } + + private void OnValidButton(Quiz quiz) + { + ValidateQuiz(quiz); + } + + private void ValidateQuiz(Quiz quiz) + { + Console.WriteLine($"Quiz {quiz.Id} validated!"); + } + + private void OnRejectButton(Quiz quiz) + { + RejectQuiz(quiz); + } + + private void RejectQuiz(Quiz quiz) + { + Console.WriteLine($"Quiz {quiz.Id} rejected!"); + } + } +} \ No newline at end of file diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor index da423b0..0f7606d 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor +++ b/WF-WebAdmin/WF-WebAdmin/Pages/ValidQuote.razor @@ -7,10 +7,10 @@ { Chargement des citations...
} -else if (quotes.Count == 0) +@* else if (quotes.Count == 0) {Aucune citation en attente de validation.
-} +} *@ else {Citations en attente de validation :
@@ -21,16 +21,15 @@ elseID : @quote.Id
Contenu : @quote.Content
Langue : @quote.Langue
-Likes : @quote.Like
Personnage : @quote.Charac
Image : @quote.ImgPath
Source : @quote.TitleSrc
Date de source : @quote.DateSrc.ToShortDateString()
-Utilisateur proposition : @quote.UserProposition
+Utilisateur : @quote.UserProposition
- - + @* + *@quotes; + [Inject] + public HttpClient Http { get; set; } - protected override async Task OnInitializedAsync() - { - // On charge toutes les citations dont isValide = false - quotes = await LoadNotValidatedQuotesAsync(); - } - - ///- /// Charge toutes les citations non validées (isValide = false) - /// et mappe les colonnes vers ton modèle. - /// - private async Task> LoadNotValidatedQuotesAsync() - { - var result = new List
(); + [Inject] + public NavigationManager NavigationManager { get; set; } - try - { - using var con = new NpgsqlConnection(connectionString); - await con.OpenAsync(); - - // Sélection des colonnes réellement présentes en DB - // + placeholders pour les autres - var sql = @" - SELECT - id_quote AS Id, - content AS Content, - likes AS ""Like"", - langue AS Langue, - -- Champs pas vraiment en DB : placeholders - '' AS Charac, - '' AS ImgPath, - '' AS TitleSrc, - now() AS DateSrc, - '' AS UserProposition - FROM quote - WHERE isValide = false - "; - - using var cmd = new NpgsqlCommand(sql, con); - using var reader = await cmd.ExecuteReaderAsync(); - - while (await reader.ReadAsync()) - { - var q = new Quote - { - Id = reader.GetInt32(reader.GetOrdinal("Id")), - Content = reader.GetString(reader.GetOrdinal("Content")), - Like = reader.GetInt32(reader.GetOrdinal("Like")), - Langue = reader.GetString(reader.GetOrdinal("Langue")), - // placeholders - Charac = reader.GetString(reader.GetOrdinal("Charac")), - ImgPath = reader.GetString(reader.GetOrdinal("ImgPath")), - TitleSrc = reader.GetString(reader.GetOrdinal("TitleSrc")), - DateSrc = reader.GetDateTime(reader.GetOrdinal("DateSrc")), - UserProposition = reader.GetString(reader.GetOrdinal("UserProposition")) - }; - result.Add(q); - } - } - catch (Exception ex) - { - Console.WriteLine($"[Erreur] LoadNotValidatedQuotesAsync : {ex.Message}"); - } - - return result; - } - - ///- /// Met à jour isValide = true pour la citation. - /// - private async Task ValiderQuote(int quoteId) - { - try - { - using var con = new NpgsqlConnection(connectionString); - await con.OpenAsync(); - - var sql = "UPDATE quote SET isValide = true WHERE id_quote = @Id"; - using var cmd = new NpgsqlCommand(sql, con); - cmd.Parameters.AddWithValue("Id", quoteId); - - int rowsAffected = await cmd.ExecuteNonQueryAsync(); - if (rowsAffected > 0) - { - // Supprime la quote de la liste pour l'enlever de l'affichage - quotes.RemoveAll(q => q.Id == quoteId); - } - } - catch (Exception ex) - { - Console.WriteLine($"[Erreur] ValiderQuote : {ex.Message}"); - } - } - - ///- /// Supprime complètement la citation de la base. - /// - private async Task RejeterQuote(int quoteId) + protected override async Task OnInitializedAsync() { - try - { - using var con = new NpgsqlConnection(connectionString); - await con.OpenAsync(); - - var sql = "DELETE FROM quote WHERE id_quote = @Id"; - using var cmd = new NpgsqlCommand(sql, con); - cmd.Parameters.AddWithValue("Id", quoteId); - - int rowsAffected = await cmd.ExecuteNonQueryAsync(); - if (rowsAffected > 0) - { - quotes.RemoveAll(q => q.Id == quoteId); - } - } - catch (Exception ex) - { - Console.WriteLine($"[Erreur] RejeterQuote : {ex.Message}"); - } + quotes = await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-dataQuote.json"); } } } diff --git a/WF-WebAdmin/WF-WebAdmin/Pages/_Layout.cshtml b/WF-WebAdmin/WF-WebAdmin/Pages/_Layout.cshtml index bc00141..8d65dee 100644 --- a/WF-WebAdmin/WF-WebAdmin/Pages/_Layout.cshtml +++ b/WF-WebAdmin/WF-WebAdmin/Pages/_Layout.cshtml @@ -12,6 +12,7 @@+ @RenderBody() @@ -33,5 +34,6 @@ +