Add GameVersion domain and login validation
This commit is contained in:
@@ -3,6 +3,7 @@ using RecNet.Domain.Common;
|
||||
namespace RecNet.Application.Profiles;
|
||||
|
||||
public sealed record LoginProfileCommand(
|
||||
string AppVersion,
|
||||
string DeviceId,
|
||||
PlatformType PlatformType,
|
||||
string PlatformId,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using RecNet.Application.Common.Interfaces;
|
||||
using RecNet.Domain.Entities.Profiles.Names;
|
||||
using RecNet.Domain.Profiles.Names;
|
||||
|
||||
namespace RecNet.Application.Profiles;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user