diff --git a/CouchLog/Components/AdminSettings/Pages/Index.razor b/CouchLog/Components/AdminSettings/Pages/Index.razor new file mode 100644 index 0000000..e506207 --- /dev/null +++ b/CouchLog/Components/AdminSettings/Pages/Index.razor @@ -0,0 +1,7 @@ +@page "/AdminSettings" + +

Index

+ +@code { + +} diff --git a/CouchLog/Components/AdminSettings/Pages/UserManagement.razor b/CouchLog/Components/AdminSettings/Pages/UserManagement.razor new file mode 100644 index 0000000..18fa06d --- /dev/null +++ b/CouchLog/Components/AdminSettings/Pages/UserManagement.razor @@ -0,0 +1,177 @@ +@page "/AdminSettings/UserManagement" +@rendermode InteractiveServer + +@using CouchLog.Data +@using Microsoft.AspNetCore.Identity +@using Microsoft.EntityFrameworkCore +@using Microsoft.AspNetCore.Components.QuickGrid + +@inject ApplicationDbContext CouchLogDB +@inject UserManager UserManager +@inject RoleManager RoleManager +@inject AuthenticationStateProvider AuthenticationStateProvider +@inject NavigationManager NavigationManager + +
+

UserManagement

+ + +
+ +
+ + + + + + + @if(context.UserId != currentUserId) + { + + } + + +
+ + + + +@code { + + string newUsername = ""; + string newUserRoleId = ""; + List gridUsers = new(); + List roles = new(); + string? currentUserId; + + protected override async Task OnInitializedAsync() + { + var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + currentUserId = authState.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value; + + var users = await CouchLogDB.Users.ToListAsync(); + roles = await CouchLogDB.Roles.ToListAsync(); + int index = 1; + + gridUsers.Clear(); + + foreach (var user in users) + { + var role = await UserManager.GetRolesAsync(user); + + gridUsers.Add(new UserGridItem + { + Index = index++, + UserId = user.Id, + UserName = user.UserName!, + Role = role.FirstOrDefault() ?? "-" + }); + } + } + + public class UserGridItem + { + public int Index { get; set; } + public string UserId { get; set; } = ""; + public string UserName { get; set; } = ""; + public string Role { get; set; } = ""; + } + + async Task DeleteUser(UserGridItem user) + { + if (user.UserId == currentUserId) + return; + + var identityUser = await UserManager.FindByIdAsync(user.UserId); + + if (identityUser is null) + return; + + var result = await UserManager.DeleteAsync(identityUser); + + if (result.Succeeded) + { + gridUsers.Remove(user); + StateHasChanged(); + } + else + { + // Optional: Fehler anzeigen + } + } + + private async Task CreateUserAsync() + { + // Validierung + if (string.IsNullOrWhiteSpace(newUsername) || string.IsNullOrWhiteSpace(newUserRoleId)) + { + // Fehlermeldung anzeigen oder abbrechen + Console.WriteLine("Bitte Benutzername und Rolle angeben."); + return; + } + + // Hier deine Logik zum Erstellen des Users + var roleIdToUse = newUserRoleId; + var usernameToUse = newUsername; + + ApplicationUser newUser = new ApplicationUser + { + UserName = newUsername, + EmailConfirmed = true + }; + + var result = await UserManager.CreateAsync(newUser, "NewPassword123!"); + + IdentityRole roleName = roles.FirstOrDefault(r => r.Id == newUserRoleId); + + if(result.Succeeded) + { + await UserManager.AddToRoleAsync(newUser, roleName.Name); + } + + // Modal schließen oder Formular zurücksetzen + newUsername = ""; + newUserRoleId = ""; + + NavigationManager.NavigateTo(NavigationManager.Uri, true); + } +} diff --git a/CouchLog/Components/AdminSettings/Pages/_Imports.razor b/CouchLog/Components/AdminSettings/Pages/_Imports.razor new file mode 100644 index 0000000..7ff33ad --- /dev/null +++ b/CouchLog/Components/AdminSettings/Pages/_Imports.razor @@ -0,0 +1,2 @@ +@using CouchLog.Components.AdminSettings.Shared +@layout AdminSettingsLayout \ No newline at end of file diff --git a/CouchLog/Components/AdminSettings/Shared/AdminSettingsLayout.razor b/CouchLog/Components/AdminSettings/Shared/AdminSettingsLayout.razor new file mode 100644 index 0000000..339c95f --- /dev/null +++ b/CouchLog/Components/AdminSettings/Shared/AdminSettingsLayout.razor @@ -0,0 +1,17 @@ +@inherits LayoutComponentBase +@layout CouchLog.Components.Layout.MainLayout + +

Manage CouchLog

+ +
+

+
+
+
+ +
+
+ @Body +
+
+
\ No newline at end of file diff --git a/CouchLog/Components/AdminSettings/Shared/AdminSettingsNavMenu.razor b/CouchLog/Components/AdminSettings/Shared/AdminSettingsNavMenu.razor new file mode 100644 index 0000000..3202bbf --- /dev/null +++ b/CouchLog/Components/AdminSettings/Shared/AdminSettingsNavMenu.razor @@ -0,0 +1,18 @@ +@using Microsoft.AspNetCore.Identity +@using CouchLog.Data + +@inject SignInManager SignInManager + + \ No newline at end of file diff --git a/CouchLog/Components/Layout/MainLayout.razor b/CouchLog/Components/Layout/MainLayout.razor index 78624f3..e188a38 100644 --- a/CouchLog/Components/Layout/MainLayout.razor +++ b/CouchLog/Components/Layout/MainLayout.razor @@ -6,10 +6,6 @@
-
- About -
-
@Body
diff --git a/CouchLog/Components/Pages/AdminSettings.razor b/CouchLog/Components/Pages/AdminSettings.razor deleted file mode 100644 index b9d02ac..0000000 --- a/CouchLog/Components/Pages/AdminSettings.razor +++ /dev/null @@ -1,7 +0,0 @@ -@page "/AdminSettings" - -@using Microsoft.AspNetCore.Authorization - -@attribute [Authorize] - -Admin Settings \ No newline at end of file diff --git a/CouchLog/Components/Pages/GlobalList.razor b/CouchLog/Components/Pages/GlobalList.razor index 050de7b..5444781 100644 --- a/CouchLog/Components/Pages/GlobalList.razor +++ b/CouchLog/Components/Pages/GlobalList.razor @@ -16,6 +16,7 @@ GlobalList
+

Global List

@@ -59,13 +60,17 @@
+ + +
@foreach (var Entity in GlobalEntities) {
-
- + +
+ + }
+
@code @@ -268,4 +291,24 @@ GenreIds.Add(GenreId); } } + + private async Task DeleteEntity(GlobalEntity entity) + { + if(entity.PicturePath != null) + { + try + { + File.Delete(Path.Combine("wwwroot", entity.PicturePath)); + } + catch(Exception) + { + } + } + + CouchLogDB.GlobalEntities.Remove(entity); + + await CouchLogDB.SaveChangesAsync(); + + NavigationManager.NavigateTo(NavigationManager.Uri, true); + } } \ No newline at end of file diff --git a/CouchLog/CouchLog.csproj b/CouchLog/CouchLog.csproj index 4b41fba..cddb734 100644 --- a/CouchLog/CouchLog.csproj +++ b/CouchLog/CouchLog.csproj @@ -58,21 +58,22 @@ - - - + + + + - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/CouchLog/CouchLog.sln b/CouchLog/CouchLog.sln index c459fa5..7f8153c 100644 --- a/CouchLog/CouchLog.sln +++ b/CouchLog/CouchLog.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.14.36511.14 +# Visual Studio Version 18 +VisualStudioVersion = 18.1.11304.174 d18.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CouchLog", "CouchLog.csproj", "{4FBF15C3-5FC5-4605-9EBC-3F7DA1ADC47A}" EndProject diff --git a/CouchLog/wwwroot/Pictures/James Bond Casino Royale_2b7bafde-0d3a-44ca-816f-54da65c2a482.jpg b/CouchLog/wwwroot/Pictures/James Bond Casino Royale_2b7bafde-0d3a-44ca-816f-54da65c2a482.jpg deleted file mode 100644 index c29322f..0000000 Binary files a/CouchLog/wwwroot/Pictures/James Bond Casino Royale_2b7bafde-0d3a-44ca-816f-54da65c2a482.jpg and /dev/null differ diff --git a/CouchLog/wwwroot/Pictures/James_Bond_Casino_Royale_2df9da94-dccd-42aa-a4fd-bd4f354f8655.jpg b/CouchLog/wwwroot/Pictures/James_Bond_Casino_Royale_2df9da94-dccd-42aa-a4fd-bd4f354f8655.jpg deleted file mode 100644 index c29322f..0000000 Binary files a/CouchLog/wwwroot/Pictures/James_Bond_Casino_Royale_2df9da94-dccd-42aa-a4fd-bd4f354f8655.jpg and /dev/null differ diff --git a/CouchLog/wwwroot/Pictures/James_Bond_Casino_Royale_6272acfb-d5b5-4e1c-a28c-38d2cc41393e.jpg b/CouchLog/wwwroot/Pictures/James_Bond_Casino_Royale_6272acfb-d5b5-4e1c-a28c-38d2cc41393e.jpg deleted file mode 100644 index c29322f..0000000 Binary files a/CouchLog/wwwroot/Pictures/James_Bond_Casino_Royale_6272acfb-d5b5-4e1c-a28c-38d2cc41393e.jpg and /dev/null differ diff --git a/CouchLog/wwwroot/Pictures/James_Bond_Casino_Royale_6c6e842a-409a-47e1-b0c7-8c9335438c65.jpg b/CouchLog/wwwroot/Pictures/James_Bond_Casino_Royale_6c6e842a-409a-47e1-b0c7-8c9335438c65.jpg deleted file mode 100644 index c29322f..0000000 Binary files a/CouchLog/wwwroot/Pictures/James_Bond_Casino_Royale_6c6e842a-409a-47e1-b0c7-8c9335438c65.jpg and /dev/null differ diff --git a/CouchLog/wwwroot/Pictures/Robin_Hood_f1e1a307-f81b-4404-b583-d64eb743a49f.jpg b/CouchLog/wwwroot/Pictures/Robin_Hood_f1e1a307-f81b-4404-b583-d64eb743a49f.jpg deleted file mode 100644 index 7c5bcb6..0000000 Binary files a/CouchLog/wwwroot/Pictures/Robin_Hood_f1e1a307-f81b-4404-b583-d64eb743a49f.jpg and /dev/null differ