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