diff --git a/config/devdojo/auth/descriptions.php b/config/devdojo/auth/descriptions.php index 3f1a8fb..f380993 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.', @@ -13,8 +14,10 @@ '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?', + '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/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/config/devdojo/auth/settings.php b/config/devdojo/auth/settings.php index a088429..e9f139f 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, @@ -12,8 +13,10 @@ '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, + 'center_align_text' => false, 'social_providers_location' => 'bottom', 'check_account_exists_before_login' => false, ]; 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/login.blade.php b/resources/views/pages/auth/login.blade.php index fe10082..599dafd 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', true)) +
+ {{ 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') diff --git a/resources/views/pages/auth/register.blade.php b/resources/views/pages/auth/register.blade.php index ad596f8..41c2788 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']; @@ -53,6 +57,21 @@ 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->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; } @@ -68,6 +87,16 @@ 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->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 redirect()->route('auth.register'); + } + if (!$this->showPasswordField) { if ($this->settings->registration_include_name_field) { $this->validateOnly('name'); @@ -126,9 +155,10 @@ public function register() @if(config('devdojo.auth.settings.social_providers_location') == 'top') - + @endif + @if($showEmailRegistration)
@if($showNameField) @@ -152,18 +182,19 @@ public function register() {{config('devdojo.auth.language.register.button')}}
+ @endif -
+
{{config('devdojo.auth.language.register.already_have_an_account')}} {{config('devdojo.auth.language.register.sign_in')}}
@if(config('devdojo.auth.settings.social_providers_location') != 'top') - + @endif @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..e216cc8 --- /dev/null +++ b/tests/Feature/RegistrationTest.php @@ -0,0 +1,100 @@ +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 () { + 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(); +}); + +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); + + config()->set('devdojo.auth.providers', [ + 'google' => ['name' => 'Google', 'active' => true], + 'facebook' => ['name' => 'Facebook', 'active' => false], + ]); + + Livewire::test('auth.register') + ->assertSee('Google'); +});