mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-08 22:36:37 +08:00
feat: make user limit configurable from admin user management (#18)
Store the per-instance user cap in settings (default 20) and expose GET/PUT /admin/users/limit endpoints. The user management page now lets admins view and update the limit without touching system settings. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: truewhile <truewhile@users.noreply.github.com>
This commit is contained in:
@@ -40,14 +40,8 @@ var (
|
||||
ErrUserExpired = errors.New("user account has expired")
|
||||
)
|
||||
|
||||
// MaxUsers 是单实例允许的最大用户数(开源版本固定上限)。
|
||||
const MaxUsers = OpenSourceUserLimit
|
||||
|
||||
// OpenSourceUserLimit 是开源版本的用户数上限。
|
||||
const OpenSourceUserLimit = 20
|
||||
|
||||
// UserLimit 是注册/邀请码发放时的固定用户数上限(授权管理已移除,固定为开源上限)。
|
||||
const UserLimit = OpenSourceUserLimit
|
||||
// MaxUsers is kept for tests that seed up to the default cap.
|
||||
const MaxUsers = DefaultMaxUsers
|
||||
|
||||
// SeedAdmin makes sure at least one admin user exists. It mirrors the
|
||||
// legacy default behaviour: if no admin row is found we create
|
||||
@@ -103,9 +97,13 @@ func (s *AuthService) Register(ctx context.Context, username, password string) (
|
||||
if err := s.repo.User.ReleaseDeletedUsername(ctx, username); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
limit, err := LoadMaxUsers(ctx, s.repo)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if n, err := s.repo.User.Count(ctx); err != nil {
|
||||
return nil, nil, err
|
||||
} else if n >= UserLimit {
|
||||
} else if n >= int64(limit) {
|
||||
return nil, nil, ErrUserLimitReached
|
||||
}
|
||||
hash, err := hashPassword(password)
|
||||
|
||||
Reference in New Issue
Block a user