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

Add case-insensitive unique constraint on User.username and email #993

Merged
merged 3 commits into from
Sep 16, 2022

Conversation

knolleary
Copy link
Member

Closes #983

It took some digging, but I found a sequelize unit test for adding a unique index that uses the lower function. This means we can add a unique index to the table, without having to add another column:

indexes: [
   { name: 'user_username_lower_unique', fields: [sequelize.fn('lower', sequelize.col('username'))], unique: true }
]

I have tested and verified this constrain works as required on both sqlite and postgres.

Alongside this, I've updated the User.byUsername/email getter functions to do case insensitive queries and improved the feedback in the Admin Create User page and User Registration page.

Copy link
Contributor

@hardillb hardillb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the errors from register/user api/v1/users post should be the same?

forge/routes/auth/index.js Show resolved Hide resolved
forge/routes/auth/index.js Show resolved Hide resolved
@hardillb
Copy link
Contributor

I'm going to merge this. I'm 99.9% sure the tests are a GH artefact that this point in time.

@hardillb hardillb merged commit 5540087 into main Sep 16, 2022
@Steve-Mcl Steve-Mcl deleted the prevent-dupe-usernames branch September 30, 2022 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User names can be same (but different case)
2 participants