Skip to content

Improve username validation and allow e-mail authentication - #725

Merged
giuscris merged 5 commits into
2.xfrom
user-auth-update
Jul 12, 2025
Merged

Improve username validation and allow e-mail authentication#725
giuscris merged 5 commits into
2.xfrom
user-auth-update

Conversation

@giuscris

@giuscris giuscris commented Jul 8, 2025

Copy link
Copy Markdown
Member

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:

  • Added support for logging in with either a username or email by updating the login field in the login form and modifying user lookup logic to check both username and email.
  • Integrated field validation for login forms using the Schemes class and added error handling for validation failures.

User Management Improvements:

  • Enforced unique email addresses during user creation and updates, with appropriate error messages when duplicates are detected.
  • Updated username validation patterns to allow more flexible formats (letters, digits, and special characters -, ., _) and restricted usernames to 3–20 characters.

UI and Styling Updates:

  • Refactored login-related SCSS classes for better naming consistency and maintainability (e.g., .login-modal-* renamed to .login-notification-*).

Routing and Configuration Adjustments:

  • Updated user-related routes to support the new username validation patterns.

These changes collectively enhance the system's usability, security, and flexibility for both users and administrators.

@giuscris
giuscris requested a review from Copilot July 8, 2025 23:35
@giuscris giuscris self-assigned this Jul 8, 2025
@giuscris giuscris added the enhancement New feature or request label Jul 8, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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/maxLength in 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 pattern lacks ^ 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 pattern is 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]+)*'

Comment thread formwork/src/Panel/Controllers/AuthenticationController.php Outdated
@RWDevelopment

RWDevelopment commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

maybe think about basic ACL and add logic for users with site access only
admin can set access to site only for specified user
admin can set their status/role like active/unactive, member, premium etc.
this group of users can login but not to panel dashboard and only to site, can not add pages, can not modify it etc.
admin can set a rate limit / unlimited access to site for this user
it is similar to Grav Login Plugin

@giuscris

giuscris commented Jul 9, 2025

Copy link
Copy Markdown
Member Author

@RWDevelopment it's a good idea, but not for now. I'm just wrapping up the tasks to finally release Formwork 2.0.
This PR brings some much needed upgrades to authentication/panel users before releasing the next version.

Would you mind to open a discussion for this feature under the Ideas category to keep track of this proposal?

@giuscris giuscris added this to the 2.0.0 milestone Jul 12, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@giuscris
giuscris marked this pull request as ready for review July 12, 2025 10:58
@giuscris
giuscris merged commit 02ea387 into 2.x Jul 12, 2025
2 checks passed
@giuscris
giuscris deleted the user-auth-update branch July 12, 2025 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants