-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Add protected usernames restriction to sign-up #7887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add protected usernames restriction to sign-up #7887
Conversation
- 新增 RestrictedNameException 异常类用于处理受限用户名 - 在注册端点中添加对受限用户名的检查逻辑 - 更新模板文件以显示受限用户名错误信息 - 在系统设置中添加受限用户名配置项 - 支持多语言显示受限用户名错误提示 - 完善用户服务中的用户名验证逻辑
application/src/main/resources/templates/gateway_fragments/signup.properties
Show resolved
Hide resolved
application/src/main/resources/templates/gateway_fragments/signup_es.properties
Show resolved
Hide resolved
application/src/main/resources/templates/gateway_fragments/signup_zh_TW.properties
Show resolved
Hide resolved
- 将系统设置中的 restrictedUsernames 字段重命名为 protectedUsernames - 修改前端模板及多语言资源文件中相关错误提示文案 - 调整用户注册服务逻辑,支持通过逗号分隔的字符串配置保留用户名 - 更新系统默认保留用户名列表至配置项 - 优化前端提示信息键名为 form.error.protectedUsernames 并同步多语言翻译
ruibaby
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #7887 +/- ##
============================================
+ Coverage 59.55% 61.19% +1.63%
- Complexity 3812 3932 +120
============================================
Files 677 689 +12
Lines 23248 23498 +250
Branches 1500 1521 +21
============================================
+ Hits 13846 14380 +534
+ Misses 8764 8392 -372
- Partials 638 726 +88 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request implements a protected usernames feature to prevent users from registering with reserved usernames during the signup process.
- Adds a new
RestrictedNameExceptionto handle restricted username validation - Introduces a
protectedUsernamesconfiguration field in system settings with a default list of reserved names - Validates usernames against the protected list during signup with appropriate error handling and user-facing messages
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
RestrictedNameException.java |
New exception class for restricted username validation |
UserServiceImpl.java |
Implements username validation logic against protected list during signup |
SystemSetting.java |
Adds protectedUsernames field to User settings model |
system-setting.yaml |
Adds textarea field for configuring protected usernames with default values |
PreAuthSignUpEndpoint.java |
Handles RestrictedNameException and maps to error state |
signup.html |
Displays error message when restricted username is used |
signup*.properties |
Adds localized error messages for restricted username validation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
application/src/main/java/run/halo/app/core/user/service/impl/UserServiceImpl.java
Outdated
Show resolved
Hide resolved
JohnNiang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing this project!
I left two comments below.
application/src/main/java/run/halo/app/core/user/service/impl/UserServiceImpl.java
Outdated
Show resolved
Hide resolved
application/src/main/java/run/halo/app/core/user/service/impl/UserServiceImpl.java
Outdated
Show resolved
Hide resolved
- 将受保护用户名检查逻辑提取到 isUsernameAllowed 方法中 - 使用 Set 替代 List 提高查找性能 - 添加用户名大小写不敏感比较 - 优化受保护用户名集合的构建过程 - 确保受保护用户名集合不可变且去重
- 调整流操作顺序以确保唯一性检查在转换为小写后执行 - 修复可能因大小写导致的重复条目问题
application/src/main/java/run/halo/app/core/user/service/impl/UserServiceImpl.java
Outdated
Show resolved
Hide resolved
|
如果需要禁用的比较多,这种配置方式感觉略复杂。是否直接长本文加特定分隔符的配置方式就可以。 |
已经改了,#7887 (comment) @liuyiwuqing 可以考虑更新下截图。 |
已更新相关截图 |
|
还有一个 checkstyle 的问题:https://github.com/halo-dev/halo/pull/7887/checks 修复之后就可以合并了。 |
|
已修复 |
JohnNiang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
ruibaby
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JohnNiang, ruibaby The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |



What type of PR is this?
/kind feature
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #7165
Does this PR introduce a user-facing change?