Skip to content

Commit

Permalink
Add option to automatically disable newly created accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaszkadziela committed Jun 21, 2024
1 parent f7771a4 commit 3466cee
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

AUTH_NEW_USERS_ENABLED=true

TELESCOPE_ENABLED=true
TELESCOPE_FILTERING_ENABLED=true
TELESCOPE_LOG_LEVEL=error
8 changes: 5 additions & 3 deletions app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Lang;
use Illuminate\Validation\Rules\Password;
use Illuminate\Validation\ValidationException;
Expand Down Expand Up @@ -39,12 +38,15 @@ public function store(Request $request): RedirectResponse
'password' => ['required', 'confirmed', Password::defaults()],
]);

$user = User::create([
$user = new User([
'username' => $request->username,
'email' => $request->email,
'password' => Hash::make($request->password),
'password' => $request->password,
]);

$user->is_enabled = (bool)config('auth.new_users_enabled');
$user->save();

event(new Registered($user));

Auth::login($user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function callback(): RedirectResponse
'password' => $password,
]);

$user->is_enabled = (bool)config('auth.new_users_enabled');
$user->email_verified_at = Carbon::now();
$user->save();

Expand Down
12 changes: 12 additions & 0 deletions config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,16 @@

'password_timeout' => 10800,

/*
|--------------------------------------------------------------------------
| New Users Enabled
|--------------------------------------------------------------------------
|
| Define whether newly registered users should be enabled by default.
| Please note that "everestserver:create-user" command is exempted from this policy.
|
*/

'new_users_enabled' => env('AUTH_NEW_USERS_ENABLED', true),

];

0 comments on commit 3466cee

Please sign in to comment.