diff --git a/README.md b/README.md index edd8006..be1f6d8 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,8 @@ A list of dependencies which can be started by using `(docker compose)|(podman-c You need to configure your local secrets which are not meant to be shared among developers using `dotnet user-secrets`. Since the projects do use the same user-secrets-id, we can do it only for the most common project, which is the Migrator: ```sh -# required: the steam-api key -dotnet user-secrets --project src/Migrator set "ELifeRPG:SteamApiKey" "" +# required for Web-UI: discord application secret + dotnet user-secrets --project src/Migrator set "OIDC:Discord:ClientSecret" "foo" # optional: override connection-string to postgresql dotnet user-secrets --project src/Migrator set "ConnectionStrings:Database" "Host=localhost;Database=foo;Username=bar;Password=baz" ``` @@ -47,5 +47,5 @@ dotnet user-secrets --project src/Migrator set "ConnectionStrings:Database" "Hos To use dotnet-ef tool, you need to specify the project and startup project like this: ```sh -dotnet ef --project src/Infrastructure --startup-project src/Migrator +dotn ``` diff --git a/src/Application/Accounts/UserSignedIn.cs b/src/Application/Accounts/UserSignedIn.cs index ac15c7f..f466a4c 100644 --- a/src/Application/Accounts/UserSignedIn.cs +++ b/src/Application/Accounts/UserSignedIn.cs @@ -11,13 +11,13 @@ public class UserSignedInResult : AbstractResult public class UserSignedInRequest : IRequest { - public UserSignedInRequest(long steamId, string accountName) + public UserSignedInRequest(long discordId, string accountName) { - SteamId = steamId; + DiscordId = discordId; AccountName = accountName; } - public long SteamId { get; } + public long DiscordId { get; } public string AccountName { get; } } @@ -33,10 +33,10 @@ public UserSignedInHandler(IDatabaseContext databaseContext) public async Task Handle(UserSignedInRequest request, CancellationToken cancellationToken) { - var account = await _databaseContext.Accounts.SingleOrDefaultAsync(x => x.SteamId == request.SteamId, cancellationToken); + var account = await _databaseContext.Accounts.SingleOrDefaultAsync(x => x.DiscordId == request.DiscordId, cancellationToken); if (account is null) { - account = new Account(request.SteamId); + account = new Account(request.DiscordId); _databaseContext.Accounts.Add(account); await _databaseContext.SaveChangesAsync(cancellationToken); } diff --git a/src/Domain/Accounts/Account.cs b/src/Domain/Accounts/Account.cs index 884ca54..e3b3afb 100644 --- a/src/Domain/Accounts/Account.cs +++ b/src/Domain/Accounts/Account.cs @@ -12,10 +12,10 @@ public Account() { } - public Account(long steamId) + public Account(long discordId) { Id = Guid.NewGuid(); - SteamId = steamId; + DiscordId = discordId; DomainEvents.Add(new AccountCreatedEvent(this)); } @@ -30,7 +30,7 @@ public Account(Guid bohemiaId) public Guid Id { get; init; } - public long SteamId { get; init; } + public long DiscordId { get; init; } public Guid? BohemiaId { get; init; } diff --git a/src/Infrastructure/Accounts/AccountTypeConfiguration.cs b/src/Infrastructure/Accounts/AccountTypeConfiguration.cs index 1eccd0a..e118b40 100644 --- a/src/Infrastructure/Accounts/AccountTypeConfiguration.cs +++ b/src/Infrastructure/Accounts/AccountTypeConfiguration.cs @@ -15,8 +15,8 @@ public void Configure(EntityTypeBuilder builder) builder.HasKey(x => x.Id).HasName("PK_Account_Id"); builder.Property(x => x.Id).HasColumnName("Id"); - builder.Property(x => x.SteamId).HasColumnName("SteamId").IsRequired(); - builder.HasIndex(x => x.SteamId).HasDatabaseName("IDX_Account_SteamId"); + builder.Property(x => x.DiscordId).HasColumnName("DiscordId").IsRequired(); + builder.HasIndex(x => x.DiscordId).HasDatabaseName("IDX_Account_DiscordId"); builder.Property(x => x.BohemiaId).HasColumnName("BohemiaId"); builder.HasIndex(x => x.BohemiaId).HasDatabaseName("IDX_Account_BohemiaId"); diff --git a/src/Infrastructure/Common/DatabaseContextSeed.cs b/src/Infrastructure/Common/DatabaseContextSeed.cs index 02ffc2f..1328fea 100644 --- a/src/Infrastructure/Common/DatabaseContextSeed.cs +++ b/src/Infrastructure/Common/DatabaseContextSeed.cs @@ -11,7 +11,7 @@ namespace ELifeRPG.Infrastructure.Common; public class DatabaseContextSeed { - private const long AccountSteam64Id = 76561198033445663; + private const long AccountDiscordId = 150097863991492608; private static readonly Guid _stateBankId = Guid.Parse("48654229-7f6e-4961-bc2e-52247d10ff22"); private static readonly Guid _characterJonDoeId = Guid.Parse("f408a4bd-cb83-4df5-a6a7-c4c3ddc5e4b2"); private static readonly Guid _stateCompanyId = new CompanyId(Guid.Parse("98a58b46-f9fd-4174-9d35-978fd3e5c41e")).Value; @@ -61,7 +61,7 @@ private static async Task SeedAccountsCharacters(IDatabaseContext context) context.Accounts.Add(new Account { Id = Guid.NewGuid(), - SteamId = AccountSteam64Id, + DiscordId = AccountDiscordId, Characters = new List { new(new Character diff --git a/src/Infrastructure/Migrations/20240606203622_SteamIdToDiscordId.Designer.cs b/src/Infrastructure/Migrations/20240606203622_SteamIdToDiscordId.Designer.cs new file mode 100644 index 0000000..9e7f3da --- /dev/null +++ b/src/Infrastructure/Migrations/20240606203622_SteamIdToDiscordId.Designer.cs @@ -0,0 +1,611 @@ +// +using System; +using ELifeRPG.Infrastructure.Common; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ELifeRPG.Infrastructure.Migrations +{ + [DbContext(typeof(DatabaseContext))] + [Migration("20240606203622_SteamIdToDiscordId")] + partial class SteamIdToDiscordId + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ELifeRPG.Domain.Accounts.Account", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("BohemiaId") + .HasColumnType("uuid") + .HasColumnName("BohemiaId"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("DiscordId") + .HasColumnType("bigint") + .HasColumnName("DiscordId"); + + b.Property("Status") + .HasColumnType("integer") + .HasColumnName("Status"); + + b.HasKey("Id") + .HasName("PK_Account_Id"); + + b.HasIndex("BohemiaId") + .HasDatabaseName("IDX_Account_BohemiaId"); + + b.HasIndex("DiscordId") + .HasDatabaseName("IDX_Account_DiscordId"); + + b.ToTable("Account", (string)null); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Banking.Bank", b => + { + b.Property("Id") + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("FK_Country_Id") + .HasColumnType("uuid"); + + b.Property("Number") + .HasColumnType("integer") + .HasColumnName("Number"); + + b.HasKey("Id") + .HasName("PK_Bank_Id"); + + b.HasIndex("FK_Country_Id"); + + b.HasIndex("Number") + .IsUnique(); + + b.ToTable("Bank", (string)null); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Banking.BankAccount", b => + { + b.Property("Id") + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("Balance") + .HasColumnType("numeric"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("FK_BankCondition_Id") + .HasColumnType("uuid"); + + b.Property("FK_Bank_Id") + .HasColumnType("uuid"); + + b.Property("Number") + .IsRequired() + .HasColumnType("text") + .HasColumnName("Number"); + + b.Property("OwnerId") + .HasColumnType("uuid"); + + b.Property("Type") + .HasColumnType("integer") + .HasColumnName("Type"); + + b.HasKey("Id") + .HasName("PK_BankAccount_Id"); + + b.HasIndex("FK_BankCondition_Id"); + + b.HasIndex("FK_Bank_Id"); + + b.HasIndex("Number") + .IsUnique(); + + b.HasIndex("OwnerId"); + + b.ToTable("BankAccount", (string)null); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Banking.BankAccountBooking", b => + { + b.Property("Id") + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("Amount") + .HasColumnType("numeric") + .HasColumnName("Amount"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("FK_BankAccount_Id") + .HasColumnType("uuid"); + + b.Property("Purpose") + .HasColumnType("text"); + + b.Property("SourceId") + .HasColumnType("uuid"); + + b.Property("Type") + .HasColumnType("integer") + .HasColumnName("Type"); + + b.HasKey("Id") + .HasName("PK_BankAccountBooking_Id"); + + b.HasIndex("FK_BankAccount_Id"); + + b.HasIndex("SourceId"); + + b.ToTable("BankAccountBooking", (string)null); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Banking.BankCondition", b => + { + b.Property("Id") + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("FK_Bank_Id") + .HasColumnType("uuid"); + + b.Property("TransactionFeeBase") + .HasColumnType("numeric") + .HasColumnName("TransactionFeeBase"); + + b.Property("TransactionFeeMultiplier") + .HasColumnType("numeric") + .HasColumnName("TransactionFeeMultiplier"); + + b.HasKey("Id") + .HasName("PK_BankCondition_Id"); + + b.HasIndex("FK_Bank_Id"); + + b.ToTable("BankCondition", (string)null); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Characters.Character", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("AccountId") + .HasColumnType("uuid"); + + b.Property("Cash") + .HasColumnType("numeric"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("WorldPosition") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValue("{\n \"location\": {\n \"x\": 0.0,\n \"y\": 0.0,\n \"z\": 0.0\n },\n \"rotation\": {\n \"a\": 0.0,\n \"b\": 0.0,\n \"c\": 0.0,\n \"d\": 0.0\n }\n}"); + + b.HasKey("Id") + .HasName("PK_Character_Id"); + + b.HasIndex("AccountId"); + + b.ToTable("Character", (string)null); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Characters.Sessions.CharacterSession", b => + { + b.Property("Id") + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("CharacterId") + .HasColumnType("uuid"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("Ended") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id") + .HasName("PK_CharacterSession_Id"); + + b.HasIndex("CharacterId"); + + b.ToTable("CharacterSession", (string)null); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Companies.Company", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("FK_Person_Id") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("Name"); + + b.HasKey("Id") + .HasName("PK_Company_Id"); + + b.HasIndex("FK_Person_Id") + .IsUnique(); + + b.ToTable("Company", (string)null); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Companies.CompanyMembership", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("CharacterId") + .HasColumnType("uuid"); + + b.Property("CompanyId") + .HasColumnType("uuid"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("PositionId") + .HasColumnType("uuid"); + + b.HasKey("Id") + .HasName("PK_CompanyMembership_Id"); + + b.HasIndex("CharacterId"); + + b.HasIndex("CompanyId"); + + b.HasIndex("PositionId"); + + b.ToTable("CompanyMembership", (string)null); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Companies.CompanyPosition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("CompanyId") + .HasColumnType("uuid"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("Name"); + + b.Property("Ordering") + .HasColumnType("integer") + .HasColumnName("Ordering"); + + b.Property("Permissions") + .HasColumnType("integer"); + + b.HasKey("Id") + .HasName("PK_CompanyPosition_Id"); + + b.HasIndex("CompanyId"); + + b.ToTable("CompanyPosition", (string)null); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Countries.Country", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("Code") + .IsRequired() + .HasColumnType("text") + .HasColumnName("Code"); + + b.HasKey("Id") + .HasName("PK_Country_Id"); + + b.HasIndex("Code") + .IsUnique(); + + b.ToTable("Country", (string)null); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Persons.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasColumnName("Id"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("FK_Person_Id") + .HasColumnType("uuid"); + + b.Property("Type") + .HasColumnType("integer"); + + b.HasKey("Id") + .HasName("PK_Person_Id"); + + b.HasIndex("FK_Person_Id") + .IsUnique(); + + b.ToTable("Person", (string)null); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Banking.Bank", b => + { + b.HasOne("ELifeRPG.Domain.Countries.Country", "Country") + .WithMany("Banks") + .HasForeignKey("FK_Country_Id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK_Bank_Country_Id"); + + b.Navigation("Country"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Banking.BankAccount", b => + { + b.HasOne("ELifeRPG.Domain.Banking.BankCondition", "BankCondition") + .WithMany("BankAccounts") + .HasForeignKey("FK_BankCondition_Id") + .HasConstraintName("FK_BankAccount_BankCondition_Id"); + + b.HasOne("ELifeRPG.Domain.Banking.Bank", "Bank") + .WithMany("Accounts") + .HasForeignKey("FK_Bank_Id") + .HasConstraintName("FK_BankAccount_Bank_Id"); + + b.HasOne("ELifeRPG.Domain.Persons.Person", "Owner") + .WithMany() + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Bank"); + + b.Navigation("BankCondition"); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Banking.BankAccountBooking", b => + { + b.HasOne("ELifeRPG.Domain.Banking.BankAccount", "BankAccount") + .WithMany("Bookings") + .HasForeignKey("FK_BankAccount_Id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK_BankAccountBooking_BankAccount_Id"); + + b.HasOne("ELifeRPG.Domain.Banking.BankAccount", "Source") + .WithMany() + .HasForeignKey("SourceId"); + + b.Navigation("BankAccount"); + + b.Navigation("Source"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Banking.BankCondition", b => + { + b.HasOne("ELifeRPG.Domain.Banking.Bank", "Bank") + .WithMany("Conditions") + .HasForeignKey("FK_Bank_Id") + .HasConstraintName("FK_BankCondition_Bank_Id"); + + b.Navigation("Bank"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Characters.Character", b => + { + b.HasOne("ELifeRPG.Domain.Accounts.Account", "Account") + .WithMany("Characters") + .HasForeignKey("AccountId") + .HasConstraintName("FK_Account_Id"); + + b.OwnsOne("ELifeRPG.Domain.Characters.CharacterName", "Name", b1 => + { + b1.Property("CharacterId") + .HasColumnType("uuid"); + + b1.Property("FirstName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasColumnName("FirstName"); + + b1.Property("LastName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasColumnName("LastName"); + + b1.HasKey("CharacterId"); + + b1.ToTable("Character"); + + b1.WithOwner() + .HasForeignKey("CharacterId"); + }); + + b.Navigation("Account"); + + b.Navigation("Name"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Characters.Sessions.CharacterSession", b => + { + b.HasOne("ELifeRPG.Domain.Characters.Character", "Character") + .WithMany("Sessions") + .HasForeignKey("CharacterId") + .HasConstraintName("FK_Character_Id"); + + b.Navigation("Character"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Companies.Company", b => + { + b.HasOne("ELifeRPG.Domain.Persons.Person", "Person") + .WithOne("Company") + .HasForeignKey("ELifeRPG.Domain.Companies.Company", "FK_Person_Id") + .HasConstraintName("FK_Company_Person_Id"); + + b.Navigation("Person"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Companies.CompanyMembership", b => + { + b.HasOne("ELifeRPG.Domain.Characters.Character", "Character") + .WithMany("CompanyMemberships") + .HasForeignKey("CharacterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK_Character_Id"); + + b.HasOne("ELifeRPG.Domain.Companies.Company", "Company") + .WithMany("Memberships") + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK_CompanyMembership_Id"); + + b.HasOne("ELifeRPG.Domain.Companies.CompanyPosition", "Position") + .WithMany() + .HasForeignKey("PositionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Character"); + + b.Navigation("Company"); + + b.Navigation("Position"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Companies.CompanyPosition", b => + { + b.HasOne("ELifeRPG.Domain.Companies.Company", "Company") + .WithMany("Positions") + .HasForeignKey("CompanyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK_Position_Id"); + + b.Navigation("Company"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Persons.Person", b => + { + b.HasOne("ELifeRPG.Domain.Characters.Character", "Character") + .WithOne("Person") + .HasForeignKey("ELifeRPG.Domain.Persons.Person", "FK_Person_Id") + .HasConstraintName("FK_Character_Person_Id"); + + b.Navigation("Character"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Accounts.Account", b => + { + b.Navigation("Characters"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Banking.Bank", b => + { + b.Navigation("Accounts"); + + b.Navigation("Conditions"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Banking.BankAccount", b => + { + b.Navigation("Bookings"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Banking.BankCondition", b => + { + b.Navigation("BankAccounts"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Characters.Character", b => + { + b.Navigation("CompanyMemberships"); + + b.Navigation("Person"); + + b.Navigation("Sessions"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Companies.Company", b => + { + b.Navigation("Memberships"); + + b.Navigation("Positions"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Countries.Country", b => + { + b.Navigation("Banks"); + }); + + modelBuilder.Entity("ELifeRPG.Domain.Persons.Person", b => + { + b.Navigation("Company"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/Migrations/20240606203622_SteamIdToDiscordId.cs b/src/Infrastructure/Migrations/20240606203622_SteamIdToDiscordId.cs new file mode 100644 index 0000000..7356b33 --- /dev/null +++ b/src/Infrastructure/Migrations/20240606203622_SteamIdToDiscordId.cs @@ -0,0 +1,58 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ELifeRPG.Infrastructure.Migrations +{ + /// + public partial class SteamIdToDiscordId : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "SteamId", + table: "Account", + newName: "DiscordId"); + + migrationBuilder.RenameIndex( + name: "IDX_Account_SteamId", + table: "Account", + newName: "IDX_Account_DiscordId"); + + migrationBuilder.AlterColumn( + name: "WorldPosition", + table: "Character", + type: "jsonb", + nullable: false, + defaultValue: "{\n \"location\": {\n \"x\": 0.0,\n \"y\": 0.0,\n \"z\": 0.0\n },\n \"rotation\": {\n \"a\": 0.0,\n \"b\": 0.0,\n \"c\": 0.0,\n \"d\": 0.0\n }\n}", + oldClrType: typeof(string), + oldType: "jsonb", + oldDefaultValue: "{\r\n \"location\": {\r\n \"x\": 0.0,\r\n \"y\": 0.0,\r\n \"z\": 0.0\r\n },\r\n \"rotation\": {\r\n \"a\": 0.0,\r\n \"b\": 0.0,\r\n \"c\": 0.0,\r\n \"d\": 0.0\r\n }\r\n}"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "DiscordId", + table: "Account", + newName: "SteamId"); + + migrationBuilder.RenameIndex( + name: "IDX_Account_DiscordId", + table: "Account", + newName: "IDX_Account_SteamId"); + + migrationBuilder.AlterColumn( + name: "WorldPosition", + table: "Character", + type: "jsonb", + nullable: false, + defaultValue: "{\r\n \"location\": {\r\n \"x\": 0.0,\r\n \"y\": 0.0,\r\n \"z\": 0.0\r\n },\r\n \"rotation\": {\r\n \"a\": 0.0,\r\n \"b\": 0.0,\r\n \"c\": 0.0,\r\n \"d\": 0.0\r\n }\r\n}", + oldClrType: typeof(string), + oldType: "jsonb", + oldDefaultValue: "{\n \"location\": {\n \"x\": 0.0,\n \"y\": 0.0,\n \"z\": 0.0\n },\n \"rotation\": {\n \"a\": 0.0,\n \"b\": 0.0,\n \"c\": 0.0,\n \"d\": 0.0\n }\n}"); + } + } +} diff --git a/src/Infrastructure/Migrations/DatabaseContextModelSnapshot.cs b/src/Infrastructure/Migrations/DatabaseContextModelSnapshot.cs index c0683a6..04e6902 100644 --- a/src/Infrastructure/Migrations/DatabaseContextModelSnapshot.cs +++ b/src/Infrastructure/Migrations/DatabaseContextModelSnapshot.cs @@ -17,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.11") + .HasAnnotation("ProductVersion", "8.0.5") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -36,22 +36,22 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Created") .HasColumnType("timestamp with time zone"); + b.Property("DiscordId") + .HasColumnType("bigint") + .HasColumnName("DiscordId"); + b.Property("Status") .HasColumnType("integer") .HasColumnName("Status"); - b.Property("SteamId") - .HasColumnType("bigint") - .HasColumnName("SteamId"); - b.HasKey("Id") .HasName("PK_Account_Id"); b.HasIndex("BohemiaId") .HasDatabaseName("IDX_Account_BohemiaId"); - b.HasIndex("SteamId") - .HasDatabaseName("IDX_Account_SteamId"); + b.HasIndex("DiscordId") + .HasDatabaseName("IDX_Account_DiscordId"); b.ToTable("Account", (string)null); }); @@ -212,7 +212,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired() .ValueGeneratedOnAdd() .HasColumnType("jsonb") - .HasDefaultValue("{\r\n \"location\": {\r\n \"x\": 0.0,\r\n \"y\": 0.0,\r\n \"z\": 0.0\r\n },\r\n \"rotation\": {\r\n \"a\": 0.0,\r\n \"b\": 0.0,\r\n \"c\": 0.0,\r\n \"d\": 0.0\r\n }\r\n}"); + .HasDefaultValue("{\n \"location\": {\n \"x\": 0.0,\n \"y\": 0.0,\n \"z\": 0.0\n },\n \"rotation\": {\n \"a\": 0.0,\n \"b\": 0.0,\n \"c\": 0.0,\n \"d\": 0.0\n }\n}"); b.HasKey("Id") .HasName("PK_Character_Id"); diff --git a/src/WebUI/Pages/Authentication/Signin.cshtml.cs b/src/WebUI/Pages/Authentication/Signin.cshtml.cs index 99e6117..a095093 100644 --- a/src/WebUI/Pages/Authentication/Signin.cshtml.cs +++ b/src/WebUI/Pages/Authentication/Signin.cshtml.cs @@ -1,6 +1,6 @@ using System.Net; using System.Security.Claims; -using AspNet.Security.OpenId.Steam; +using AspNet.Security.OAuth.Discord; using ELifeRPG.Application.Accounts; using MediatR; using Microsoft.AspNetCore.Authentication; @@ -24,26 +24,26 @@ public async Task OnGet([FromQuery] string? provider, [FromQuery] { if (string.IsNullOrEmpty(provider) && string.IsNullOrEmpty(callback)) { - provider = SteamAuthenticationDefaults.AuthenticationScheme; + provider = DiscordAuthenticationDefaults.AuthenticationScheme; } - if (provider?.Equals(SteamAuthenticationDefaults.AuthenticationScheme, StringComparison.OrdinalIgnoreCase) ?? false) + if (provider?.Equals(DiscordAuthenticationDefaults.AuthenticationScheme, StringComparison.OrdinalIgnoreCase) ?? false) { - var uri = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{HttpContext.Request.PathBase}{HttpContext.Request.Path}?callback={SteamAuthenticationDefaults.AuthenticationScheme}"; + var uri = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{HttpContext.Request.PathBase}{HttpContext.Request.Path}?callback={DiscordAuthenticationDefaults.AuthenticationScheme}"; if (!string.IsNullOrEmpty(redirectUri)) { uri += $"&redirectUri={redirectUri}"; } - return Challenge(new AuthenticationProperties { RedirectUri = uri }, SteamAuthenticationDefaults.AuthenticationScheme); + return Challenge(new AuthenticationProperties { RedirectUri = uri }, DiscordAuthenticationDefaults.AuthenticationScheme); } - if (callback?.Equals(SteamAuthenticationDefaults.AuthenticationScheme, StringComparison.OrdinalIgnoreCase) ?? false) + if (callback?.Equals(DiscordAuthenticationDefaults.AuthenticationScheme, StringComparison.OrdinalIgnoreCase) ?? false) { var identity = User.Identities.First(); var nameIdentifierClaim = identity.Claims.Single(x => x.Type == ClaimTypes.NameIdentifier); var nameClaim = identity.Claims.Single(x => x.Type == ClaimTypes.Name); - await _mediator.Send(new UserSignedInRequest(long.Parse(nameIdentifierClaim.Value[^17..]), nameClaim.Value)); + await _mediator.Send(new UserSignedInRequest(long.Parse(nameIdentifierClaim.Value), nameClaim.Value)); return Redirect($"/{redirectUri ?? string.Empty}"); } diff --git a/src/WebUI/Pages/Errors/Unauthorized.razor b/src/WebUI/Pages/Errors/Unauthorized.razor index fe880e5..5f7d6a5 100644 --- a/src/WebUI/Pages/Errors/Unauthorized.razor +++ b/src/WebUI/Pages/Errors/Unauthorized.razor @@ -14,7 +14,7 @@ - Sign-In with Steam + Sign-In with Discord Back to Home diff --git a/src/WebUI/Pages/Index.razor b/src/WebUI/Pages/Index.razor index 23322a7..bd2cdd3 100644 --- a/src/WebUI/Pages/Index.razor +++ b/src/WebUI/Pages/Index.razor @@ -12,7 +12,7 @@ Sign-Out - Sign-In + Sign-In diff --git a/src/WebUI/Program.cs b/src/WebUI/Program.cs index f02c472..174c35a 100644 --- a/src/WebUI/Program.cs +++ b/src/WebUI/Program.cs @@ -1,4 +1,4 @@ -using AspNet.Security.OpenId.Steam; +using AspNet.Security.OAuth.Discord; using ELifeRPG.Application; using ELifeRPG.Core.WebUI.Shared; using Microsoft.AspNetCore.Authentication.Cookies; @@ -14,7 +14,7 @@ .AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; - options.DefaultChallengeScheme = SteamAuthenticationDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = DiscordAuthenticationDefaults.AuthenticationScheme; }) .AddCookie(options => { @@ -22,10 +22,11 @@ options.LoginPath = "/authentication/sign-in"; options.LogoutPath = "/authentication/sign-out"; }) - .AddSteam(options => + .AddDiscord(options => { options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; - options.ApplicationKey = builder.Configuration.GetValue("ELifeRPG:SteamApiKey"); + options.ClientId = builder.Configuration.GetValue("OIDC:Discord:ClientId")!; + options.ClientSecret = builder.Configuration.GetValue("OIDC:Discord:ClientSecret")!; }); builder.Services.AddAntiforgery(options => diff --git a/src/WebUI/Properties/launchSettings.json b/src/WebUI/Properties/launchSettings.json index 693fce4..a22c150 100644 --- a/src/WebUI/Properties/launchSettings.json +++ b/src/WebUI/Properties/launchSettings.json @@ -5,7 +5,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "https://localhost:7039;http://localhost:5039", + "applicationUrl": "https://localhost:5000", "environmentVariables": { "DOTNET_ENVIRONMENT": "Development" } diff --git a/src/WebUI/WebUI.csproj b/src/WebUI/WebUI.csproj index b42bd70..47be2ed 100644 --- a/src/WebUI/WebUI.csproj +++ b/src/WebUI/WebUI.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/WebUI/appsettings.Development.json b/src/WebUI/appsettings.Development.json index d2fcef5..fc3e0cd 100644 --- a/src/WebUI/appsettings.Development.json +++ b/src/WebUI/appsettings.Development.json @@ -10,7 +10,9 @@ "Database": "Host=localhost;Database=eliferpg;Username=postgres;Password=supersecret", "OpenTelemetryTracingEndpoint": "http://localhost:4317" }, - "ELifeRPG": { - "SteamApiKey": "" + "OIDC": { + "Discord": { + "ClientId": "1248358786268270734" + } } }