fix: accept username, not just email, on login and register forms#559
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The admin Add user dialog lets an operator create an account with either an
email or a plain username, and the backend accepts both: the
/loginand/registerendpoints pass the value straight toauthenticate()/RegisterRequest, whose validator explicitly allows "a standard email addressor a plain username" (
deeptutor/api/routers/auth.py).But the login and register forms hardcoded the identity field as
type="email", so the browser's native HTML5 validation rejected anythingwithout an
@("Please include an '@' in the email address"). The result: youcould create a username-only account from the admin panel, but never sign in
with it — the form blocked submission before the request was even sent.
This change makes the frontend match the admin dialog and the backend:
type="email"→type="text"(drops the browser's email-only validation)autoComplete="email"→autoComplete="username"Email→Email or username(added to bothenandzhlocales)No backend changes — it already supported username login.
Related Issues
Module(s) Affected
agentsapiconfigcoreknowledgeloggingservicestoolsutilsweb(Frontend)docs(Documentation)scriptstests...Checklist
pre-commit run --all-filesand fixed any issues.Additional Notes
Before / After
type="email"blocks a username)Email or username)Tests — added
tests/multi_user/test_login_username_contract.py, locking thebackend contract the form relies on so a future change (e.g. swapping the field
for
pydantic.EmailStr) can't silently break username login again:RegisterRequestaccepts an email or a bare username; rejects empty/garbageand passwords shorter than 8 chars.
LoginRequestimposes no email-only or password-length validation.authenticate()round-trips a user created with a plain username.Note on
pre-commit— all hooks pass on the changed files exceptcheck-json, which flags a pre-existing duplicate key ("Space tooltip") inweb/locales/{en,zh}/app.json. That duplicate is already present ondevand isunrelated to this PR; happy to fix it in a separate change if useful.