Added hopframe backend
This commit is contained in:
@@ -22,6 +22,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
await AuthHandler.HandleCallback(Code);
|
await AuthHandler.HandleCallback(Code);
|
||||||
Navigator.NavigateTo("/enqueue", forceLoad: true);
|
Navigator.NavigateTo("/admin", forceLoad: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<main>
|
<main>
|
||||||
<form class="search-section" @onsubmit="ExecuteSearch">
|
<form class="search-section" @onsubmit="ExecuteSearch">
|
||||||
<input type="text" id="searchInput" placeholder="Song oder Künstler suchen..." @onchange="e => _searchText = e.Value!.ToString()!">
|
<input type="search" id="searchInput" placeholder="Song oder Künstler suchen..." @onchange="e => _searchText = e.Value!.ToString()!">
|
||||||
<button class="button-primary" type="submit" disabled=@_isLoading>Suchen</button>
|
<button class="button-primary" type="submit" disabled=@_isLoading>Suchen</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
@page "/login"
|
@page "/login"
|
||||||
@using SpotiParty.Web.Services
|
@using SpotiParty.Web.Services
|
||||||
|
|
||||||
<a class="button-primary" href="@_uri">Mit Spotify einloggen</a>
|
|
||||||
|
|
||||||
@inject AuthorizationHandler AuthHandler
|
@inject AuthorizationHandler AuthHandler
|
||||||
|
@inject NavigationManager Navigator
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
|
||||||
private Uri _uri = null!;
|
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync() {
|
protected override async Task OnInitializedAsync() {
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
_uri = await AuthHandler.ConstructLoginUri();
|
var uri = await AuthHandler.ConstructLoginUri();
|
||||||
|
Navigator.NavigateTo(uri.ToString(), forceLoad: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,4 +7,6 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options) : DbCont
|
|||||||
|
|
||||||
public DbSet<User> Users { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
|
public DbSet<Event> Events { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
56
SpotiParty.Web/Migrations/20251130142549_Added Spotify Id.Designer.cs
generated
Normal file
56
SpotiParty.Web/Migrations/20251130142549_Added Spotify Id.Designer.cs
generated
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
using SpotiParty.Web;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SpotiParty.Web.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DatabaseContext))]
|
||||||
|
[Migration("20251130142549_Added Spotify Id")]
|
||||||
|
partial class AddedSpotifyId
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.0")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("SpotiParty.Web.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("DisplayName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.Property<string>("RefreshToken")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.Property<string>("SpotifyUserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.HasKey("UserId");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
30
SpotiParty.Web/Migrations/20251130142549_Added Spotify Id.cs
Normal file
30
SpotiParty.Web/Migrations/20251130142549_Added Spotify Id.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SpotiParty.Web.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddedSpotifyId : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "SpotifyUserId",
|
||||||
|
table: "Users",
|
||||||
|
type: "character varying(255)",
|
||||||
|
maxLength: 255,
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "SpotifyUserId",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
59
SpotiParty.Web/Migrations/20251130170930_Added admin property.Designer.cs
generated
Normal file
59
SpotiParty.Web/Migrations/20251130170930_Added admin property.Designer.cs
generated
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
using SpotiParty.Web;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SpotiParty.Web.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DatabaseContext))]
|
||||||
|
[Migration("20251130170930_Added admin property")]
|
||||||
|
partial class Addedadminproperty
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.0")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("SpotiParty.Web.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("DisplayName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.Property<bool>("IsAdmin")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("RefreshToken")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.Property<string>("SpotifyUserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.HasKey("UserId");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SpotiParty.Web.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Addedadminproperty : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "IsAdmin",
|
||||||
|
table: "Users",
|
||||||
|
type: "boolean",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "IsAdmin",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
99
SpotiParty.Web/Migrations/20251130175629_Added events.Designer.cs
generated
Normal file
99
SpotiParty.Web/Migrations/20251130175629_Added events.Designer.cs
generated
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
using SpotiParty.Web;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SpotiParty.Web.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(DatabaseContext))]
|
||||||
|
[Migration("20251130175629_Added events")]
|
||||||
|
partial class Addedevents
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.0")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("SpotiParty.Web.Models.Event", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("End")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("HostUserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Start")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("HostUserId");
|
||||||
|
|
||||||
|
b.ToTable("Events");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SpotiParty.Web.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("DisplayName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.Property<bool>("IsAdmin")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("RefreshToken")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.Property<string>("SpotifyUserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.HasKey("UserId");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SpotiParty.Web.Models.Event", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SpotiParty.Web.Models.User", "Host")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("HostUserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Host");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
50
SpotiParty.Web/Migrations/20251130175629_Added events.cs
Normal file
50
SpotiParty.Web/Migrations/20251130175629_Added events.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace SpotiParty.Web.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Addedevents : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Events",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
HostUserId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
|
||||||
|
Start = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
End = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Events", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Events_Users_HostUserId",
|
||||||
|
column: x => x.HostUserId,
|
||||||
|
principalTable: "Users",
|
||||||
|
principalColumn: "UserId",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Events_HostUserId",
|
||||||
|
table: "Events",
|
||||||
|
column: "HostUserId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Events");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,35 @@ namespace SpotiParty.Web.Migrations
|
|||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("SpotiParty.Web.Models.Event", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("End")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("HostUserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Start")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("HostUserId");
|
||||||
|
|
||||||
|
b.ToTable("Events");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("SpotiParty.Web.Models.User", b =>
|
modelBuilder.Entity("SpotiParty.Web.Models.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("UserId")
|
b.Property<Guid>("UserId")
|
||||||
@@ -33,15 +62,34 @@ namespace SpotiParty.Web.Migrations
|
|||||||
.HasMaxLength(255)
|
.HasMaxLength(255)
|
||||||
.HasColumnType("character varying(255)");
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.Property<bool>("IsAdmin")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
b.Property<string>("RefreshToken")
|
b.Property<string>("RefreshToken")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasMaxLength(255)
|
.HasMaxLength(255)
|
||||||
.HasColumnType("character varying(255)");
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
|
b.Property<string>("SpotifyUserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(255)
|
||||||
|
.HasColumnType("character varying(255)");
|
||||||
|
|
||||||
b.HasKey("UserId");
|
b.HasKey("UserId");
|
||||||
|
|
||||||
b.ToTable("Users");
|
b.ToTable("Users");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SpotiParty.Web.Models.Event", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SpotiParty.Web.Models.User", "Host")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("HostUserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Host");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
SpotiParty.Web/Models/Event.cs
Normal file
18
SpotiParty.Web/Models/Event.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace SpotiParty.Web.Models;
|
||||||
|
|
||||||
|
public class Event {
|
||||||
|
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
public int Id { get; init; }
|
||||||
|
|
||||||
|
public required User Host { get; init; }
|
||||||
|
|
||||||
|
[MaxLength(255)]
|
||||||
|
public required string Name { get; set; }
|
||||||
|
|
||||||
|
public DateTime Start { get; set; }
|
||||||
|
|
||||||
|
public DateTime End { get; set; }
|
||||||
|
}
|
||||||
@@ -7,8 +7,13 @@ public class User {
|
|||||||
public Guid UserId { get; init; } = Guid.CreateVersion7();
|
public Guid UserId { get; init; } = Guid.CreateVersion7();
|
||||||
|
|
||||||
[MaxLength(255)]
|
[MaxLength(255)]
|
||||||
public string DisplayName { get; init; }
|
public required string SpotifyUserId { get; init; }
|
||||||
|
|
||||||
[MaxLength(255)]
|
[MaxLength(255)]
|
||||||
public string RefreshToken { get; set; }
|
public required string DisplayName { get; init; }
|
||||||
|
|
||||||
|
[MaxLength(255)]
|
||||||
|
public required string RefreshToken { get; set; }
|
||||||
|
|
||||||
|
public bool IsAdmin { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
|
using HopFrame.Core.Services;
|
||||||
|
using HopFrame.Web;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using SpotiParty.Web;
|
using SpotiParty.Web;
|
||||||
using SpotiParty.Web.Components;
|
using SpotiParty.Web.Components;
|
||||||
|
using SpotiParty.Web.Models;
|
||||||
using SpotiParty.Web.Services;
|
using SpotiParty.Web.Services;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@@ -11,9 +14,44 @@ builder.Services.AddRazorComponents()
|
|||||||
|
|
||||||
builder.AddServiceDefaults();
|
builder.AddServiceDefaults();
|
||||||
|
|
||||||
|
builder.Services.AddHttpContextAccessor();
|
||||||
|
builder.Services.AddScoped<ClientSideStorage>();
|
||||||
builder.AddNpgsqlDbContext<DatabaseContext>("SpotiParty");
|
builder.AddNpgsqlDbContext<DatabaseContext>("SpotiParty");
|
||||||
|
builder.Services.AddDbContextFactory<DatabaseContext>(options => {
|
||||||
|
options.UseNpgsql(builder.Configuration.GetConnectionString("SpotiParty"));
|
||||||
|
});
|
||||||
builder.Services.AddScoped<AuthorizationHandler>();
|
builder.Services.AddScoped<AuthorizationHandler>();
|
||||||
|
|
||||||
|
builder.Services.AddScoped<IHopFrameAuthHandler, DashboardAuthHandler>();
|
||||||
|
builder.Services.AddHopFrame(config => {
|
||||||
|
config.SetLoginPage("/login");
|
||||||
|
|
||||||
|
config.AddDbContext<DatabaseContext>(context => {
|
||||||
|
context.Table<User>(table => {
|
||||||
|
table
|
||||||
|
.SetViewPolicy(DashboardAuthHandler.AdminPolicy)
|
||||||
|
.SetCreatePolicy(DashboardAuthHandler.AdminPolicy)
|
||||||
|
.SetUpdatePolicy(DashboardAuthHandler.AdminPolicy)
|
||||||
|
.SetDeletePolicy(DashboardAuthHandler.AdminPolicy);
|
||||||
|
|
||||||
|
table.Property(u => u.RefreshToken)
|
||||||
|
.List(false)
|
||||||
|
.DisplayValue(false)
|
||||||
|
.SetEditable(false);
|
||||||
|
|
||||||
|
table.ShowSearchSuggestions(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
context.Table<Event>(table => {
|
||||||
|
table.Property(e => e.Id)
|
||||||
|
.List(false)
|
||||||
|
.SetEditable(false);
|
||||||
|
|
||||||
|
table.ShowSearchSuggestions(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
@@ -37,6 +75,7 @@ app.UseAntiforgery();
|
|||||||
|
|
||||||
app.MapStaticAssets();
|
app.MapStaticAssets();
|
||||||
app.MapRazorComponents<App>()
|
app.MapRazorComponents<App>()
|
||||||
.AddInteractiveServerRenderMode();
|
.AddInteractiveServerRenderMode()
|
||||||
|
.AddHopFramePages();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using SpotifyAPI.Web;
|
using SpotifyAPI.Web;
|
||||||
using SpotiParty.Web.Models;
|
using SpotiParty.Web.Models;
|
||||||
|
|
||||||
namespace SpotiParty.Web.Services;
|
namespace SpotiParty.Web.Services;
|
||||||
|
|
||||||
public sealed class AuthorizationHandler(NavigationManager navigator, DatabaseContext context) {
|
public sealed class AuthorizationHandler(NavigationManager navigator, DatabaseContext context, ClientSideStorage storage) {
|
||||||
|
|
||||||
private async Task<(string clientId, string clientSecret)> GetClientSecrets() {
|
private async Task<(string clientId, string clientSecret)> GetClientSecrets() {
|
||||||
var fileLines = await File.ReadAllLinesAsync(Path.Combine(Environment.CurrentDirectory, ".dev-token"));
|
var fileLines = await File.ReadAllLinesAsync(Path.Combine(Environment.CurrentDirectory, ".dev-token"));
|
||||||
@@ -45,13 +46,25 @@ public sealed class AuthorizationHandler(NavigationManager navigator, DatabaseCo
|
|||||||
|
|
||||||
var client = new SpotifyClient(response.AccessToken);
|
var client = new SpotifyClient(response.AccessToken);
|
||||||
var spotiUser = await client.UserProfile.Current();
|
var spotiUser = await client.UserProfile.Current();
|
||||||
var user = new User {
|
|
||||||
DisplayName = spotiUser.DisplayName,
|
|
||||||
RefreshToken = response.RefreshToken
|
|
||||||
};
|
|
||||||
|
|
||||||
await context.Users.AddAsync(user);
|
var user = await context.Users.FirstOrDefaultAsync(u => u.SpotifyUserId == spotiUser.Id);
|
||||||
await context.SaveChangesAsync();
|
if (user is null) {
|
||||||
|
user = new User {
|
||||||
|
DisplayName = spotiUser.DisplayName,
|
||||||
|
RefreshToken = response.RefreshToken,
|
||||||
|
SpotifyUserId = spotiUser.Id,
|
||||||
|
IsAdmin = await context.Users.CountAsync() == 0
|
||||||
|
};
|
||||||
|
|
||||||
|
await context.Users.AddAsync(user);
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
user.RefreshToken = response.RefreshToken;
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
storage.SaveUserToken(response.RefreshToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
19
SpotiParty.Web/Services/ClientSideStorage.cs
Normal file
19
SpotiParty.Web/Services/ClientSideStorage.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
namespace SpotiParty.Web.Services;
|
||||||
|
|
||||||
|
public class ClientSideStorage(IHttpContextAccessor accessor) {
|
||||||
|
|
||||||
|
private const string AuthCookieName = "RefreshToken";
|
||||||
|
|
||||||
|
public void SaveUserToken(string token) {
|
||||||
|
accessor.HttpContext?.Response.Cookies.Append(AuthCookieName, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? GetUserToken() {
|
||||||
|
return accessor.HttpContext?.Request.Cookies[AuthCookieName];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteUserToken() {
|
||||||
|
accessor.HttpContext?.Response.Cookies.Delete(AuthCookieName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
37
SpotiParty.Web/Services/DashboardAuthHandler.cs
Normal file
37
SpotiParty.Web/Services/DashboardAuthHandler.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using HopFrame.Core.Services;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace SpotiParty.Web.Services;
|
||||||
|
|
||||||
|
public class DashboardAuthHandler(ClientSideStorage storage, IDbContextFactory<DatabaseContext> contextFactory) : IHopFrameAuthHandler {
|
||||||
|
|
||||||
|
public const string AdminPolicy = "ADMIN";
|
||||||
|
|
||||||
|
public async Task<bool> IsAuthenticatedAsync(string? policy) {
|
||||||
|
var token = storage.GetUserToken();
|
||||||
|
if (string.IsNullOrWhiteSpace(token))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
await using var context = await contextFactory.CreateDbContextAsync();
|
||||||
|
var user = await context.Users.AsNoTracking().FirstOrDefaultAsync(u => u.RefreshToken == token);
|
||||||
|
if (user is null) return false;
|
||||||
|
|
||||||
|
if (policy == AdminPolicy) {
|
||||||
|
return user.IsAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> GetCurrentUserDisplayNameAsync() {
|
||||||
|
var token = storage.GetUserToken();
|
||||||
|
if (string.IsNullOrWhiteSpace(token))
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
await using var context = await contextFactory.CreateDbContextAsync();
|
||||||
|
var user = await context.Users.AsNoTracking().FirstOrDefaultAsync(u => u.RefreshToken == token);
|
||||||
|
if (user is null) return string.Empty;
|
||||||
|
|
||||||
|
return user.DisplayName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="13.0.1" />
|
<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" Version="10.0.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.0">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<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">
|
<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: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_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_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_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></wpf:ResourceDictionary>
|
||||||
Reference in New Issue
Block a user