Skip to content

suggest username when taken on register#32

Open
caoerz-helen wants to merge 1 commit into
CMU-313:mainfrom
caoerz-helen:main
Open

suggest username when taken on register#32
caoerz-helen wants to merge 1 commit into
CMU-313:mainfrom
caoerz-helen:main

Conversation

@caoerz-helen
Copy link
Copy Markdown

@caoerz-helen caoerz-helen commented Feb 2, 2026

Resolves #1

Summary

When a user enters a username that is already taken on the register page, the UI now suggests an alternative username (e.g., test1test11) instead of only showing “Username taken”.


Changes

  • Added two helper functions in public/src/client/register.js:

    • async function isUsernameAvailable(name)
      • Slugifies the name.
      • Uses Promise.allSettled with api.head('/users/bySlug/:slug') and api.head('/groups/:name') to check whether a username or group already exists.
    • async function suggestedUsername(baseSlug)
      • Tries baseSlug + 1..20 and returns the first candidate where isUsernameAvailable returns true.
  • Updated validateUsername(username, callback) to:

    • Keep all existing length and format checks (too short, too long, invalid characters).
    • After those pass, call isUsernameAvailable.
      • If available: call showSuccess as before.
      • If not available:
        • Call suggestedUsername(userslug).
        • If a suggestion is found, show a combined error message:
          • Existing [[error:username-taken]]
          • Plus [[user:username-taken-workaround, <suggestion>]]
        • Mark the input as invalid and set validationError = true.
        • If no suggestion is found, fall back to the original [[error:username-taken]] message.
    • Ensure callback() is still called once validation finishes.
  • Kept the new text English-only by explicitly using config.defaultLang for the workaround message, as required.


How I Tested

Case 1 – Username already taken

  • Created a user test1 first.
  • On the register page, typed test1 into the Username field and blurred the input.
  • Observed:
    • Red error styling.
    • Two lines of text:
      • “Username taken”
      • “The username you requested was already taken, so we have altered it slightly. You are now known as test11.” (with a suggested alternative).

Case 2 – Username available

  • Entered a unique username (e.g., unique123).
  • Observed:
    • Green success styling.

Case 3 – Existing validation behavior

  • Tried usernames that are:
    • Too short
    • Too long
    • Invalid per utils.isUserNameValid

Screenshots

Register page showing taken username test1 and suggestion message
Screenshot 2026-02-02 at 1 09 57 PM

@caoerz-helen caoerz-helen changed the title suggest username when taken on register suggest username when taken on register Resolves #1 Feb 2, 2026
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 21601855893

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 78.841%

Totals Coverage Status
Change from base Build 21503398961: 0.0%
Covered Lines: 25358
Relevant Lines: 30328

💛 - Coveralls

@caoerz-helen caoerz-helen changed the title suggest username when taken on register Resolves #1 suggest username when taken on register Feb 2, 2026
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.

Suggest a new username if a username is taken during registration

3 participants