From f52f89735c8951b54d3f9ae3c8288e66b3ef0e73 Mon Sep 17 00:00:00 2001 From: Bobby Iliev Date: Sun, 17 Nov 2024 17:29:44 +0200 Subject: [PATCH 1/8] Allow users to disable registrations --- config/devdojo/auth/descriptions.php | 1 + config/devdojo/auth/settings.php | 1 + resources/views/pages/auth/register.blade.php | 13 +++++- tests/Feature/RegistrationTest.php | 45 +++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/RegistrationTest.php diff --git a/config/devdojo/auth/descriptions.php b/config/devdojo/auth/descriptions.php index 3f1a8fb..2fd362f 100644 --- a/config/devdojo/auth/descriptions.php +++ b/config/devdojo/auth/descriptions.php @@ -6,6 +6,7 @@ return [ 'settings' => [ 'redirect_after_auth' => 'Where should the user be redirected to after they are authenticated?', + 'registration_enabled' => 'Enable or disable registration functionality. If disabled, users will not be able to register for an account.', 'registration_show_password_same_screen' => 'During registrations, show the password on the same screen or show it on an individual screen.', 'registration_include_name_field' => 'During registration, include the Name field.', 'registration_include_password_confirmation_field' => 'During registration, include the Password Confirmation field.', diff --git a/config/devdojo/auth/settings.php b/config/devdojo/auth/settings.php index a088429..cb46d55 100644 --- a/config/devdojo/auth/settings.php +++ b/config/devdojo/auth/settings.php @@ -5,6 +5,7 @@ */ return [ 'redirect_after_auth' => '/', + 'registration_enabled' => true, 'registration_show_password_same_screen' => true, 'registration_include_name_field' => false, 'registration_include_password_confirmation_field' => false, diff --git a/resources/views/pages/auth/register.blade.php b/resources/views/pages/auth/register.blade.php index ad596f8..eb9fe9e 100644 --- a/resources/views/pages/auth/register.blade.php +++ b/resources/views/pages/auth/register.blade.php @@ -53,6 +53,12 @@ public function mount() { $this->loadConfigs(); + if (!$this->settings->registration_enabled) { + session()->flash('error', config('devdojo.auth.language.register.registrations_disabled', 'Registrations are currently disabled.')); + redirect()->route('auth.login'); + return; + } + if ($this->settings->registration_include_name_field) { $this->showNameField = true; } @@ -68,6 +74,11 @@ public function mount() public function register() { + if (!$this->settings->registration_enabled) { + session()->flash('error', config('devdojo.auth.language.register.registrations_disabled', 'Registrations are currently disabled.')); + return redirect()->route('auth.login'); + } + if (!$this->showPasswordField) { if ($this->settings->registration_include_name_field) { $this->validateOnly('name'); @@ -166,4 +177,4 @@ public function register() @endvolt - \ No newline at end of file + diff --git a/tests/Feature/RegistrationTest.php b/tests/Feature/RegistrationTest.php new file mode 100644 index 0000000..8fdc1ff --- /dev/null +++ b/tests/Feature/RegistrationTest.php @@ -0,0 +1,45 @@ +set('devdojo.auth.settings.registration_enabled', true); +}); + +it('allows access to registration page when enabled', function () { + Livewire::test('auth.register') + ->assertOk() + ->assertDontSee('Registrations are currently disabled'); +}); + +it('redirects to login when registrations are disabled', function () { + config()->set('devdojo.auth.settings.registration_enabled', false); + + Livewire::test('auth.register') + ->assertRedirect(route('auth.login')); + + expect(session('error'))->toBe( + config('devdojo.auth.language.register.registrations_disabled', 'Registrations are currently disabled.') + ); +}); + +it('allows registration when enabled', function () { + $component = Livewire::test('auth.register') + ->set('email', 'test@example.com') + ->set('password', 'password123') + ->set('name', 'Test User') + ->call('register'); + + expect(Auth::check())->toBeTrue(); + expect(Auth::user()->email)->toBe('test@example.com'); +}); + +it('preserves other registration settings when enabled', function () { + config()->set('devdojo.auth.settings.registration_include_name_field', true); + config()->set('devdojo.auth.settings.registration_show_password_same_screen', true); + + $component = Livewire::test('auth.register'); + + expect($component->get('showNameField'))->toBeTrue(); + expect($component->get('showPasswordField'))->toBeTrue(); +}); From b3c2c94600c20b2de248216ca1d0688629aa5fa0 Mon Sep 17 00:00:00 2001 From: Bobby Iliev Date: Mon, 18 Nov 2024 10:01:43 +0200 Subject: [PATCH 2/8] Hide registration link on login page --- resources/views/pages/auth/login.blade.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/resources/views/pages/auth/login.blade.php b/resources/views/pages/auth/login.blade.php index fe10082..bed8582 100644 --- a/resources/views/pages/auth/login.blade.php +++ b/resources/views/pages/auth/login.blade.php @@ -188,10 +188,12 @@ public function authenticate() -
- {{ config('devdojo.auth.language.login.dont_have_an_account') }} - {{ config('devdojo.auth.language.login.sign_up') }} -
+ @if(config('devdojo.auth.settings.registration_enabled')) +
+ {{ config('devdojo.auth.language.login.dont_have_an_account') }} + {{ config('devdojo.auth.language.login.sign_up') }} +
+ @endif @if(config('devdojo.auth.settings.login_show_social_providers') && config('devdojo.auth.settings.social_providers_location') != 'top') From 2a76f9e22d97eadee27f22b29eca77db7b2cad7c Mon Sep 17 00:00:00 2001 From: Bobby Iliev Date: Sun, 1 Dec 2024 16:42:06 +0200 Subject: [PATCH 3/8] Allow users to disable email registrations --- config/devdojo/auth/descriptions.php | 1 + config/devdojo/auth/settings.php | 1 + resources/views/pages/auth/login.blade.php | 2 +- resources/views/pages/auth/register.blade.php | 22 +++++++- tests/Feature/RegistrationTest.php | 50 +++++++++++++++++++ 5 files changed, 74 insertions(+), 2 deletions(-) diff --git a/config/devdojo/auth/descriptions.php b/config/devdojo/auth/descriptions.php index 2fd362f..ffe93c3 100644 --- a/config/devdojo/auth/descriptions.php +++ b/config/devdojo/auth/descriptions.php @@ -14,6 +14,7 @@ 'enable_branding' => 'This will toggle on/off the Auth branding at the bottom of each auth screen. Consider leaving on to support and help grow this project.', 'dev_mode' => 'This is for development mode, when set in Dev Mode Assets will be loaded from Vite', 'enable_2fa' => 'Enable the ability for users to turn on Two Factor Authentication', + 'enable_email_registration' => 'Enable the ability for users to register via email', 'login_show_social_providers' => 'Show the social providers login buttons on the login form', 'center_align_social_provider_button_content' => 'Center align the content in the social provider button?', 'social_providers_location' => 'The location of the social provider buttons (top or bottom)', diff --git a/config/devdojo/auth/settings.php b/config/devdojo/auth/settings.php index cb46d55..a9ce1b6 100644 --- a/config/devdojo/auth/settings.php +++ b/config/devdojo/auth/settings.php @@ -13,6 +13,7 @@ 'enable_branding' => true, 'dev_mode' => false, 'enable_2fa' => false, // Enable or disable 2FA functionality globally + 'enable_email_registration' => true, 'login_show_social_providers' => true, 'center_align_social_provider_button_content' => false, 'social_providers_location' => 'bottom', diff --git a/resources/views/pages/auth/login.blade.php b/resources/views/pages/auth/login.blade.php index bed8582..058c4e3 100644 --- a/resources/views/pages/auth/login.blade.php +++ b/resources/views/pages/auth/login.blade.php @@ -188,7 +188,7 @@ public function authenticate() - @if(config('devdojo.auth.settings.registration_enabled')) + @if(config('devdojo.auth.settings.registration_enabled', true))
{{ config('devdojo.auth.language.login.dont_have_an_account') }} {{ config('devdojo.auth.language.login.sign_up') }} diff --git a/resources/views/pages/auth/register.blade.php b/resources/views/pages/auth/register.blade.php index eb9fe9e..7939916 100644 --- a/resources/views/pages/auth/register.blade.php +++ b/resources/views/pages/auth/register.blade.php @@ -29,10 +29,14 @@ public $showEmailField = true; public $showPasswordField = false; public $showPasswordConfirmationField = false; - + public $showEmailRegistration = true; public function rules() { + if (!$this->settings->enable_email_registration) { + return []; + } + $nameValidationRules = []; if (config('devdojo.auth.settings.registration_include_name_field')) { $nameValidationRules = ['name' => 'required']; @@ -59,6 +63,15 @@ public function mount() return; } + if (!$this->settings->enable_email_registration) { + $this->showEmailRegistration = false; + $this->showNameField = false; + $this->showEmailField = false; + $this->showPasswordField = false; + $this->showPasswordConfirmationField = false; + return; + } + if ($this->settings->registration_include_name_field) { $this->showNameField = true; } @@ -79,6 +92,11 @@ public function register() return redirect()->route('auth.login'); } + if (!$this->settings->enable_email_registration) { + session()->flash('error', config('devdojo.auth.language.register.email_registration_disabled', 'Email registration is currently disabled. Please use social login.')); + return; + } + if (!$this->showPasswordField) { if ($this->settings->registration_include_name_field) { $this->validateOnly('name'); @@ -140,6 +158,7 @@ public function register() @endif + @if($showEmailRegistration)
@if($showNameField) @@ -163,6 +182,7 @@ public function register() {{config('devdojo.auth.language.register.button')}}
+ @endif
{{config('devdojo.auth.language.register.already_have_an_account')}} diff --git a/tests/Feature/RegistrationTest.php b/tests/Feature/RegistrationTest.php index 8fdc1ff..07a35ef 100644 --- a/tests/Feature/RegistrationTest.php +++ b/tests/Feature/RegistrationTest.php @@ -4,6 +4,7 @@ beforeEach(function () { config()->set('devdojo.auth.settings.registration_enabled', true); + config()->set('devdojo.auth.settings.enable_email_registration', true); }); it('allows access to registration page when enabled', function () { @@ -43,3 +44,52 @@ expect($component->get('showNameField'))->toBeTrue(); expect($component->get('showPasswordField'))->toBeTrue(); }); + +it('hides email registration form when email registration is disabled', function () { + config()->set('devdojo.auth.settings.enable_email_registration', false); + + $component = Livewire::test('auth.register'); + + expect($component->get('showEmailRegistration'))->toBeFalse(); + expect($component->get('showEmailField'))->toBeFalse(); + expect($component->get('showPasswordField'))->toBeFalse(); + expect($component->get('showNameField'))->toBeFalse(); +}); + +it('shows email registration form when email registration is enabled', function () { + config()->set('devdojo.auth.settings.enable_email_registration', true); + + $component = Livewire::test('auth.register'); + + expect($component->get('showEmailRegistration'))->toBeTrue(); + expect($component->get('showEmailField'))->toBeTrue(); +}); + +it('prevents email registration when disabled', function () { + config()->set('devdojo.auth.settings.enable_email_registration', false); + + $component = Livewire::test('auth.register') + ->set('email', 'test@example.com') + ->set('password', 'password123') + ->call('register'); + + expect(Auth::check())->toBeFalse(); + expect(session('error'))->toBe( + config('devdojo.auth.language.register.email_registration_disabled', 'Email registration is currently disabled. Please use social login.') + ); +}); + +it('validates empty rules when email registration is disabled', function () { + config()->set('devdojo.auth.settings.enable_email_registration', false); + + $component = Livewire::test('auth.register'); + + expect($component->instance()->rules())->toBeEmpty(); +}); + +it('preserves social login functionality when email registration is disabled', function () { + config()->set('devdojo.auth.settings.enable_email_registration', false); + + Livewire::test('auth.register') + ->assertSee('social-providers'); +}); From 0828339a82c9636399fbe6bf2a45fa2bc4d489d2 Mon Sep 17 00:00:00 2001 From: Bobby Iliev Date: Sun, 1 Dec 2024 17:02:35 +0200 Subject: [PATCH 4/8] Fix failing tests --- config/devdojo/auth/language.php | 1 + resources/views/pages/auth/register.blade.php | 2 +- tests/Feature/RegistrationTest.php | 7 ++++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/config/devdojo/auth/language.php b/config/devdojo/auth/language.php index a20efaf..009ea36 100644 --- a/config/devdojo/auth/language.php +++ b/config/devdojo/auth/language.php @@ -33,6 +33,7 @@ 'already_have_an_account' => 'Already have an account?', 'sign_in' => 'Sign in', 'button' => 'Continue', + 'email_registration_disabled' => 'Email registration is currently disabled. Please use social login.', ], 'verify' => [ 'page_title' => 'Verify Your Account', diff --git a/resources/views/pages/auth/register.blade.php b/resources/views/pages/auth/register.blade.php index 7939916..f950023 100644 --- a/resources/views/pages/auth/register.blade.php +++ b/resources/views/pages/auth/register.blade.php @@ -94,7 +94,7 @@ public function register() if (!$this->settings->enable_email_registration) { session()->flash('error', config('devdojo.auth.language.register.email_registration_disabled', 'Email registration is currently disabled. Please use social login.')); - return; + return redirect()->route('auth.register'); } if (!$this->showPasswordField) { diff --git a/tests/Feature/RegistrationTest.php b/tests/Feature/RegistrationTest.php index 07a35ef..e216cc8 100644 --- a/tests/Feature/RegistrationTest.php +++ b/tests/Feature/RegistrationTest.php @@ -90,6 +90,11 @@ it('preserves social login functionality when email registration is disabled', function () { config()->set('devdojo.auth.settings.enable_email_registration', false); + config()->set('devdojo.auth.providers', [ + 'google' => ['name' => 'Google', 'active' => true], + 'facebook' => ['name' => 'Facebook', 'active' => false], + ]); + Livewire::test('auth.register') - ->assertSee('social-providers'); + ->assertSee('Google'); }); From 9f3ed999da996e01fea1512ceb0fb9470ad42303 Mon Sep 17 00:00:00 2001 From: Tony Lea Date: Tue, 3 Dec 2024 20:26:46 -0500 Subject: [PATCH 5/8] Conditionally showing the separator --- resources/views/pages/auth/register.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/pages/auth/register.blade.php b/resources/views/pages/auth/register.blade.php index f950023..267e461 100644 --- a/resources/views/pages/auth/register.blade.php +++ b/resources/views/pages/auth/register.blade.php @@ -155,7 +155,7 @@ public function register() @if(config('devdojo.auth.settings.social_providers_location') == 'top') - + @endif @if($showEmailRegistration) @@ -190,7 +190,7 @@ public function register()
@if(config('devdojo.auth.settings.social_providers_location') != 'top') - + @endif From 15fcfd019a489e0b06e715e7f8fe1ffe7c5adb9a Mon Sep 17 00:00:00 2001 From: Tony Lea Date: Tue, 3 Dec 2024 20:42:21 -0500 Subject: [PATCH 6/8] adding updates to center text in container --- config/devdojo/auth/descriptions.php | 1 + config/devdojo/auth/settings.php | 1 + resources/views/components/elements/container.blade.php | 2 +- resources/views/components/elements/social-providers.blade.php | 2 +- resources/views/pages/auth/register.blade.php | 2 +- 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config/devdojo/auth/descriptions.php b/config/devdojo/auth/descriptions.php index ffe93c3..c501328 100644 --- a/config/devdojo/auth/descriptions.php +++ b/config/devdojo/auth/descriptions.php @@ -17,6 +17,7 @@ 'enable_email_registration' => 'Enable the ability for users to register via email', 'login_show_social_providers' => 'Show the social providers login buttons on the login form', 'center_align_social_provider_button_content' => 'Center align the content in the social provider button?', + 'center_align_container_text' => 'Center align the text in the container?', 'social_providers_location' => 'The location of the social provider buttons (top or bottom)', 'check_account_exists_before_login' => 'Determines if the system checks for account existence before login', ], diff --git a/config/devdojo/auth/settings.php b/config/devdojo/auth/settings.php index a9ce1b6..01450c6 100644 --- a/config/devdojo/auth/settings.php +++ b/config/devdojo/auth/settings.php @@ -16,6 +16,7 @@ 'enable_email_registration' => true, 'login_show_social_providers' => true, 'center_align_social_provider_button_content' => false, + 'center_align_container_text' => false, 'social_providers_location' => 'bottom', 'check_account_exists_before_login' => false, ]; diff --git a/resources/views/components/elements/container.blade.php b/resources/views/components/elements/container.blade.php index 40820dd..92b9d89 100644 --- a/resources/views/components/elements/container.blade.php +++ b/resources/views/components/elements/container.blade.php @@ -13,7 +13,7 @@ @endphp
-
+
{{ $slot }}
\ No newline at end of file diff --git a/resources/views/components/elements/social-providers.blade.php b/resources/views/components/elements/social-providers.blade.php index e174931..7acb539 100644 --- a/resources/views/components/elements/social-providers.blade.php +++ b/resources/views/components/elements/social-providers.blade.php @@ -7,7 +7,7 @@ @if($separator && config('devdojo.auth.settings.social_providers_location') != 'top') {{ $separator_text }} @endif -
+
@foreach($socialProviders as $slug => $provider) @endforeach diff --git a/resources/views/pages/auth/register.blade.php b/resources/views/pages/auth/register.blade.php index 267e461..62afc24 100644 --- a/resources/views/pages/auth/register.blade.php +++ b/resources/views/pages/auth/register.blade.php @@ -184,7 +184,7 @@ public function register() @endif -
+
{{config('devdojo.auth.language.register.already_have_an_account')}} {{config('devdojo.auth.language.register.sign_in')}}
From d13e3ae82c3e146a53ee3987e4223663dfb3f1aa Mon Sep 17 00:00:00 2001 From: Tony Lea Date: Tue, 3 Dec 2024 20:44:23 -0500 Subject: [PATCH 7/8] updating registration page --- resources/views/components/elements/container.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/components/elements/container.blade.php b/resources/views/components/elements/container.blade.php index 92b9d89..17aad72 100644 --- a/resources/views/components/elements/container.blade.php +++ b/resources/views/components/elements/container.blade.php @@ -13,7 +13,7 @@ @endphp
-
+
{{ $slot }}
\ No newline at end of file From f6b71367b78012b1542ab939e5c6e9fc8de994c1 Mon Sep 17 00:00:00 2001 From: Tony Lea Date: Tue, 3 Dec 2024 21:03:03 -0500 Subject: [PATCH 8/8] Adding a few more design and setting updates --- config/devdojo/auth/descriptions.php | 2 +- config/devdojo/auth/settings.php | 2 +- resources/views/components/elements/container.blade.php | 2 +- resources/views/pages/auth/login.blade.php | 2 +- resources/views/pages/auth/register.blade.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/devdojo/auth/descriptions.php b/config/devdojo/auth/descriptions.php index c501328..f380993 100644 --- a/config/devdojo/auth/descriptions.php +++ b/config/devdojo/auth/descriptions.php @@ -17,7 +17,7 @@ 'enable_email_registration' => 'Enable the ability for users to register via email', 'login_show_social_providers' => 'Show the social providers login buttons on the login form', 'center_align_social_provider_button_content' => 'Center align the content in the social provider button?', - 'center_align_container_text' => 'Center align the text in the container?', + 'center_align_text' => 'Center align text?', 'social_providers_location' => 'The location of the social provider buttons (top or bottom)', 'check_account_exists_before_login' => 'Determines if the system checks for account existence before login', ], diff --git a/config/devdojo/auth/settings.php b/config/devdojo/auth/settings.php index 01450c6..e9f139f 100644 --- a/config/devdojo/auth/settings.php +++ b/config/devdojo/auth/settings.php @@ -16,7 +16,7 @@ 'enable_email_registration' => true, 'login_show_social_providers' => true, 'center_align_social_provider_button_content' => false, - 'center_align_container_text' => false, + 'center_align_text' => false, 'social_providers_location' => 'bottom', 'check_account_exists_before_login' => false, ]; diff --git a/resources/views/components/elements/container.blade.php b/resources/views/components/elements/container.blade.php index 17aad72..40820dd 100644 --- a/resources/views/components/elements/container.blade.php +++ b/resources/views/components/elements/container.blade.php @@ -13,7 +13,7 @@ @endphp
-
+
{{ $slot }}
\ No newline at end of file diff --git a/resources/views/pages/auth/login.blade.php b/resources/views/pages/auth/login.blade.php index 058c4e3..599dafd 100644 --- a/resources/views/pages/auth/login.blade.php +++ b/resources/views/pages/auth/login.blade.php @@ -189,7 +189,7 @@ public function authenticate() @if(config('devdojo.auth.settings.registration_enabled', true)) -
+
{{ config('devdojo.auth.language.login.dont_have_an_account') }} {{ config('devdojo.auth.language.login.sign_up') }}
diff --git a/resources/views/pages/auth/register.blade.php b/resources/views/pages/auth/register.blade.php index 62afc24..41c2788 100644 --- a/resources/views/pages/auth/register.blade.php +++ b/resources/views/pages/auth/register.blade.php @@ -184,7 +184,7 @@ public function register() @endif -
+
{{config('devdojo.auth.language.register.already_have_an_account')}} {{config('devdojo.auth.language.register.sign_in')}}