From 12995989c45a855bf9d1b375d441f1d5b3231ce9 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 30 Jan 2019 18:11:22 -0700 Subject: [PATCH] Add max user limit --- app/Http/Controllers/Auth/RegisterController.php | 12 ++++++++++-- config/pixelfed.php | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index d9354697a..4ce5538e9 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -116,7 +116,13 @@ class RegisterController extends Controller */ public function showRegistrationForm() { - $view = config('pixelfed.open_registration') == true ? 'auth.register' : 'site.closed-registration'; + $count = User::count(); + $limit = config('pixelfed.max_users'); + if($limit && $limit <= $count) { + $view = 'site.closed-registration'; + } else { + $view = config('pixelfed.open_registration') == true ? 'auth.register' : 'site.closed-registration'; + } return view($view); } @@ -128,7 +134,9 @@ class RegisterController extends Controller */ public function register(Request $request) { - if(false == config('pixelfed.open_registration')) { + $count = User::count(); + $limit = config('pixelfed.max_users'); + if(false == config('pixelfed.open_registration') || $limit && $limit <= $count) { return abort(403); } diff --git a/config/pixelfed.php b/config/pixelfed.php index f6da8cd58..da60ba793 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -208,6 +208,16 @@ return [ */ 'cloud_storage' => env('PF_ENABLE_CLOUD', false), + /* + |-------------------------------------------------------------------------- + | Max User Limit + |-------------------------------------------------------------------------- + | + | Allow a maximum number of user accounts. Default: off + | + */ + 'max_users' => env('PF_MAX_USERS', false), + 'media_types' => env('MEDIA_TYPES', 'image/jpeg,image/png,image/gif'), 'enforce_account_limit' => env('LIMIT_ACCOUNT_SIZE', true),