Skip to content

Commit 08ab522

Browse files
Merge pull request #376 from crimsonstrife/dev
Update new Prod version
2 parents dd14862 + 54c5815 commit 08ab522

13 files changed

Lines changed: 275 additions & 102 deletions

File tree

app/Actions/Fortify/CreateNewUser.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
use App\Models\Team;
66
use App\Models\User;
7+
use App\Settings\AuthSettings;
78
use Illuminate\Support\Facades\DB;
89
use Illuminate\Support\Facades\Hash;
910
use Illuminate\Support\Facades\Validator;
11+
use Illuminate\Validation\ValidationException;
1012
use Laravel\Fortify\Contracts\CreatesNewUsers;
1113
use Laravel\Jetstream\Jetstream;
14+
use Throwable;
1215

1316
class CreateNewUser implements CreatesNewUsers
1417
{
@@ -18,10 +21,17 @@ class CreateNewUser implements CreatesNewUsers
1821
* Create a newly registered user.
1922
*
2023
* @param array<string, string> $input
21-
* @throws \Throwable
24+
* @throws Throwable
2225
*/
2326
public function create(array $input): User
2427
{
28+
$settings = app(AuthSettings::class);
29+
if (!($settings->allowRegistration ?? true)) {
30+
throw ValidationException::withMessages([
31+
'email' => __('Registration is currently closed.'),
32+
]);
33+
}
34+
2535
Validator::make($input, [
2636
'name' => ['required', 'string', 'max:255'],
2737
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App\Filament\Pages\Settings;
4+
5+
use App\Settings\AuthSettings;
6+
use Filament\Forms\Components\Toggle;
7+
use Filament\Pages\SettingsPage;
8+
use Filament\Schemas\Schema;
9+
use Filament\Support\Icons\Heroicon;
10+
11+
class ManageAuthSettings extends SettingsPage
12+
{
13+
protected static string $settings = AuthSettings::class;
14+
15+
protected static ?string $title = 'Authentication';
16+
protected static string|null|\UnitEnum $navigationGroup = 'Settings';
17+
protected static string|\BackedEnum|null $navigationIcon = Heroicon::OutlinedUserPlus;
18+
19+
public function form(Schema $schema): Schema
20+
{
21+
return $schema->schema([
22+
Toggle::make('allowRegistration')
23+
->label('Allow self-registration')
24+
->helperText('When off, only admins can create accounts.'),
25+
]);
26+
}
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use App\Settings\AuthSettings;
6+
use Closure;
7+
use Illuminate\Http\Request;
8+
use Symfony\Component\HttpFoundation\Response;
9+
10+
/**
11+
* Prevents access to the registration page when disabled.
12+
*/
13+
readonly class EnsureRegistrationIsEnabled
14+
{
15+
public function __construct(private AuthSettings $settings)
16+
{
17+
}
18+
19+
public function handle(Request $request, Closure $next): Response
20+
{
21+
if (!($this->settings->allowRegistration ?? true) && $request->routeIs('register')) {
22+
return redirect()->route('login')
23+
->with('status', __('Registration is currently closed.'));
24+
}
25+
26+
return $next($request);
27+
}
28+
}

app/Settings/AuthSettings.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Settings;
4+
5+
use Spatie\LaravelSettings\Settings;
6+
7+
/**
8+
* @phpstan-type AuthSettingsShape array{allowRegistration: bool}
9+
*/
10+
class AuthSettings extends Settings
11+
{
12+
public bool $allowRegistration = false;
13+
14+
public static function group(): string
15+
{
16+
return 'auth';
17+
}
18+
}

bootstrap/app.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use App\Http\Middleware\AllowPublicEmbed;
4+
use App\Http\Middleware\EnsureRegistrationIsEnabled;
45
use App\Http\Middleware\EnsureSupportIdentity;
56
use App\Http\Middleware\SetPermissionsTeamContext;
67
use App\Http\Middleware\VerifyIngestKey;
@@ -23,6 +24,7 @@
2324
$middleware->alias([
2425
'support.identity' => EnsureSupportIdentity::class,
2526
'ingest.key' => VerifyIngestKey::class,
27+
'auth.registration' => EnsureRegistrationIsEnabled::class,
2628
]);
2729
$middleware->group('api', [
2830
EnsureFrontendRequestsAreStateful::class,

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
"ext-mbstring": "*",
1313
"ext-zip": "*",
1414
"ashallendesign/short-url": "^8.3",
15-
"blaspsoft/blasp": "^2.1",
15+
"blaspsoft/blasp": "^3.0",
1616
"calebporzio/sushi": "^2.5",
1717
"codedge/laravel-selfupdater": "^3.10",
1818
"dedoc/scramble": "^0.12.34",
1919
"doctrine/dbal": "^4.3",
2020
"filament/filament": "^4.0",
21-
"filament/spatie-laravel-settings-plugin": "^v4.0.19",
21+
"filament/spatie-laravel-settings-plugin": "^4.0",
2222
"guzzlehttp/guzzle": "^7.10",
2323
"kalnoy/nestedset": "^6.0",
2424
"knuckleswtf/scribe": "^5.3",

0 commit comments

Comments
 (0)