community-platform icon indicating copy to clipboard operation
community-platform copied to clipboard

[feature request] prevent signup if username contains invalid characters

Open iSCJT opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. Username that is saved is different to the one entered by the user when joining as all special characters are stripped. e.g. if you used [email protected] as the username in the database it would save seanexamplecom

Describe the solution you'd like I think it's preferable to tell users they can only use certain characters for the username and check this as part of the form validation prior to creating the user.

Describe alternatives you've considered request a display name on the user signup form and then use an auto generated username based on the email address in the background. Where the username currently appears in the ui then show the display name.

Additional context N/A

iSCJT avatar Jun 07 '23 16:06 iSCJT

Hey @AlfonsoGhislieri, Shall I work on this?

professorabhay avatar Jun 18 '23 13:06 professorabhay

@professorabhay please do. I'll assign you to the ticket. Thanks for helping out.

iSCJT avatar Jun 19 '23 07:06 iSCJT

Hey @iSCJT, Can you provide some details about invalid username character ? So, that I can make checks for that

professorabhay avatar Jun 24 '23 04:06 professorabhay

@professorabhay currently we use this function to strip out any special characters: https://github.com/ONEARMY/community-platform/blob/954c5a47fcb89094b10e34cdf4659ae9cfc3a588/src/utils/helpers.ts#L7

So anything that doesn't pass this regex we'd want to highlight to the user signing up that it's invalid and prevent the form being submitted. Thanks.

iSCJT avatar Jun 24 '23 09:06 iSCJT

@professorabhay how are you getting on with this one?

iSCJT avatar Jul 05 '23 08:07 iSCJT

Hey @iSCJT, We can add some more checks and throw an error if case not pass.

export const formatLowerNoSpecial = (text: string) => {
  const strippedText = stripSpecialCharacters(text);
  const lowercaseText = strippedText.toLowerCase();

  // Check if the stripped text is equal to the original text,
  // indicating that no special characters were present.
  if (strippedText !== text) {
    // Display an error message to the user or prevent form submission.
    // For example:
    throw new Error('Invalid characters found in the username. Only letters, numbers, dashes, and underscores are allowed.');
  }

  return lowercaseText;
}

professorabhay avatar Jul 09 '23 02:07 professorabhay

hey @professorabhay - do you want to start a PR for this one? otherwise will remove you as the assignee so other contributors can pick this up

evakill avatar Aug 30 '23 22:08 evakill

It didn't look like any existing PR's had been made for this so I put together #2780.

jgable avatar Sep 13 '23 19:09 jgable

:tada: This issue has been resolved in version 1.104.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

onearmy-bot avatar Oct 03 '23 17:10 onearmy-bot