diff --git a/Refresh.GameServer/Database/GameDatabaseContext.Registration.cs b/Refresh.GameServer/Database/GameDatabaseContext.Registration.cs index 257942e6..7623bf77 100644 --- a/Refresh.GameServer/Database/GameDatabaseContext.Registration.cs +++ b/Refresh.GameServer/Database/GameDatabaseContext.Registration.cs @@ -18,6 +18,8 @@ public GameUser CreateUser(string username, string emailAddress, bool skipChecks if (this.IsEmailTaken(emailAddress)) throw new InvalidOperationException("Cannot create a user with an existing email address"); } + + emailAddress = emailAddress.ToLowerInvariant(); GameUser user = new() { diff --git a/Refresh.GameServer/Database/GameDatabaseContext.Users.cs b/Refresh.GameServer/Database/GameDatabaseContext.Users.cs index 1bc9ffc6..d2fed487 100644 --- a/Refresh.GameServer/Database/GameDatabaseContext.Users.cs +++ b/Refresh.GameServer/Database/GameDatabaseContext.Users.cs @@ -35,6 +35,7 @@ public partial class GameDatabaseContext // Users public GameUser? GetUserByEmailAddress(string? emailAddress) { if (emailAddress == null) return null; + emailAddress = emailAddress.ToLowerInvariant(); return this._realm.All().FirstOrDefault(u => u.EmailAddress == emailAddress); } @@ -104,6 +105,9 @@ public void UpdateUserData(GameUser user, ApiUpdateUserRequest data) user.EmailAddressVerified = false; }); } + + data.EmailAddress = data.EmailAddress?.ToLowerInvariant(); + this.UpdateUserData(user, data); } diff --git a/Refresh.GameServer/Database/GameDatabaseProvider.cs b/Refresh.GameServer/Database/GameDatabaseProvider.cs index 1e48e950..10ceffdf 100644 --- a/Refresh.GameServer/Database/GameDatabaseProvider.cs +++ b/Refresh.GameServer/Database/GameDatabaseProvider.cs @@ -32,7 +32,7 @@ protected GameDatabaseProvider(IDateTimeProvider time) this._time = time; } - protected override ulong SchemaVersion => 99; + protected override ulong SchemaVersion => 100; protected override string Filename => "refreshGameServer.realm"; @@ -162,6 +162,9 @@ protected override void Migrate(Migration migration, ulong oldVersion) // In version 94, we added an option to redirect grief reports to photos if (oldVersion < 94) newUser.RedirectGriefReportsToPhotos = false; + + // In version 100, we started enforcing lowercase email addresses + if (oldVersion < 100) newUser.EmailAddress = oldUser.EmailAddress?.ToLowerInvariant(); } IQueryable? oldLevels = migration.OldRealm.DynamicApi.All("GameLevel"); diff --git a/Refresh.GameServer/Endpoints/ApiV3/AuthenticationApiEndpoints.cs b/Refresh.GameServer/Endpoints/ApiV3/AuthenticationApiEndpoints.cs index fa2f90bf..59d80f23 100644 --- a/Refresh.GameServer/Endpoints/ApiV3/AuthenticationApiEndpoints.cs +++ b/Refresh.GameServer/Endpoints/ApiV3/AuthenticationApiEndpoints.cs @@ -140,7 +140,6 @@ public ApiOkResponse SendPasswordResetEmail(RequestContext context, } context.Logger.LogInfo(RefreshContext.PasswordReset, "Sending a password reset request email to {0}.", user.Username); - context.Logger.LogTrace(RefreshContext.PasswordReset, "Generating a reset token for {0}", user.Username); Token token = database.GenerateTokenForUser(user, TokenType.PasswordReset, TokenGame.Website, TokenPlatform.Website); context.Logger.LogTrace(RefreshContext.PasswordReset, "Reset token: {0}", token.TokenData);