mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-28 07:58:40 +00:00
Prevent access to GameServer features if email enforcement is enabled and email is unverified
This commit is contained in:
parent
fbe3ceec7c
commit
9e9c96e1a3
3 changed files with 36 additions and 0 deletions
|
@ -22,6 +22,8 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
||||||
public class CommentController : ControllerBase
|
public class CommentController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly DatabaseContext database;
|
private readonly DatabaseContext database;
|
||||||
|
|
||||||
|
private static readonly bool emailEnforcementEnabled = EnforceEmailConfiguration.Instance.EnableEmailEnforcement;
|
||||||
public CommentController(DatabaseContext database)
|
public CommentController(DatabaseContext database)
|
||||||
{
|
{
|
||||||
this.database = database;
|
this.database = database;
|
||||||
|
@ -33,9 +35,13 @@ public class CommentController : ControllerBase
|
||||||
{
|
{
|
||||||
GameTokenEntity token = this.GetToken();
|
GameTokenEntity token = this.GetToken();
|
||||||
|
|
||||||
|
UserEntity? user = await this.database.UserFromGameToken(token);
|
||||||
|
|
||||||
// Return bad request if both are true or both are false
|
// Return bad request if both are true or both are false
|
||||||
if ((slotId == 0 || SlotHelper.IsTypeInvalid(slotType)) == (username == null)) return this.BadRequest();
|
if ((slotId == 0 || SlotHelper.IsTypeInvalid(slotType)) == (username == null)) return this.BadRequest();
|
||||||
|
|
||||||
|
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
||||||
|
|
||||||
bool success = await this.database.RateComment(token.UserId, commentId, rating);
|
bool success = await this.database.RateComment(token.UserId, commentId, rating);
|
||||||
if (!success) return this.BadRequest();
|
if (!success) return this.BadRequest();
|
||||||
|
|
||||||
|
@ -53,6 +59,8 @@ public class CommentController : ControllerBase
|
||||||
|
|
||||||
if ((slotId == 0 || SlotHelper.IsTypeInvalid(slotType)) == (username == null)) return this.BadRequest();
|
if ((slotId == 0 || SlotHelper.IsTypeInvalid(slotType)) == (username == null)) return this.BadRequest();
|
||||||
|
|
||||||
|
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
||||||
|
|
||||||
int originalSlotId = slotId;
|
int originalSlotId = slotId;
|
||||||
|
|
||||||
if (slotType == "developer") slotId = await SlotHelper.GetPlaceholderSlotId(this.database, slotId, SlotType.Developer);
|
if (slotType == "developer") slotId = await SlotHelper.GetPlaceholderSlotId(this.database, slotId, SlotType.Developer);
|
||||||
|
@ -117,9 +125,13 @@ public class CommentController : ControllerBase
|
||||||
{
|
{
|
||||||
GameTokenEntity token = this.GetToken();
|
GameTokenEntity token = this.GetToken();
|
||||||
|
|
||||||
|
UserEntity? user = await this.database.UserFromGameToken(token);
|
||||||
|
|
||||||
// Deny request if in read-only mode
|
// Deny request if in read-only mode
|
||||||
if (ServerConfiguration.Instance.UserGeneratedContentLimits.ReadOnlyMode) return this.BadRequest();
|
if (ServerConfiguration.Instance.UserGeneratedContentLimits.ReadOnlyMode) return this.BadRequest();
|
||||||
|
|
||||||
|
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
||||||
|
|
||||||
GameComment? comment = await this.DeserializeBody<GameComment>();
|
GameComment? comment = await this.DeserializeBody<GameComment>();
|
||||||
if (comment?.Message == null) return this.BadRequest();
|
if (comment?.Message == null) return this.BadRequest();
|
||||||
|
|
||||||
|
@ -156,11 +168,15 @@ public class CommentController : ControllerBase
|
||||||
{
|
{
|
||||||
GameTokenEntity token = this.GetToken();
|
GameTokenEntity token = this.GetToken();
|
||||||
|
|
||||||
|
UserEntity? user = await this.database.UserFromGameToken(token);
|
||||||
|
|
||||||
// Deny request if in read-only mode
|
// Deny request if in read-only mode
|
||||||
if (ServerConfiguration.Instance.UserGeneratedContentLimits.ReadOnlyMode) return this.BadRequest();
|
if (ServerConfiguration.Instance.UserGeneratedContentLimits.ReadOnlyMode) return this.BadRequest();
|
||||||
|
|
||||||
if ((slotId == 0 || SlotHelper.IsTypeInvalid(slotType)) == (username == null)) return this.BadRequest();
|
if ((slotId == 0 || SlotHelper.IsTypeInvalid(slotType)) == (username == null)) return this.BadRequest();
|
||||||
|
|
||||||
|
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
||||||
|
|
||||||
CommentEntity? comment = await this.database.Comments.FirstOrDefaultAsync(c => c.CommentId == commentId);
|
CommentEntity? comment = await this.database.Comments.FirstOrDefaultAsync(c => c.CommentId == commentId);
|
||||||
if (comment == null) return this.NotFound();
|
if (comment == null) return this.NotFound();
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using LBPUnion.ProjectLighthouse.Database;
|
using LBPUnion.ProjectLighthouse.Database;
|
||||||
using LBPUnion.ProjectLighthouse.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
|
using LBPUnion.ProjectLighthouse.Configuration;
|
||||||
|
using LBPUnion.ProjectLighthouse.Migrations;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
|
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Users;
|
using LBPUnion.ProjectLighthouse.Types.Users;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
@ -20,6 +24,8 @@ public class EnterLevelController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly DatabaseContext database;
|
private readonly DatabaseContext database;
|
||||||
|
|
||||||
|
private static readonly bool emailEnforcementEnabled = EnforceEmailConfiguration.Instance.EnableEmailEnforcement;
|
||||||
|
|
||||||
public EnterLevelController(DatabaseContext database)
|
public EnterLevelController(DatabaseContext database)
|
||||||
{
|
{
|
||||||
this.database = database;
|
this.database = database;
|
||||||
|
@ -30,8 +36,13 @@ public class EnterLevelController : ControllerBase
|
||||||
{
|
{
|
||||||
GameTokenEntity token = this.GetToken();
|
GameTokenEntity token = this.GetToken();
|
||||||
|
|
||||||
|
UserEntity? user = await this.database.UserFromGameToken(token);
|
||||||
|
|
||||||
if (SlotHelper.IsTypeInvalid(slotType)) return this.BadRequest();
|
if (SlotHelper.IsTypeInvalid(slotType)) return this.BadRequest();
|
||||||
|
|
||||||
|
// Return bad request on unverified email if enforcement is enabled
|
||||||
|
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
||||||
|
|
||||||
// don't count plays for developer slots
|
// don't count plays for developer slots
|
||||||
if (slotType == "developer") return this.Ok();
|
if (slotType == "developer") return this.Ok();
|
||||||
|
|
||||||
|
@ -100,8 +111,13 @@ public class EnterLevelController : ControllerBase
|
||||||
{
|
{
|
||||||
GameTokenEntity token = this.GetToken();
|
GameTokenEntity token = this.GetToken();
|
||||||
|
|
||||||
|
UserEntity? user = await this.database.UserFromGameToken(token);
|
||||||
|
|
||||||
if (SlotHelper.IsTypeInvalid(slotType)) return this.BadRequest();
|
if (SlotHelper.IsTypeInvalid(slotType)) return this.BadRequest();
|
||||||
|
|
||||||
|
// Return bad request on unverified email if enforcement is enabled
|
||||||
|
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
||||||
|
|
||||||
if (slotType == "developer") return this.Ok();
|
if (slotType == "developer") return this.Ok();
|
||||||
|
|
||||||
SlotEntity? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slotId);
|
SlotEntity? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slotId);
|
||||||
|
|
|
@ -25,6 +25,8 @@ public class MatchController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly DatabaseContext database;
|
private readonly DatabaseContext database;
|
||||||
|
|
||||||
|
private static readonly bool emailEnforcementEnabled = EnforceEmailConfiguration.Instance.EnableEmailEnforcement;
|
||||||
|
|
||||||
public MatchController(DatabaseContext database)
|
public MatchController(DatabaseContext database)
|
||||||
{
|
{
|
||||||
this.database = database;
|
this.database = database;
|
||||||
|
@ -43,6 +45,8 @@ public class MatchController : ControllerBase
|
||||||
UserEntity? user = await this.database.UserFromGameToken(token);
|
UserEntity? user = await this.database.UserFromGameToken(token);
|
||||||
if (user == null) return this.Forbid();
|
if (user == null) return this.Forbid();
|
||||||
|
|
||||||
|
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
||||||
|
|
||||||
await LastContactHelper.SetLastContact(this.database, user, token.GameVersion, token.Platform);
|
await LastContactHelper.SetLastContact(this.database, user, token.GameVersion, token.Platform);
|
||||||
|
|
||||||
// Do not allow matchmaking if it has been disabled
|
// Do not allow matchmaking if it has been disabled
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue