Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Disable Signups for new users #7254

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

davpsh
Copy link

@davpsh davpsh commented May 2, 2024

These changes allow to enable/disable new user registration based on ENV setting. The feature was implemented in version 4.x and was not present in chandler. Fixes #6687

Changes:

  • added new environment parameter APP_DISABLE_SIGNUP
  • restricting registration access based on env setting value

@CLAassistant
Copy link

CLAassistant commented May 2, 2024

CLA assistant check
All committers have signed the CLA.

lang/en/auth.php Outdated Show resolved Hide resolved
Copy link
Member

@asbiin asbiin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the work.
However it is a little bit more complicated than needed, please see my reviews.

app/Helpers/SignupHelper.php Outdated Show resolved Hide resolved
app/Http/Controllers/Auth/LoginController.php Outdated Show resolved Hide resolved
app/Http/Middleware/EnsureSignupIsEnabled.php Outdated Show resolved Hide resolved
app/Http/Middleware/EnsureSignupIsEnabled.php Outdated Show resolved Hide resolved
phpunit.xml Outdated Show resolved Hide resolved
tests/Feature/Auth/RegistrationTest.php Show resolved Hide resolved
app/Providers/FortifyServiceProvider.php Outdated Show resolved Hide resolved
@davpsh davpsh changed the title Issue 6687: Disable Signups for new users feat: Disable Signups for new users May 8, 2024
@davpsh davpsh requested a review from asbiin May 8, 2024 07:46
@davpsh
Copy link
Author

davpsh commented Feb 1, 2025

Thank you for the work.
However it is a little bit more complicated than needed, please see my reviews.

@asbiin, can you give feedback on the current state of the code? Is there anything else that needs to be fixed?

Copy link
Member

@asbiin asbiin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @davpsh I left some comments to fix the code, I've tested it but I got an issue running it ...

Comment on lines +18 to +22
public function __construct(
protected SignupHelper $signupHelper
) {
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't working actually

Suggested change
public function __construct(
protected SignupHelper $signupHelper
) {
}

@@ -40,6 +46,7 @@ public function __invoke(Request $request): Response
}

return Inertia::render('Auth/Login', $data + [
'isSignupEnabled' => $this->signupHelper->isEnabled(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should fix it

Suggested change
'isSignupEnabled' => $this->signupHelper->isEnabled(),
'isSignupEnabled' => app(SignupHelper::class)->isEnabled(),

Comment on lines +14 to +21
public function __construct(
protected SignupHelper $signupHelper,
) {
}

public function handle(Request $request, Closure $next): Response
{
abort_if(! $this->signupHelper->isEnabled(), 403, trans('Registration is currently disabled'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function __construct(
protected SignupHelper $signupHelper,
) {
}
public function handle(Request $request, Closure $next): Response
{
abort_if(! $this->signupHelper->isEnabled(), 403, trans('Registration is currently disabled'));
public function handle(Request $request, Closure $next): Response
{
abort_if(! app(SignupHelper::class)->isEnabled(), 403, trans('Registration is currently disabled'));

use Tests\TestCase;

class RegistrationTest extends TestCase
{
use DatabaseTransactions;

#[Test]
public function registration_screen_can_be_rendered()
public function testAccessToRegistrationPage(): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the new syntax

Suggested change
public function testAccessToRegistrationPage(): void
#[Test]
public function registration_screen_can_be_rendered(): void

use Laravel\Jetstream\Jetstream;
use PHPUnit\Framework\Attributes\Test;
use Mockery;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use Mockery;
use PHPUnit\Framework\Attributes\Test;
use Mockery;

}

#[Test]
public function new_users_can_register()
public function testRegistration(): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function testRegistration(): void
#[Test]
public function new_users_can_register()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How do disable Signups for new users?
3 participants