enable us to disable registration
This commit is contained in:
@@ -4,6 +4,9 @@ APP_KEY=
|
|||||||
APP_DEBUG=true
|
APP_DEBUG=true
|
||||||
APP_URL=http://localhost:8000
|
APP_URL=http://localhost:8000
|
||||||
|
|
||||||
|
# Set to false to disable public account registration.
|
||||||
|
PUBLIC_REGISTRATION_ENABLED=true
|
||||||
|
|
||||||
APP_LOCALE=en
|
APP_LOCALE=en
|
||||||
APP_FALLBACK_LOCALE=en
|
APP_FALLBACK_LOCALE=en
|
||||||
APP_FAKER_LOCALE=en_US
|
APP_FAKER_LOCALE=en_US
|
||||||
|
|||||||
+1
-1
@@ -161,7 +161,7 @@ return [
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
'features' => [
|
'features' => [
|
||||||
Features::registration(),
|
...(env('PUBLIC_REGISTRATION_ENABLED', true) ? [Features::registration()] : []),
|
||||||
Features::resetPasswords(),
|
Features::resetPasswords(),
|
||||||
Features::emailVerification(),
|
Features::emailVerification(),
|
||||||
Features::twoFactorAuthentication([
|
Features::twoFactorAuthentication([
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
|
|
||||||
|
trait BootsWithPublicRegistrationDisabled
|
||||||
|
{
|
||||||
|
public function createApplication(): Application
|
||||||
|
{
|
||||||
|
$previous = $_SERVER['PUBLIC_REGISTRATION_ENABLED'] ?? null;
|
||||||
|
$_SERVER['PUBLIC_REGISTRATION_ENABLED'] = 'false';
|
||||||
|
|
||||||
|
try {
|
||||||
|
return parent::createApplication();
|
||||||
|
} finally {
|
||||||
|
if ($previous === null) {
|
||||||
|
unset($_SERVER['PUBLIC_REGISTRATION_ENABLED']);
|
||||||
|
} else {
|
||||||
|
$_SERVER['PUBLIC_REGISTRATION_ENABLED'] = $previous;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uses(BootsWithPublicRegistrationDisabled::class);
|
||||||
|
|
||||||
|
test('guests cannot open the public registration form', function () {
|
||||||
|
$this->get('/register')->assertNotFound();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('public registration rejects form and JSON submissions without creating a user', function (bool $json) {
|
||||||
|
$credentials = [
|
||||||
|
'name' => 'Public Signup',
|
||||||
|
'email' => 'signup@example.com',
|
||||||
|
'password' => 'password',
|
||||||
|
'password_confirmation' => 'password',
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $json
|
||||||
|
? $this->postJson('/register', $credentials)
|
||||||
|
: $this->post('/register', $credentials);
|
||||||
|
|
||||||
|
$response->assertNotFound();
|
||||||
|
$this->assertDatabaseMissing('users', ['email' => $credentials['email']]);
|
||||||
|
$this->assertGuest();
|
||||||
|
})->with(['form' => [false], 'JSON' => [true]]);
|
||||||
|
|
||||||
|
test('login and welcome views hide their registration links', function () {
|
||||||
|
$registrationLink = 'href="'.url('/register').'"';
|
||||||
|
|
||||||
|
$this->get('/login')->assertOk()->assertDontSee($registrationLink, false);
|
||||||
|
$this->view('stylist-theme-frontend::welcome')->assertDontSee($registrationLink, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('administrators can create users while public registration is disabled', function () {
|
||||||
|
$admin = User::factory()->create(['helpdesk_admin' => true]);
|
||||||
|
|
||||||
|
$this->actingAs($admin)->post(route('user-management.store'), [
|
||||||
|
'name' => 'Provisioned User',
|
||||||
|
'email' => 'provisioned@example.com',
|
||||||
|
'password' => 'password',
|
||||||
|
'password_confirmation' => 'password',
|
||||||
|
])->assertSessionHasNoErrors()->assertRedirect();
|
||||||
|
|
||||||
|
$user = User::query()->where('email', 'provisioned@example.com')->sole();
|
||||||
|
expect($user->hasVerifiedEmail())->toBeTrue();
|
||||||
|
$this->assertAuthenticatedAs($admin);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user