Skip to content

Commit

Permalink
Enforce lowercase for email addresses
Browse files Browse the repository at this point in the history
Closes #262
  • Loading branch information
jvyden committed Nov 9, 2023
1 parent 376b8fd commit 39c6ea2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
4 changes: 4 additions & 0 deletions Refresh.GameServer/Database/GameDatabaseContext.Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GameUser>().FirstOrDefault(u => u.EmailAddress == emailAddress);
}

Expand Down Expand Up @@ -104,6 +105,9 @@ public void UpdateUserData(GameUser user, ApiUpdateUserRequest data)
user.EmailAddressVerified = false;
});
}

data.EmailAddress = data.EmailAddress?.ToLowerInvariant();

this.UpdateUserData<ApiUpdateUserRequest>(user, data);
}

Expand Down
5 changes: 4 additions & 1 deletion Refresh.GameServer/Database/GameDatabaseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<dynamic>? oldLevels = migration.OldRealm.DynamicApi.All("GameLevel");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 39c6ea2

Please sign in to comment.