Add GameVersion domain and login validation

This commit is contained in:
Holden
2026-06-19 15:11:08 -05:00
parent 076fed09f2
commit 2cfc5e7369
31 changed files with 291 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
using RecNet.Application.Common.Tokens;
using RecNet.Domain.Entities.Profiles;
using RecNet.Domain.Profiles;
namespace RecNet.Application.Common.Interfaces;

View File

@@ -7,6 +7,6 @@ public class ApplicationMappingProfile : Profile
{
public ApplicationMappingProfile()
{
CreateMap<Domain.Entities.Profiles.Profile, ProfileDTO>();
CreateMap<Domain.Profiles.Profile, ProfileDTO>();
}
}

View File

@@ -1,5 +1,5 @@
using RecNet.Application.Common.Interfaces;
using RecNet.Domain.Repositories;
using RecNet.Domain.Profiles;
namespace RecNet.Application.Neutrino;

View File

@@ -3,6 +3,7 @@ using RecNet.Domain.Common;
namespace RecNet.Application.Profiles;
public sealed record LoginProfileCommand(
string AppVersion,
string DeviceId,
PlatformType PlatformType,
string PlatformId,

View File

@@ -1,5 +1,5 @@
using RecNet.Application.Common.Interfaces;
using RecNet.Domain.Entities.Profiles.Names;
using RecNet.Domain.Profiles.Names;
namespace RecNet.Application.Profiles;

View File

@@ -1,16 +1,18 @@
using AutoMapper;
using RecNet.Application.Common.Interfaces;
using RecNet.Domain.Repositories;
using ProfileEntity = RecNet.Domain.Entities.Profiles.Profile;
using RecNet.Domain.GameVersions;
using RecNet.Domain.Profiles;
using ProfileEntity = RecNet.Domain.Profiles.Profile;
namespace RecNet.Application.Profiles;
public class ProfileService(
NameGenerator nameGenerator,
IProfileRepository profileRepository,
ITokenService tokenService,
IConfigService configService,
IEnumerable<IPlatformAuthValidator> validators,
IGameVersionRepository gameVersionRepository,
IProfileRepository profileRepository,
IConfigService configService,
NameGenerator nameGenerator,
ITokenService tokenService,
IMapper mapper) : IProfileService
{
public async Task<ProfileDTO?> GetProfileAsync(Guid profileId, CancellationToken ct = default)
@@ -35,6 +37,15 @@ public class ProfileService(
LoginProfileCommand command,
CancellationToken ct = default)
{
// 1. Validate Game Version
if (string.IsNullOrWhiteSpace(command.AppVersion))
return LoginProfileResult.Fail("App version is required.");
var isValidGameVersion = await gameVersionRepository.IsValidAsync(command.AppVersion, ct);
if (!isValidGameVersion)
return LoginProfileResult.Fail("Invalid app version.");
// 2. Validate Platform Authentication
var validator = validators.FirstOrDefault(x => x.PlatformType == command.PlatformType);
if (validator is null)
return LoginProfileResult.Fail("Invalid platform type");
@@ -48,6 +59,7 @@ public class ProfileService(
if (!auth.Succeeded && !ignoreAuthValidation)
return LoginProfileResult.Fail($"Platform Auth Failed: {auth.Message}");
// 3. Get or Create Profile
var profile = await profileRepository.GetByPlatform(
command.PlatformType,
command.PlatformId,
@@ -67,7 +79,7 @@ public class ProfileService(
if (profile.IsBanned)
return LoginProfileResult.Fail("Profile is banned");
profile.RecordSuccessfulLogin(command.DeviceId, auth.Name);
await profileRepository.SaveChangesAsync(ct);