Validate login request and refactor login handling
This commit is contained in:
@@ -1,12 +1,22 @@
|
||||
using RecNet.Domain.Common;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using RecNet.Domain.Common;
|
||||
|
||||
namespace API.Contracts.Profiles.Requests;
|
||||
|
||||
public class LoginRequest
|
||||
{
|
||||
[Required]
|
||||
public required string AppVersion { get; set; }
|
||||
|
||||
[Required, StringLength(128, MinimumLength = 1)]
|
||||
public required string DeviceId { get; set; }
|
||||
|
||||
[Required]
|
||||
public required string PlatformAuthentication { get; set; }
|
||||
|
||||
[Required, StringLength(50, MinimumLength = 1)]
|
||||
public required string PlatformId { get; set; }
|
||||
|
||||
[EnumDataType(typeof(PlatformType))]
|
||||
public PlatformType PlatformType { get; set; }
|
||||
}
|
||||
@@ -68,10 +68,7 @@ public class ProfileService(
|
||||
if (profile.IsBanned)
|
||||
return LoginProfileResult.Fail("Profile is banned");
|
||||
|
||||
if (auth.Name is not null && profile.Name != auth.Name)
|
||||
profile.SetName(auth.Name);
|
||||
|
||||
profile.AddDeviceId(command.DeviceId);
|
||||
profile.RecordSuccessfulLogin(command.DeviceId, auth.Name);
|
||||
|
||||
await profileRepository.SaveChangesAsync(ct);
|
||||
|
||||
|
||||
@@ -61,6 +61,14 @@ public class Profile
|
||||
DeviceIds.Add(deviceId);
|
||||
}
|
||||
|
||||
public void RecordSuccessfulLogin(string deviceId, string? platformName)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(platformName) && Name != platformName)
|
||||
SetName(platformName);
|
||||
|
||||
AddDeviceId(deviceId);
|
||||
}
|
||||
|
||||
public void Ban()
|
||||
=> IsBanned = true;
|
||||
|
||||
@@ -16,8 +16,18 @@ public class SteamAuthValidator(ISteamAuthService steamAuthService) : IPlatformA
|
||||
string platformId,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var steamParams = JsonSerializer.Deserialize<SteamPlatformAuth>(platformAuthentication);
|
||||
if (steamParams == null)
|
||||
SteamPlatformAuth? steamParams;
|
||||
|
||||
try
|
||||
{
|
||||
steamParams = JsonSerializer.Deserialize<SteamPlatformAuth>(platformAuthentication);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
return PlatformAuthResult.Failure("Invalid authentication");
|
||||
}
|
||||
|
||||
if (steamParams?.AppId is null || string.IsNullOrWhiteSpace(steamParams.Ticket))
|
||||
return PlatformAuthResult.Failure("Invalid authentication");
|
||||
|
||||
var result = await steamAuthService.AuthorizeAsync(steamParams.Ticket, steamParams.AppId.AppId, ct);
|
||||
|
||||
Reference in New Issue
Block a user