46 lines
1.9 KiB
C#
46 lines
1.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using RecRoomArchive.Models.API.PlatformLogin.Requests;
|
|
using RecRoomArchive.Models.API.PlatformLogin.Responses;
|
|
using RecRoomArchive.Services;
|
|
|
|
namespace RecRoomArchive.Controllers.API.PlatformLogin.V2
|
|
{
|
|
/// <summary>
|
|
/// Used to login to accounts on Rec Room
|
|
/// </summary>
|
|
[Route(template: "api/[controller]/v2")]
|
|
[ApiController]
|
|
public class PlatformLoginController(AppVersionService appVersionService, AccountService accountService, AuthorizationService authorizationService) : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Checks if the appVersion provided is allowed to play (which it most certainly will be unless its a weird build or someone messed with it)
|
|
/// </summary>
|
|
/// <returns>An Ok response if the version is valid, Forbid if it is not. Forbid will yield the client displaying "Rec Room Update Required" soo maybe don't</returns>
|
|
[HttpPost]
|
|
public async Task<ActionResult> Login([FromHeader(Name = "X-Rec-Room-Version")] string appVersion, [FromForm] BaseLoginRequest loginRequest)
|
|
{
|
|
var username = loginRequest.Name ?? string.Empty;
|
|
|
|
var buildTimestamp = loginRequest.BuildTimestamp;
|
|
|
|
// We are going to store the appVersion on login now...
|
|
await appVersionService.StoreAppVersion(appVersion);
|
|
await appVersionService.StoreBuildTimestamp(buildTimestamp);
|
|
|
|
// See if a profile exists yet...
|
|
if(!accountService.AccountExists())
|
|
{
|
|
// ...if not, create it!
|
|
accountService.CreateAccount(username);
|
|
}
|
|
|
|
var accountId = accountService.GetSelfAccountId()!.Value;
|
|
|
|
return Ok(new BaseLoginResponse
|
|
{
|
|
Token = authorizationService.GenerateToken(accountId),
|
|
PlayerId = accountId
|
|
});
|
|
}
|
|
}
|
|
} |