Resolve "User management" #5

Merged
leon.hoppe merged 4 commits from feature/user-management into dev 2026-01-18 19:36:49 +01:00
23 changed files with 142 additions and 40 deletions
Showing only changes of commit 2d3c973d47 - Show all commits

41
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,41 @@
stages:
- build
- test
- publish
variables:
DOCKER_IMAGE: registry.leon-hoppe.de/leon.hoppe/spotiparty
build:
stage: build
image: mcr.microsoft.com/dotnet/sdk:9.0
script:
- dotnet restore
- dotnet build --configuration Release --no-restore
artifacts:
paths:
- "**/bin/Release"
expire_in: 10 minutes
test:
stage: test
image: mcr.microsoft.com/dotnet/sdk:9.0
script:
- dotnet test --verbosity normal
dependencies:
- build
publish:
stage: publish
tags:
- docker
before_script:
- git lfs pull
script:
- export VERSION=$(echo $CI_COMMIT_TAG | sed 's/^v//')
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin registry.leon-hoppe.de
- docker build -t $DOCKER_IMAGE:$VERSION -t $DOCKER_IMAGE:latest -f SpotiParty.Web/Dockerfile .
- docker push $DOCKER_IMAGE:$VERSION
- docker push $DOCKER_IMAGE:latest
only:
- tags

View File

@@ -4,7 +4,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>fe08e5bf-d119-470a-a4cc-7686f019ce64</UserSecretsId>

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>

View File

@@ -9,7 +9,7 @@
<link rel="stylesheet" href="@Assets["app.css"]"/>
<link rel="stylesheet" href="@Assets["SpotiParty.Web.styles.css"]"/>
<ImportMap/>
<link rel="icon" type="image/png" href="favicon.png"/>
<link rel="icon" href="favicon.ico"/>
<HeadOutlet/>
</head>

View File

@@ -2,8 +2,10 @@
@using SpotiParty.Web.Components.Components
@rendermode InteractiveServer
<PageTitle>SpotiParty</PageTitle>
<header>
<h1>🎵 SpotiParty</h1>
<h1>@(_event?.Name ?? " ")</h1>
<p>Suche ein Lied und füge es zur Warteschlange hinzu</p>
</header>
@@ -27,7 +29,7 @@
</main>
<footer>
<p>SpotiParty © @_currentYear</p>
<p><a href="https://git.leon-hoppe.de/leon.hoppe/spotiparty" target="_blank">SpotiParty</a> © @_currentYear</p>
</footer>
<dialog class="confirm-dialog" style="display: @(_selectedTrack is null ? "none" : "block")">

View File

@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Components;
using Microsoft.EntityFrameworkCore;
using SpotifyAPI.Web;
using SpotiParty.Web.Models;
using SpotiParty.Web.Services;
namespace SpotiParty.Web.Components.Pages;
@@ -9,6 +10,8 @@ public partial class EnqueuePage(AuthorizationHandler authHandler, NavigationMan
[Parameter]
public string EventId { get; set; } = string.Empty;
private Event? _event;
private readonly int _currentYear = DateTime.Now.Year;
private SpotifyClient _client = null!;
@@ -28,22 +31,24 @@ public partial class EnqueuePage(AuthorizationHandler authHandler, NavigationMan
return;
}
var eventEntry = await context.Events
_event = await context.Events
.Include(e => e.Host)
.FirstOrDefaultAsync(e => e.Id == guid);
if (eventEntry is null) {
navigator.NavigateTo("/", forceLoad: true);
return;
}
var now = DateTime.Now;
if (eventEntry.Start > now || eventEntry.End < now) {
if (_event is null) {
navigator.NavigateTo("/", forceLoad: true);
return;
}
var client = await authHandler.ConfigureClient(eventEntry.Host.UserId);
StateHasChanged();
var now = DateTime.Now;
if (_event.Start > now || _event.End < now) {
navigator.NavigateTo("/", forceLoad: true);
return;
}
var client = await authHandler.ConfigureClient(_event.Host.UserId);
if (client is null) {
navigator.NavigateTo("/", forceLoad: true);

View File

@@ -8,6 +8,7 @@
header h1 {
margin: 0;
font-size: 2rem;
height: 2rem;
&:focus {
outline: none;
@@ -63,6 +64,10 @@ footer {
text-align: center;
padding: 0.5rem;
background: var(--color-primary);
a {
color: var(--color-text);
}
}
.confirm-dialog {

View File

@@ -0,0 +1,6 @@
@page "/"
<h3>HomePage</h3>
@code {
}

View File

@@ -0,0 +1 @@

View File

@@ -6,7 +6,7 @@
protected override void OnInitialized() {
base.OnInitialized();
Navigator.NavigateTo("/login", forceLoad: true);
Navigator.NavigateTo("/", forceLoad: true);
}
}

View File

@@ -1,4 +1,4 @@
<Router AppAssembly="typeof(Program).Assembly" NotFoundPage="typeof(Pages.NotFound)">
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="routeData"/>
<FocusOnNavigate RouteData="routeData" Selector="h1"/>

View File

@@ -1,10 +1,10 @@
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["SpotiParty.Web/SpotiParty.Web.csproj", "SpotiParty.Web/"]

View File

@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace SpotiParty.Web.Models;
@@ -6,7 +7,8 @@ public class Event {
[Key]
public Guid Id { get; init; } = Guid.CreateVersion7();
public required User Host { get; set; }
[ForeignKey("host")]
public virtual required User Host { get; set; }
[MaxLength(255)]
public required string Name { get; set; }

View File

@@ -1,4 +1,3 @@
using HopFrame.Core.Callbacks;
using HopFrame.Core.Services;
using HopFrame.Web;
using Microsoft.EntityFrameworkCore;
@@ -9,6 +8,8 @@ using SpotiParty.Web.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddEnvironmentVariables();
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
@@ -44,16 +45,15 @@ builder.Services.AddHopFrame(config => {
.List(false)
.DisplayValue(false)
.SetEditable(false);
table.ShowSearchSuggestions(false);
});
context.Table<Event>()
.SetDisplayName(Guid.NewGuid().ToString())
.Ignore(true);
});
config.AddCustomRepository<EventsDashboardRepo, Event, Guid>(e => e.Id, table => {
//table.SetDisplayName("Events");
table.SetDisplayName("Events");
table.Property(e => e.Id)
.List(false)
@@ -61,18 +61,15 @@ builder.Services.AddHopFrame(config => {
.SetCreatable(false);
table.Property(e => e.Host)
.List(false)
.SetEditable(false)
.SetCreatable(false)
.SetDisplayedProperty(u => u.DisplayName);
table.ShowSearchSuggestions(false);
table.AddCallbackHandler(CallbackType.CreateEntry, async (entry, services) => {
var auth = services.GetRequiredService<DashboardAuthHandler>();
var user = await auth.GetCurrentUser();
entry.Host = user!;
});
});
config.AddPlugin<AdminDashboardPlugin>();
});
var app = builder.Build();
@@ -91,7 +88,7 @@ await using (var scope = app.Services.CreateAsyncScope()) {
app.MapDefaultEndpoints();
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
app.UseStatusCodePagesWithReExecute("/not-found");
//app.UseHttpsRedirection();
app.UseAntiforgery();

View File

@@ -0,0 +1,27 @@
using HopFrame.Core.Config;
using HopFrame.Web.Plugins.Events;
using Microsoft.AspNetCore.Components;
using Microsoft.FluentUI.AspNetCore.Components;
using SpotiParty.Web.Models;
namespace SpotiParty.Web.Services;
public class AdminDashboardPlugin(NavigationManager navigator) {
[HopFrame.Web.Plugins.Annotations.EventHandler]
public void OnTableInitialized(TableInitializedEvent e) {
if (e.Table.TableType != typeof(Event)) return;
e.AddEntityButton(new IconInfo {
Variant = IconVariant.Regular,
Size = IconSize.Size16,
Name = "Open"
}, OnButtonClicked);
}
private void OnButtonClicked(object o, TableConfig config) {
var entity = (Event)o;
navigator.NavigateTo(navigator.BaseUri + $"enqueue/{entity.Id}");
}
}

View File

@@ -5,11 +5,17 @@ using SpotiParty.Web.Models;
namespace SpotiParty.Web.Services;
public sealed class AuthorizationHandler(NavigationManager navigator, DatabaseContext context, ClientSideStorage storage) {
public sealed class AuthorizationHandler(NavigationManager navigator, DatabaseContext context, ClientSideStorage storage, IConfiguration configuration) {
private async Task<(string clientId, string clientSecret)> GetClientSecrets() {
#if DEBUG
var fileLines = await File.ReadAllLinesAsync(Path.Combine(Environment.CurrentDirectory, ".dev-token"));
return (fileLines[0], fileLines[1]);
#endif
#pragma warning disable CS0162 // Unreachable code detected
return (configuration["ClientId"]!, configuration["ClientSecret"]!);
#pragma warning restore CS0162 // Unreachable code detected
}
public async Task<SpotifyClient?> ConfigureClient(Guid userId) {

View File

@@ -29,6 +29,10 @@ public class EventsDashboardRepo(DatabaseContext context, DashboardAuthHandler h
}
public async Task CreateItem(Event item) {
var creator = await handler.GetCurrentUser();
context.Attach(creator!);
item.Host = creator!;
await context.Events.AddAsync(item);
await context.SaveChangesAsync();
}

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<BlazorDisableThrowNavigationException>true</BlazorDisableThrowNavigationException>
@@ -19,11 +19,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="13.0.1" />
<PackageReference Include="HopFrame.Core" Version="3.2.1" />
<PackageReference Include="HopFrame.Web" Version="3.2.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.0">
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.5.2" />
<PackageReference Include="HopFrame.Web" Version="3.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

View File

@@ -2,7 +2,9 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Microsoft.AspNetCore": "Warning",
"HopFrame": "Debug",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
}
},
"DetailedErrors": true

View File

@@ -5,5 +5,7 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ClientId": null,
"ClientSecret": null
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -1,7 +1,10 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005Cleon_005CDocuments_005CProjekte_005CSpotiParty_005CHopFrame_002ECore_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005Cleon_005CDocuments_005CProjekte_005CSpotiParty_005CHopFrame_002EWeb_002Edll/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAspireEFPostgreSqlExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FSourcesCache_003F7b8c93872a6630cad8be31c0bbb3f21ffc274a4e8bf081b76fc09649b93393ee_003FAspireEFPostgreSqlExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEntityFrameworkServiceCollectionExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FSourcesCache_003F93cfc51838b859ffb0d584bc342f1a2c3f0b2ad7f3197ea24cd81b4b845f0_003FEntityFrameworkServiceCollectionExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFullTrack_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F8b91718e15e747bab2ecc54bf74dc11b39600_003Fd5_003F3f30c052_003FFullTrack_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AHopFrameConfigurator_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F4682f2518e994f22b1a441cd50dcbd54f600_003F82_003Fb359f37f_003FHopFrameConfigurator_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIToken_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F8b91718e15e747bab2ecc54bf74dc11b39600_003F9f_003F2fe8c76b_003FIToken_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIUserToken_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F8b91718e15e747bab2ecc54bf74dc11b39600_003F00_003F10e67097_003FIUserToken_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIUserToken_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F8b91718e15e747bab2ecc54bf74dc11b39600_003F00_003F10e67097_003FIUserToken_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AServiceCollectionExtensions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ff0aecc1b9e4e4164a6ba51415eba18fb1fa00_003F0f_003Fdac1d453_003FServiceCollectionExtensions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>