ProjectLighthouse/ProjectLighthouse.Servers.GameServer/Controllers/LogoutController.cs
Josh 64b95e807d
Refactor Database class (#616)
Refactor Database into DatabaseContext
Moved into separate folder so it actually has a namespace instead sitting in the root
2023-02-15 23:54:30 -06:00

43 lines
No EOL
1.2 KiB
C#

using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
[ApiController]
[Authorize]
[Route("LITTLEBIGPLANETPS3_XML/goodbye")]
[Produces("text/xml")]
public class LogoutController : ControllerBase
{
private readonly DatabaseContext database;
public LogoutController(DatabaseContext database)
{
this.database = database;
}
[HttpPost]
public async Task<IActionResult> OnPost()
{
GameToken token = this.GetToken();
User? user = await this.database.UserFromGameToken(token);
if (user == null) return this.StatusCode(403, "");
user.LastLogout = TimeHelper.TimestampMillis;
this.database.GameTokens.RemoveWhere(t => t.TokenId == token.TokenId);
this.database.LastContacts.RemoveWhere(c => c.UserId == token.UserId);
await this.database.SaveChangesAsync();
return this.Ok();
}
}