summaryrefslogtreecommitdiff
path: root/internal/processing/user/create.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2025-02-10 15:46:36 +0100
committerLibravatar GitHub <noreply@github.com>2025-02-10 15:46:36 +0100
commit787bdc1488da476e54fb0daded061cf36ecf9010 (patch)
tree892cf4b9d42887ac703d8ee565be884c89b2d903 /internal/processing/user/create.go
parent[bugfix] Fix POST to create account endpoint (#3767) (diff)
downloadgotosocial-787bdc1488da476e54fb0daded061cf36ecf9010.tar.xz
[feature] make account sign-up / backlog limits configurable (#3768)
Diffstat (limited to 'internal/processing/user/create.go')
-rw-r--r--internal/processing/user/create.go51
1 files changed, 30 insertions, 21 deletions
diff --git a/internal/processing/user/create.go b/internal/processing/user/create.go
index 0d848583e..f878d8320 100644
--- a/internal/processing/user/create.go
+++ b/internal/processing/user/create.go
@@ -44,34 +44,43 @@ func (p *Processor) Create(
app *gtsmodel.Application,
form *apimodel.AccountCreateRequest,
) (*gtsmodel.User, gtserror.WithCode) {
- const (
- usersPerDay = 10
- regBacklog = 20
+ var (
+ usersPerDay = config.GetAccountsRegistrationDailyLimit()
+ regBacklog = config.GetAccountsRegistrationBacklogLimit()
)
- // Ensure no more than usersPerDay
+ // If usersPerDay limit is in place,
+ // ensure no more than usersPerDay
// have registered in the last 24h.
- newUsersCount, err := p.state.DB.CountApprovedSignupsSince(ctx, time.Now().Add(-24*time.Hour))
- if err != nil {
- err := fmt.Errorf("db error counting new users: %w", err)
- return nil, gtserror.NewErrorInternalError(err)
- }
+ if usersPerDay > 0 {
+ newUsersCount, err := p.state.DB.CountApprovedSignupsSince(ctx, time.Now().Add(-24*time.Hour))
+ if err != nil {
+ err := fmt.Errorf("db error counting new users: %w", err)
+ return nil, gtserror.NewErrorInternalError(err)
+ }
- if newUsersCount >= usersPerDay {
- err := fmt.Errorf("this instance has hit its limit of new sign-ups for today; you can try again tomorrow")
- return nil, gtserror.NewErrorUnprocessableEntity(err, err.Error())
+ if newUsersCount >= usersPerDay {
+ err := fmt.Errorf("this instance has hit its limit of new sign-ups for today (%d); you can try again tomorrow", usersPerDay)
+ return nil, gtserror.NewErrorUnprocessableEntity(err, err.Error())
+ }
}
- // Ensure the new users backlog isn't full.
- backlogLen, err := p.state.DB.CountUnhandledSignups(ctx)
- if err != nil {
- err := fmt.Errorf("db error counting registration backlog length: %w", err)
- return nil, gtserror.NewErrorInternalError(err)
- }
+ // If registration backlog limit is
+ // in place, ensure backlog isn't full.
+ if regBacklog > 0 {
+ backlogLen, err := p.state.DB.CountUnhandledSignups(ctx)
+ if err != nil {
+ err := fmt.Errorf("db error counting registration backlog length: %w", err)
+ return nil, gtserror.NewErrorInternalError(err)
+ }
- if backlogLen >= regBacklog {
- err := fmt.Errorf("this instance's sign-up backlog is currently full; you must wait until pending sign-ups are handled by the admin(s)")
- return nil, gtserror.NewErrorUnprocessableEntity(err, err.Error())
+ if backlogLen >= regBacklog {
+ err := fmt.Errorf(
+ "this instance's sign-up backlog is currently full (%d sign-ups pending approval); "+
+ "you must wait until some pending sign-ups are handled by the admin(s)", regBacklog,
+ )
+ return nil, gtserror.NewErrorUnprocessableEntity(err, err.Error())
+ }
}
emailAvailable, err := p.state.DB.IsEmailAvailable(ctx, form.Email)