Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Enforce case-insensitive username uniqueness #557

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_users" (
"id" TEXT NOT NULL PRIMARY KEY,
"username" TEXT NOT NULL COLLATE NOCASE,
"hashed_password" TEXT NOT NULL,
"is_server_owner" BOOLEAN NOT NULL DEFAULT false,
"avatar_url" TEXT,
"last_login" DATETIME,
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"deleted_at" DATETIME,
"is_locked" BOOLEAN NOT NULL DEFAULT false,
"max_sessions_allowed" INTEGER,
"permissions" TEXT,
"user_preferences_id" TEXT,
CONSTRAINT "users_user_preferences_id_fkey" FOREIGN KEY ("user_preferences_id") REFERENCES "user_preferences" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_users" ("avatar_url", "created_at", "deleted_at", "hashed_password", "id", "is_locked", "is_server_owner", "last_login", "max_sessions_allowed", "permissions", "user_preferences_id", "username") SELECT "avatar_url", "created_at", "deleted_at", "hashed_password", "id", "is_locked", "is_server_owner", "last_login", "max_sessions_allowed", "permissions", "user_preferences_id", "username" FROM "users";
DROP TABLE "users";
ALTER TABLE "new_users" RENAME TO "users";
CREATE UNIQUE INDEX "users_username_key" ON "users"("username");
CREATE UNIQUE INDEX "users_user_preferences_id_key" ON "users"("user_preferences_id");
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const buildSchema = (
.refine(
(value) =>
(!!editingUser && value === editingUser.username) ||
existingUsers.every((user) => user.username !== value),
existingUsers.every((user) => user.username.toLowerCase() !== value.toLowerCase()),
() => ({
message: t(
'settingsScene.server/users.createOrUpdateForm.validation.usernameAlreadyExists',
Expand Down
5 changes: 4 additions & 1 deletion packages/i18n/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,10 @@
}
},
"validation": {
"ageRestrictionTooLow": "Age restriction cannot be less than 0"
"ageRestrictionTooLow": "Age restriction cannot be less than 0",
"missingUsername": "Username is required",
"missingPassword": "Password is required",
"usernameAlreadyExists": "Username already exists"
},
"createSubmitButton": "Create user",
"updateSubmitButton": "Update user"
Expand Down
Loading