Improve username validation and allow e-mail authentication - #725
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors username validation rules, enables email‐based authentication alongside username login, and updates the login/register UI and translations to support the changes.
- Centralizes and expands username validation using updated regex plus
minLength/maxLengthin YAML schemes - Adds a unified “login” field for username or email in forms, updates controller logic to authenticate by either value, and enforces email uniqueness
- Renames login/register CSS classes and templates for consistent styling and improved markup
Reviewed Changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| site/schemes/users/user.yaml | Replace password pattern with minLength |
| panel/views/register/register.php | Wrap register caption in .section-header |
| panel/views/partials/login/notification.php | Rename .login-modal-* to .login-notification-* |
| panel/views/layouts/login.php | Use .login-container and add nested .sections/<section> |
| panel/views/fields/text.php | Add autocomplete attribute |
| panel/views/fields/password.php | Standardize autocomplete accessor call |
| panel/views/fields/email.php | Add autocomplete attribute |
| panel/views/authentication/login.php | Replace static inputs with dynamic fields loop and section header |
| panel/translations/uk.yaml | Introduce usernameOrEmail and new email‐error messages |
| panel/translations/ru.yaml | Introduce usernameOrEmail and new email‐error messages |
| panel/translations/pt.yaml | Introduce usernameOrEmail and new email‐error messages |
| panel/translations/pl.yaml | Introduce usernameOrEmail and new email‐error messages |
| panel/translations/it.yaml | Introduce usernameOrEmail and new email‐error messages |
| panel/translations/fr.yaml | Introduce usernameOrEmail and new email‐error messages |
| panel/translations/es.yaml | Introduce usernameOrEmail and new email‐error messages |
| panel/translations/en.yaml | Introduce usernameOrEmail and new email‐error messages |
| panel/translations/de.yaml | Introduce usernameOrEmail and new email‐error messages |
| panel/src/scss/components/_login.scss | Rename .login-modal-* rules to .login-notification-* and .login-container |
| panel/schemes/forms/register.yaml | Update username regex and add minLength/maxLength |
| panel/schemes/forms/login.yaml | Add login form scheme for username/email |
| panel/modals/newUser.yaml | Update username regex and add minLength/maxLength in modal |
| panel/config/routes/routes.php | Align route regex to new username format |
| formwork/src/Panel/Controllers/UsersController.php | Add email‐uniqueness checks in create and update |
| formwork/src/Panel/Controllers/AuthenticationController.php | Inject login scheme, validate fields, support email login |
| formwork/fields/text.php | Add autocomplete mapping for Text fields |
Comments suppressed due to low confidence (2)
panel/schemes/forms/register.yaml:14
- The
patternlacks^and$anchors, so it may match substrings instead of the full username. Wrap the regex as^...$to enforce full-string validation.
pattern: '[a-zA-Z][a-zA-Z0-9]*([\-._][a-zA-Z0-9]+)*'
panel/modals/newUser.yaml:16
- Same issue: the username
patternis missing^and$, so it won't enforce matching the entire string. Add anchors to ensure exact validation.
pattern: '[a-zA-Z][a-zA-Z0-9]*([\-._][a-zA-Z0-9]+)*'
|
maybe think about basic ACL and add logic for users with site access only |
|
@RWDevelopment it's a good idea, but not for now. I'm just wrapping up the tasks to finally release Formwork 2.0. Would you mind to open a discussion for this feature under the Ideas category to keep track of this proposal? |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This pull request introduces several improvements and updates across the authentication, user management, and validation systems, as well as UI and internationalization enhancements. Key changes include adding support for email-based login, stricter validation for usernames and emails, and improved error handling. Below is a summary of the most important updates grouped by theme:
Authentication Enhancements:
loginfield in the login form and modifying user lookup logic to check both username and email.Schemesclass and added error handling for validation failures.User Management Improvements:
-,.,_) and restricted usernames to 3–20 characters.UI and Styling Updates:
.login-modal-*renamed to.login-notification-*).Routing and Configuration Adjustments:
These changes collectively enhance the system's usability, security, and flexibility for both users and administrators.