From 9fa8479ed8ae975ca5b7b7c0473072639245d301 Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Wed, 25 Apr 2018 21:22:39 -0400 Subject: [PATCH] Improve the functionality surrounding the REGISTRATION variable in the .env file so it can continue to enable registration globally by setting its value to "true", but now also enable registration for a single IP address by setting its value to that address --- app/Dashboard.php | 11 +++++++++++ app/Http/Controllers/Auth/RegisterController.php | 7 +++++-- resources/views/dashboard/sections/nav.blade.php | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/Dashboard.php b/app/Dashboard.php index 4f69c65..544225b 100644 --- a/app/Dashboard.php +++ b/app/Dashboard.php @@ -84,4 +84,15 @@ class Dashboard return null; } } + + /** + * Checks the registration status against the REGISTRATION variable in .env + * + * @return boolean + */ + public static function canRegister() + { + $registration_status = env('REGISTRATION', false); + return $registration_status === true || $registration_status === \Request::ip(); + } } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 431d682..0c6b5c0 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -1,6 +1,7 @@ $data['name'], 'email' => $data['email'], 'password' => Hash::make($data['password']), 'api_token' => str_random(60) ]); + } else { + abort(404); } } @@ -78,7 +81,7 @@ class RegisterController extends Controller { */ public function showRegistrationForm() { - if (env('REGISTRATION', false)) { + if (Dashboard::canRegister()) { return view('auth.register'); } else { header('Location: /login'); diff --git a/resources/views/dashboard/sections/nav.blade.php b/resources/views/dashboard/sections/nav.blade.php index 4d3337f..4b239a4 100644 --- a/resources/views/dashboard/sections/nav.blade.php +++ b/resources/views/dashboard/sections/nav.blade.php @@ -16,7 +16,7 @@ @if (Auth::guest()) - @if(env('REGISTRATION', false)) + @if(App\Dashboard::canRegister()) @endif @else