mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-28 16:08:38 +00:00
Fix comments and unauthorize null users
This commit is contained in:
parent
7495c41d44
commit
cb6d77203b
3 changed files with 14 additions and 5 deletions
|
@ -36,10 +36,12 @@ public class CommentController : ControllerBase
|
||||||
GameTokenEntity token = this.GetToken();
|
GameTokenEntity token = this.GetToken();
|
||||||
|
|
||||||
UserEntity? user = await this.database.UserFromGameToken(token);
|
UserEntity? user = await this.database.UserFromGameToken(token);
|
||||||
|
if (user == null) return this.Unauthorized();
|
||||||
|
|
||||||
// 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();
|
||||||
|
|
||||||
|
// Return bad request on unverified email if enforcement is enabled
|
||||||
if (emailEnforcementEnabled && !user.EmailAddressVerified) 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);
|
||||||
|
@ -59,6 +61,7 @@ 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();
|
||||||
|
|
||||||
|
// Return bad request on unverified email if enforcement is enabled
|
||||||
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
||||||
|
|
||||||
int originalSlotId = slotId;
|
int originalSlotId = slotId;
|
||||||
|
@ -126,11 +129,13 @@ public class CommentController : ControllerBase
|
||||||
GameTokenEntity token = this.GetToken();
|
GameTokenEntity token = this.GetToken();
|
||||||
|
|
||||||
UserEntity? user = await this.database.UserFromGameToken(token);
|
UserEntity? user = await this.database.UserFromGameToken(token);
|
||||||
|
if (user == null) return this.Unauthorized();
|
||||||
|
|
||||||
// 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();
|
// Return bad request on unverified email if enforcement is enabled
|
||||||
|
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();
|
||||||
|
@ -175,7 +180,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();
|
// Return bad request on unverified email if enforcement is enabled
|
||||||
|
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();
|
||||||
|
|
|
@ -37,11 +37,12 @@ public class EnterLevelController : ControllerBase
|
||||||
GameTokenEntity token = this.GetToken();
|
GameTokenEntity token = this.GetToken();
|
||||||
|
|
||||||
UserEntity? user = await this.database.UserFromGameToken(token);
|
UserEntity? user = await this.database.UserFromGameToken(token);
|
||||||
|
if (user == null) return this.Unauthorized();
|
||||||
|
|
||||||
if (SlotHelper.IsTypeInvalid(slotType)) return this.BadRequest();
|
if (SlotHelper.IsTypeInvalid(slotType)) return this.BadRequest();
|
||||||
|
|
||||||
// Return bad request on unverified email if enforcement is enabled
|
// Return bad request on unverified email if enforcement is enabled
|
||||||
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
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();
|
||||||
|
@ -112,11 +113,12 @@ public class EnterLevelController : ControllerBase
|
||||||
GameTokenEntity token = this.GetToken();
|
GameTokenEntity token = this.GetToken();
|
||||||
|
|
||||||
UserEntity? user = await this.database.UserFromGameToken(token);
|
UserEntity? user = await this.database.UserFromGameToken(token);
|
||||||
|
if (user == null) return this.Unauthorized();
|
||||||
|
|
||||||
if (SlotHelper.IsTypeInvalid(slotType)) return this.BadRequest();
|
if (SlotHelper.IsTypeInvalid(slotType)) return this.BadRequest();
|
||||||
|
|
||||||
// Return bad request on unverified email if enforcement is enabled
|
// Return bad request on unverified email if enforcement is enabled
|
||||||
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
||||||
|
|
||||||
if (slotType == "developer") return this.Ok();
|
if (slotType == "developer") return this.Ok();
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,9 @@ public class MatchController : ControllerBase
|
||||||
GameTokenEntity token = this.GetToken();
|
GameTokenEntity token = this.GetToken();
|
||||||
|
|
||||||
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.Unauthorized();
|
||||||
|
|
||||||
|
// Return bad request on unverified email if enforcement is enabled
|
||||||
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue