Skip to content

Commit

Permalink
feat: switch from steam to discord authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
kwinkel committed Jun 6, 2024
1 parent 73e5581 commit 945cef1
Show file tree
Hide file tree
Showing 15 changed files with 712 additions and 40 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" "<your-steam-api-key>"
# 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"
```
Expand All @@ -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 <command>
dotn <command>
```
10 changes: 5 additions & 5 deletions src/Application/Accounts/UserSignedIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public class UserSignedInResult : AbstractResult

public class UserSignedInRequest : IRequest<UserSignedInResult>
{
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; }
}
Expand All @@ -33,10 +33,10 @@ public UserSignedInHandler(IDatabaseContext databaseContext)

public async Task<UserSignedInResult> 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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Domain/Accounts/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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; }

Expand Down
4 changes: 2 additions & 2 deletions src/Infrastructure/Accounts/AccountTypeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public void Configure(EntityTypeBuilder<Account> 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");
Expand Down
4 changes: 2 additions & 2 deletions src/Infrastructure/Common/DatabaseContextSeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Character>
{
new(new Character
Expand Down
Loading

0 comments on commit 945cef1

Please sign in to comment.