diff --git a/ProjectLighthouse.Localization/Register.resx b/ProjectLighthouse.Localization/Register.resx
index 15a1183e..1e530f21 100644
--- a/ProjectLighthouse.Localization/Register.resx
+++ b/ProjectLighthouse.Localization/Register.resx
@@ -21,4 +21,7 @@
Caution: Your username MUST match your PSN/RPCN username in order to be able to sign in from in-game.
+
+ You do not have an email set on your account or you have not verified it. You can set an email by opening the text chat and typing "/setemail [youremail@example.com]" (do not include the brackets), then check your inbox for a verification email.
+
\ No newline at end of file
diff --git a/ProjectLighthouse.Localization/StringLists/RegisterStrings.cs b/ProjectLighthouse.Localization/StringLists/RegisterStrings.cs
index c9acf363..85f6f29a 100644
--- a/ProjectLighthouse.Localization/StringLists/RegisterStrings.cs
+++ b/ProjectLighthouse.Localization/StringLists/RegisterStrings.cs
@@ -3,6 +3,7 @@ namespace LBPUnion.ProjectLighthouse.Localization.StringLists;
public static class RegisterStrings
{
public static readonly TranslatableString UsernameNotice = create("username_notice");
+ public static readonly TranslatableString EmailVerificationNotice = create("email_verify_notice");
private static TranslatableString create(string key) => new(TranslationAreas.Register, key);
}
\ No newline at end of file
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs
index 7e3baeb9..53e0afca 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs
@@ -3,6 +3,7 @@ using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using LBPUnion.ProjectLighthouse.Types.Filter;
@@ -29,6 +30,7 @@ public class CommentController : ControllerBase
[HttpPost("rateUserComment/{username}")]
[HttpPost("rateComment/{slotType}/{slotId:int}")]
+ [EmailVerification]
public async Task RateComment([FromQuery] int commentId, [FromQuery] int rating, string? username, string? slotType, int slotId)
{
GameTokenEntity token = this.GetToken();
@@ -113,6 +115,7 @@ public class CommentController : ControllerBase
[HttpPost("postUserComment/{username}")]
[HttpPost("postComment/{slotType}/{slotId:int}")]
+ [EmailVerification]
public async Task PostComment(string? username, string? slotType, int slotId)
{
GameTokenEntity token = this.GetToken();
@@ -152,6 +155,7 @@ public class CommentController : ControllerBase
[HttpPost("deleteUserComment/{username}")]
[HttpPost("deleteComment/{slotType}/{slotId:int}")]
+ [EmailVerification]
public async Task DeleteComment([FromQuery] int commentId, string? username, string? slotType, int slotId)
{
GameTokenEntity token = this.GetToken();
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/FriendsController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/FriendsController.cs
index 83e198d8..49c1df81 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/FriendsController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/FriendsController.cs
@@ -1,6 +1,7 @@
#nullable enable
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Users;
using LBPUnion.ProjectLighthouse.StorableLists.Stores;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
@@ -17,6 +18,7 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
[Authorize]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
+[EmailVerification]
public class FriendsController : ControllerBase
{
private readonly DatabaseContext database;
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Login/ClientConfigurationController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Login/ClientConfigurationController.cs
index f4ed348c..b2a5ba15 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/Login/ClientConfigurationController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/Login/ClientConfigurationController.cs
@@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Users;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Serialization;
@@ -70,6 +71,7 @@ public class ClientConfigurationController : ControllerBase
[HttpPost("privacySettings")]
[Produces("text/xml")]
+ [EmailVerification]
public async Task SetPrivacySetting()
{
UserEntity? user = await this.database.UserFromGameToken(this.GetToken());
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Matching/EnterLevelController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Matching/EnterLevelController.cs
index e8b2aa37..0db8ad44 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/Matching/EnterLevelController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/Matching/EnterLevelController.cs
@@ -2,6 +2,7 @@
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
@@ -16,6 +17,7 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Matching;
[Authorize]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
+[EmailVerification]
public class EnterLevelController : ControllerBase
{
private readonly DatabaseContext database;
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Matching/MatchController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Matching/MatchController.cs
index 2b3b295b..53f46df8 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/Matching/MatchController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/Matching/MatchController.cs
@@ -5,6 +5,7 @@ using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Logging;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using LBPUnion.ProjectLighthouse.Types.Logging;
@@ -21,6 +22,7 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Matching;
[Authorize]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
+[EmailVerification]
public class MatchController : ControllerBase
{
private readonly DatabaseContext database;
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs
index cccc9b48..488c3591 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs
@@ -3,7 +3,6 @@ using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
-using LBPUnion.ProjectLighthouse.Localization;
using LBPUnion.ProjectLighthouse.Localization.StringLists;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Serialization;
@@ -13,6 +12,7 @@ using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using LBPUnion.ProjectLighthouse.Types.Filter;
using LBPUnion.ProjectLighthouse.Types.Logging;
using LBPUnion.ProjectLighthouse.Types.Mail;
+using LBPUnion.ProjectLighthouse.Types.Notifications;
using LBPUnion.ProjectLighthouse.Types.Serialization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -55,16 +55,23 @@ along with this program. If not, see .";
{
GameTokenEntity token = this.GetToken();
- string username = await this.database.UsernameFromGameToken(token);
+ UserEntity? user = await this.database.UserFromGameToken(token);
+ if (user == null) return this.Forbid();
StringBuilder announceText = new(ServerConfiguration.Instance.AnnounceText);
- announceText.Replace("%user", username);
+ announceText.Replace("%user", user.Username);
announceText.Replace("%id", token.UserId.ToString());
+ if (ServerConfiguration.Instance.Mail.RequireEmailVerification)
+ {
+ announceText.Insert(0,
+ RegisterStrings.EmailVerificationNotice.Translate(user.Language) + "\n\n");
+ }
+
if (ServerConfiguration.Instance.UserGeneratedContentLimits.ReadOnlyMode)
{
- announceText.Insert(0, BaseLayoutStrings.ReadOnlyWarn.Translate(LocalizationManager.DefaultLang) + "\n\n");
+ announceText.Insert(0, BaseLayoutStrings.ReadOnlyWarn.Translate(user.Language) + "\n\n");
}
#if DEBUG
@@ -96,6 +103,15 @@ along with this program. If not, see .";
StringBuilder builder = new();
+ UserEntity? user = await this.database.UserFromGameToken(token);
+ if (user?.EmailAddressVerified == false)
+ {
+ GameNotification verifyEmailNotification = new();
+ verifyEmailNotification.Type = NotificationType.ModerationNotification;
+ verifyEmailNotification.Text = RegisterStrings.EmailVerificationNotice.Translate(user.Language);
+ builder.AppendLine(LighthouseSerializer.Serialize(this.HttpContext.RequestServices, verifyEmailNotification));
+ }
+
foreach (NotificationEntity notification in notifications)
{
builder.AppendLine(LighthouseSerializer.Serialize(this.HttpContext.RequestServices,
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/ReportController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/ReportController.cs
index bf5007c3..2e53dd9c 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/ReportController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/ReportController.cs
@@ -5,6 +5,7 @@ using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Helpers;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.Types.Entities.Moderation;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using LBPUnion.ProjectLighthouse.Types.Moderation.Reports;
@@ -18,6 +19,7 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
[Authorize]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
+[EmailVerification]
public class ReportController : ControllerBase
{
private readonly DatabaseContext database;
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Resources/PhotosController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Resources/PhotosController.cs
index 4c73d0a0..2056ba1d 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/Resources/PhotosController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/Resources/PhotosController.cs
@@ -6,6 +6,7 @@ using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Logging;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
@@ -33,6 +34,7 @@ public class PhotosController : ControllerBase
}
[HttpPost("uploadPhoto")]
+ [EmailVerification]
public async Task UploadPhoto()
{
GameTokenEntity token = this.GetToken();
@@ -234,6 +236,7 @@ public class PhotosController : ControllerBase
}
[HttpPost("deletePhoto/{id:int}")]
+ [EmailVerification]
public async Task DeletePhoto(int id)
{
GameTokenEntity token = this.GetToken();
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Resources/ResourcesController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Resources/ResourcesController.cs
index 7231ccaf..8a2995eb 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/Resources/ResourcesController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/Resources/ResourcesController.cs
@@ -1,9 +1,9 @@
-#nullable enable
using System.Text;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Logging;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Misc;
using LBPUnion.ProjectLighthouse.Types.Logging;
using LBPUnion.ProjectLighthouse.Types.Resources;
@@ -52,6 +52,7 @@ public class ResourcesController : ControllerBase
[HttpPost("upload/{hash}/unattributed")]
[HttpPost("upload/{hash}")]
+ [EmailVerification]
public async Task UploadResource(string hash)
{
string assetsDirectory = FileHelper.ResourcePath;
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/LevelTagsController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/LevelTagsController.cs
index 2b069099..34975c0e 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/LevelTagsController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/LevelTagsController.cs
@@ -1,6 +1,7 @@
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
@@ -41,6 +42,7 @@ public class LevelTagsController : ControllerBase
}
[HttpPost("tag/{slotType}/{id:int}")]
+ [EmailVerification]
public async Task PostTag([FromForm(Name = "t")] string tagName, [FromRoute] string slotType, [FromRoute] int id)
{
GameTokenEntity token = this.GetToken();
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PlaylistController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PlaylistController.cs
index 4763708a..69ff9dde 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PlaylistController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PlaylistController.cs
@@ -2,6 +2,7 @@
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using LBPUnion.ProjectLighthouse.Types.Serialization;
@@ -41,6 +42,7 @@ public class PlaylistController : ControllerBase
}
[HttpPost("playlists/{playlistId:int}/delete")]
+ [EmailVerification]
public async Task DeletePlaylist(int playlistId)
{
GameTokenEntity token = this.GetToken();
@@ -60,6 +62,7 @@ public class PlaylistController : ControllerBase
[HttpPost("playlists/{playlistId:int}/slots")]
[HttpPost("playlists/{playlistId:int}/slots/{slotId:int}/delete")]
[HttpPost("playlists/{playlistId:int}/order_slots")]
+ [EmailVerification]
public async Task UpdatePlaylist(int playlistId, int slotId)
{
GameTokenEntity token = this.GetToken();
@@ -124,6 +127,7 @@ public class PlaylistController : ControllerBase
}
[HttpPost("playlists")]
+ [EmailVerification]
public async Task CreatePlaylist()
{
GameTokenEntity token = this.GetToken();
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs
index dfb42c71..7d0b7fc1 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs
@@ -6,6 +6,7 @@ using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
@@ -24,6 +25,7 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
[Authorize]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
+[EmailVerification]
public class PublishController : ControllerBase
{
private readonly DatabaseContext database;
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs
index 3b2a7fbb..ee83e8e3 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs
@@ -3,6 +3,7 @@ using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
@@ -29,6 +30,7 @@ public class ReviewController : ControllerBase
// LBP1 rating
[HttpPost("rate/user/{slotId:int}")]
+ [EmailVerification]
public async Task Rate(int slotId, int rating)
{
GameTokenEntity token = this.GetToken();
@@ -58,6 +60,7 @@ public class ReviewController : ControllerBase
// LBP2 and beyond rating
[HttpPost("dpadrate/user/{slotId:int}")]
+ [EmailVerification]
public async Task DPadRate(int slotId, int rating)
{
GameTokenEntity token = this.GetToken();
@@ -89,6 +92,7 @@ public class ReviewController : ControllerBase
}
[HttpPost("postReview/user/{slotId:int}")]
+ [EmailVerification]
public async Task PostReview(int slotId)
{
GameTokenEntity token = this.GetToken();
@@ -202,6 +206,7 @@ public class ReviewController : ControllerBase
}
[HttpPost("rateReview/user/{slotId:int}/{username}")]
+ [EmailVerification]
public async Task RateReview(int slotId, string username, int rating = 0)
{
GameTokenEntity token = this.GetToken();
@@ -255,6 +260,7 @@ public class ReviewController : ControllerBase
}
[HttpPost("deleteReview/user/{slotId:int}/{username}")]
+ [EmailVerification]
public async Task DeleteReview(int slotId, string username)
{
GameTokenEntity token = this.GetToken();
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs
index a7c41dd6..a789cc24 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs
@@ -3,6 +3,7 @@ using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Logging;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.StorableLists.Stores;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
@@ -42,6 +43,7 @@ public class ScoreController : ControllerBase
[HttpPost("scoreboard/{slotType}/{id:int}")]
[HttpPost("scoreboard/{slotType}/{id:int}/{childId:int}")]
+ [EmailVerification]
public async Task SubmitScore(string slotType, int id, int childId)
{
GameTokenEntity token = this.GetToken();
diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs
index 7301bc52..34254f23 100644
--- a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs
+++ b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs
@@ -6,6 +6,7 @@ using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
+using LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Users;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
@@ -63,6 +64,7 @@ public class UserController : ControllerBase
}
[HttpPost("updateUser")]
+ [EmailVerification]
public async Task UpdateUser()
{
GameTokenEntity token = this.GetToken();
@@ -171,6 +173,7 @@ public class UserController : ControllerBase
[HttpPost("update_my_pins")]
[Produces("text/json")]
+ [EmailVerification]
public async Task UpdateMyPins()
{
UserEntity? user = await this.database.UserFromGameToken(this.GetToken());
diff --git a/ProjectLighthouse.Servers.GameServer/Middlewares/EmailVerificationMiddleware.cs b/ProjectLighthouse.Servers.GameServer/Middlewares/EmailVerificationMiddleware.cs
new file mode 100644
index 00000000..d7c14375
--- /dev/null
+++ b/ProjectLighthouse.Servers.GameServer/Middlewares/EmailVerificationMiddleware.cs
@@ -0,0 +1,47 @@
+using LBPUnion.ProjectLighthouse.Configuration;
+using LBPUnion.ProjectLighthouse.Database;
+using LBPUnion.ProjectLighthouse.Middlewares;
+using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
+using LBPUnion.ProjectLighthouse.Types.Entities.Token;
+using Microsoft.AspNetCore.Http.Features;
+
+namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Middlewares;
+
+public class EmailVerificationAttribute : Attribute;
+
+public class EmailVerificationMiddleware: MiddlewareDBContext
+{
+
+ public EmailVerificationMiddleware(RequestDelegate next) : base(next)
+ {
+
+ }
+
+ public override async Task InvokeAsync(HttpContext context, DatabaseContext database)
+ {
+ if (ServerConfiguration.Instance.Mail.RequireEmailVerification)
+ {
+ Endpoint? endpoint = context.Features.Get()?.Endpoint;
+ EmailVerificationAttribute? attribute = endpoint?.Metadata.GetMetadata();
+
+ if (attribute != null)
+ {
+ GameTokenEntity? gameToken = await database.GameTokenFromRequest(context.Request);
+ if (gameToken == null)
+ {
+ context.Response.StatusCode = 403;
+ context.Abort();
+ return;
+ }
+ UserEntity? user = await database.UserFromGameToken(gameToken);
+ if (!user!.EmailAddressVerified)
+ {
+ context.Response.StatusCode = 401; // 403 will cause a re-auth
+ context.Abort();
+ return;
+ }
+ }
+ }
+ await this.next(context);
+ }
+}
\ No newline at end of file
diff --git a/ProjectLighthouse.Servers.GameServer/Startup/GameServerStartup.cs b/ProjectLighthouse.Servers.GameServer/Startup/GameServerStartup.cs
index 0d372e8f..b37b5d14 100644
--- a/ProjectLighthouse.Servers.GameServer/Startup/GameServerStartup.cs
+++ b/ProjectLighthouse.Servers.GameServer/Startup/GameServerStartup.cs
@@ -106,6 +106,7 @@ public class GameServerStartup
app.UseMiddleware();
app.UseMiddleware();
app.UseMiddleware(computeDigests);
+ app.UseMiddleware();
app.UseMiddleware();
app.UseRouting();
diff --git a/ProjectLighthouse/Configuration/ConfigurationCategories/MailConfiguration.cs b/ProjectLighthouse/Configuration/ConfigurationCategories/MailConfiguration.cs
index 8fa4c153..784ba15b 100644
--- a/ProjectLighthouse/Configuration/ConfigurationCategories/MailConfiguration.cs
+++ b/ProjectLighthouse/Configuration/ConfigurationCategories/MailConfiguration.cs
@@ -17,4 +17,6 @@ public class MailConfiguration
public string Password { get; set; } = "";
public bool UseSSL { get; set; } = true;
+
+ public bool RequireEmailVerification { get; set; } = true;
}
\ No newline at end of file
diff --git a/ProjectLighthouse/Configuration/ServerConfiguration.cs b/ProjectLighthouse/Configuration/ServerConfiguration.cs
index d145495c..1bb7cba2 100644
--- a/ProjectLighthouse/Configuration/ServerConfiguration.cs
+++ b/ProjectLighthouse/Configuration/ServerConfiguration.cs
@@ -11,7 +11,7 @@ public class ServerConfiguration : ConfigurationBase
// This is so Lighthouse can properly identify outdated configurations and update them with newer settings accordingly.
// If you are modifying anything here, this value MUST be incremented.
// Thanks for listening~
- public override int ConfigVersion { get; set; } = 31;
+ public override int ConfigVersion { get; set; } = 32;
public override string ConfigName { get; set; } = "lighthouse.yml";
public string WebsiteListenUrl { get; set; } = "http://localhost:10060";