Store an additional copy of all usernames in lowercase
This commit is contained in:
parent
b3d8ab2fbd
commit
1689c3da67
@ -238,6 +238,7 @@ public final class APIv3 extends AbstractVerticle {
|
||||
});
|
||||
database.getCollection("users").createIndexes(ImmutableList.of(
|
||||
new IndexModel(new Document("lastUsername", 1)),
|
||||
new IndexModel(new Document("lastUsernameLower", 1)),
|
||||
new IndexModel(new Document("emailToken", 1))
|
||||
), (a, b) -> {
|
||||
});
|
||||
|
@ -41,6 +41,7 @@ public final class User {
|
||||
|
||||
@Getter @Id @JsonSerialize(using = UuidJsonSerializer.class) @JsonDeserialize(using = UuidJsonDeserializer.class) private UUID id;
|
||||
@Getter private String lastUsername;
|
||||
@Getter private String lastUsernameLower;
|
||||
@Getter @ExcludeFromReplies private Map<String, Instant> aliases = new HashMap<>();
|
||||
@Getter @ExcludeFromReplies @Setter private String totpSecret;
|
||||
@Getter @ExcludeFromReplies private String password;
|
||||
@ -148,6 +149,10 @@ public final class User {
|
||||
usersCollection.find(new Document("lastUsername", lastUsername)).first(SyncUtils.vertxWrap(callback));
|
||||
}
|
||||
|
||||
public static void findByLastUsernameLower(String lastUsernameLower, SingleResultCallback<User> callback) {
|
||||
usersCollection.find(new Document("lastUsernameLower", lastUsernameLower)).first(SyncUtils.vertxWrap(callback));
|
||||
}
|
||||
|
||||
public static void findOrCreateByIdGrouped(Map<UUID, String> search, SingleResultCallback<Map<UUID, User>> callback) {
|
||||
usersCollection.find(new Document("_id", new Document("$in", search.keySet()))).into(new LinkedList<>(), SyncUtils.vertxWrap((users, error) -> {
|
||||
if (error != null) {
|
||||
@ -205,6 +210,7 @@ public final class User {
|
||||
public User(UUID id, String lastUsername) {
|
||||
this.id = id;
|
||||
this.lastUsername = lastUsername;
|
||||
this.lastUsernameLower = lastUsername.toLowerCase();
|
||||
this.aliases = new HashMap<>();
|
||||
this.lastSeenAt = Instant.now();
|
||||
this.firstSeenAt = Instant.now();
|
||||
@ -215,6 +221,7 @@ public final class User {
|
||||
public void updateUsername(String newUsername) {
|
||||
this.aliases.put(newUsername, Instant.now());
|
||||
this.lastUsername = newUsername;
|
||||
this.lastUsernameLower = newUsername.toLowerCase();
|
||||
}
|
||||
|
||||
public void checkNameCollisions(SingleResultCallback<Void> callback) {
|
||||
|
@ -22,7 +22,7 @@ public final class GETUsersIdVerifyPassword implements Handler<RoutingContext> {
|
||||
User user = SyncUtils.runBlocking(v -> User.findById(ctx.request().getParam("userId"), v));
|
||||
|
||||
if (user == null) {
|
||||
user = SyncUtils.runBlocking(v -> User.findByLastUsername(ctx.request().getParam("userId"), v));
|
||||
user = SyncUtils.runBlocking(v -> User.findByLastUsernameLower(ctx.request().getParam("userId"), v));
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user