mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-28 07:58:40 +00:00
Move everything into middleware
This commit is contained in:
parent
a322a32b38
commit
561e1d4e26
8 changed files with 93 additions and 62 deletions
|
@ -27,8 +27,6 @@ public class PhotosController : ControllerBase
|
|||
{
|
||||
private readonly DatabaseContext database;
|
||||
|
||||
private static readonly bool emailEnforcementEnabled = EnforceEmailConfiguration.Instance.EnableEmailEnforcement;
|
||||
|
||||
public PhotosController(DatabaseContext database)
|
||||
{
|
||||
this.database = database;
|
||||
|
@ -41,9 +39,6 @@ public class PhotosController : ControllerBase
|
|||
UserEntity? user = await this.database.UserFromGameToken(token);
|
||||
if (user == null) return this.Unauthorized();
|
||||
|
||||
// Return bad request on unverified email if enforcement is enabled
|
||||
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
||||
|
||||
// Deny request if in read-only mode
|
||||
if (ServerConfiguration.Instance.UserGeneratedContentLimits.ReadOnlyMode) return this.BadRequest();
|
||||
|
||||
|
@ -181,12 +176,6 @@ public class PhotosController : ControllerBase
|
|||
[HttpGet("photos/{slotType}/{id:int}")]
|
||||
public async Task<IActionResult> SlotPhotos(string slotType, int id, [FromQuery] string? by)
|
||||
{
|
||||
GameTokenEntity token = this.GetToken();
|
||||
UserEntity? user = await this.database.UserFromGameToken(token);
|
||||
|
||||
// Return bad request on unverified email if enforcement is enabled
|
||||
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
||||
|
||||
if (SlotHelper.IsTypeInvalid(slotType)) return this.BadRequest();
|
||||
|
||||
if (slotType == "developer") id = await SlotHelper.GetPlaceholderSlotId(this.database, id, SlotType.Developer);
|
||||
|
@ -248,10 +237,6 @@ public class PhotosController : ControllerBase
|
|||
public async Task<IActionResult> DeletePhoto(int id)
|
||||
{
|
||||
GameTokenEntity token = this.GetToken();
|
||||
UserEntity? user = await this.database.UserFromGameToken(token);
|
||||
|
||||
// Return bad request on unverified email if enforcement is enabled
|
||||
if (emailEnforcementEnabled && !user.EmailAddressVerified) return this.BadRequest();
|
||||
|
||||
PhotoEntity? photo = await this.database.Photos.FirstOrDefaultAsync(p => p.PhotoId == id);
|
||||
if (photo == null) return this.NotFound();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue