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 username check to signup form #257

Merged
merged 12 commits into from
Jul 4, 2021
Merged

Add username check to signup form #257

merged 12 commits into from
Jul 4, 2021

Conversation

Coteh
Copy link
Owner

@Coteh Coteh commented Jun 13, 2021

Fixes #14.

When username is available, username field will be green.
Screenshot 2021-06-12 at 21-47-51 simpleimage - Simple Image Upload
When username is not available, username field will be red with error message below.
Screenshot 2021-06-12 at 21-47-43 simpleimage - Simple Image Upload
When long username is submitted, it will look like this. This is acceptable for now.
Screenshot 2021-06-12 at 21-51-20 simpleimage - Simple Image Upload

When other error occurs (e.g. rate limit error), there will be no highlight and no message. It would effectively look like the way it did before. I decided it would be better UX to not show an error in this case.

@codecov
Copy link

codecov bot commented Jun 13, 2021

Codecov Report

Merging #257 (d130133) into development (caec0af) will increase coverage by 1.17%.
The diff coverage is 75.00%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development     #257      +/-   ##
===============================================
+ Coverage        52.66%   53.83%   +1.17%     
===============================================
  Files               14       15       +1     
  Lines             1088     1133      +45     
===============================================
+ Hits               573      610      +37     
- Misses             515      523       +8     
Impacted Files Coverage Δ
lib/database-ops.js 53.87% <57.14%> (+0.27%) ⬆️
lib/routes/route.js 40.69% <72.09%> (+2.77%) ⬆️
lib/util/username.js 100.00% <100.00%> (ø)
lib/util.js 94.54% <0.00%> (-1.82%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update caec0af...d130133. Read the comment docs.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jun 13, 2021

This pull request introduces 1 alert when merging a11af41 into dcb08a9 - view on LGTM.com

new alerts:

  • 1 for Database query built from user-controlled sources

field.classList.add(`input-field-${exists ? "error" : "success"}`);
const label = field.nextElementSibling;
if (label) {
label.innerText = exists ? `${username} is not available` : "";
Copy link
Owner Author

Choose a reason for hiding this comment

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

From UX perspective I think I might actually want to display “username is available” if I’m not adding in checkmark.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done
Screenshot 2021-06-19 at 23-18-18 simpleimage - Simple Image Upload

const server = require("../../lib/server");
const { MongoMemoryServer } = require('mongodb-memory-server');
const { MongoClient } = require("mongodb");
const bcrypt = require("bcrypt");
Copy link
Owner Author

Choose a reason for hiding this comment

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

I think this can be removed.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done

@Coteh Coteh changed the base branch from master to development June 18, 2021 17:05
@Coteh
Copy link
Owner Author

Coteh commented Jun 20, 2021

Also adapted username length check done in #261 to be used in username check endpoint as well. This is how it would look in frontend if user typed too long of a username before signing up:

Screenshot 2021-06-19 at 23-04-34 simpleimage - Simple Image Upload

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jun 20, 2021

This pull request introduces 3 alerts when merging 1d91699 into caec0af - view on LGTM.com

new alerts:

  • 1 for Database query built from user-controlled sources
  • 1 for Unused variable, import, function or class
  • 1 for Type confusion through parameter tampering

- Add message on frontend when username check returns long username error
- Add message when username is available
- Extract username check from database-ops into a separate method, to be used in /register route handler and in /check_username. Ideally controllers should be calling the method, but for now I think having the check be called in route handler is better than in DB method.
- Remove sanitize username and email calls in addUser, which are now useless. Sanitize method to be dealt with in #95
- Add a couple new test cases to check_username to handle username too long and undefined error with username verification
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jun 20, 2021

This pull request introduces 2 alerts when merging 60dcf2f into caec0af - view on LGTM.com

new alerts:

  • 1 for Database query built from user-controlled sources
  • 1 for Type confusion through parameter tampering

Copy link
Owner Author

@Coteh Coteh left a comment

Choose a reason for hiding this comment

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

Also leaving a comment to remind myself to check the codecov and LGTM warnings before merging.

assets/js/main.js Outdated Show resolved Hide resolved
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jun 27, 2021

This pull request introduces 2 alerts when merging 2fba9e8 into caec0af - view on LGTM.com

new alerts:

  • 1 for Database query built from user-controlled sources
  • 1 for Type confusion through parameter tampering

…ndUser

- Also add test to check_username to ensure that setting up a MongoDB query with $ character will not work
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jun 28, 2021

This pull request introduces 1 alert when merging 4b68922 into caec0af - view on LGTM.com

new alerts:

  • 1 for Type confusion through parameter tampering

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jul 3, 2021

This pull request introduces 1 alert when merging 460abfb into caec0af - view on LGTM.com

new alerts:

  • 1 for Type confusion through parameter tampering

Coteh added 2 commits July 3, 2021 19:36
…e first one passed.

I believe the LGTM check here https://lgtm.com/projects/g/Coteh/simpleimage/rev/pr-f9f55bc57545265fe0b92210ec390456e24bab06 is a false positive. Previous commit prevents arrays from reaching the verifyUsername call. Nonetheless, I have also added this extra handle after looking into this further. I think it would make sense to only check the first username passed in, if multiple were passed in. User should not be passing in multiple usernames ideally, though.
--inspect-brk, unlike --inspect, breaks on start of execution of the script. Seems like this was preventing execution of the line that starts the server. By changing it to --inspect, things are working as expected now.
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jul 3, 2021

This pull request introduces 1 alert when merging ce0984b into caec0af - view on LGTM.com

new alerts:

  • 1 for Type confusion through parameter tampering

Copy link
Owner Author

@Coteh Coteh left a comment

Choose a reason for hiding this comment

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

The final LGTM alert appears to be false positive. Non-string username parameters should not make it to the verifyUsername check. The handler will either reject it outright, or in the case of an array, will take the first element only and check that one.

Everything else looks good, will merge it in.

… are passed into it. Also rename the function to isValidUsername and add unit tests.
Copy link
Owner Author

@Coteh Coteh left a comment

Choose a reason for hiding this comment

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

Fixed LGTM alert with another check for username type in the util function itself, and added unit tests as well.

@Coteh Coteh merged commit 341df34 into development Jul 4, 2021
@Coteh Coteh deleted the check-username branch July 4, 2021 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check for username after username is typed in register screen
1 participant