Update AdminInviteController

pull/6637/head
Daniel Supernault 3 weeks ago
parent d8412ec0f5
commit 9fe9b7eb32
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1

@ -41,6 +41,7 @@ class AdminInviteCommand extends Command
$this->line(' ');
$this->info(' Manage user registration invite links');
$this->line(' ');
$this->handleExpiredInvites();
return match ($this->choice(
'Select an action',
@ -48,17 +49,24 @@ class AdminInviteCommand extends Command
'Create invite',
'View invites',
'Expire invite',
'Expire all invites',
'Cancel',
],
3
4
)) {
'Create invite' => $this->create(),
'View invites' => $this->view(),
'Expire invite' => $this->expire(),
'Expire all invites' => $this->expireAll(),
default => Command::SUCCESS,
};
}
protected function handleExpiredInvites()
{
AdminInvite::whereNotNull('expires_at')->where('expires_at', '<', now())->delete();
}
protected function create(): int
{
$this->info('Create Invite');
@ -78,14 +86,14 @@ class AdminInviteCommand extends Command
$expires = match ($this->choice(
'Set an invite expiry date?',
[
'No - invite never expires',
'Yes - expire after 24 hours',
'No - invite never expires',
'Custom - let me pick an expiry date',
],
0
)) {
'No - invite never expires' => null,
'Yes - expire after 24 hours' => now()->addHours(24),
'No - invite never expires' => null,
'Custom - let me pick an expiry date' => now()->addDays(
(int) $this->ask('Custom expiry date in days', 14)
),
@ -172,6 +180,14 @@ class AdminInviteCommand extends Command
return Command::SUCCESS;
}
protected function expireAll(): int
{
$count = AdminInvite::query()->delete();
$this->info('Deleted '.$count.' invites');
return Command::SUCCESS;
}
protected function promptForEmail(): string
{
do {

@ -123,7 +123,7 @@ class AdminInviteController extends Controller
$emailRules = [
'required',
'string',
'email',
'email:strict,rfc,dns,spoof,filter',
'max:255',
'unique:users',
function ($attribute, $value, $fail) {
@ -189,7 +189,7 @@ class AdminInviteController extends Controller
'email' => [
'required',
'string',
'email',
'email:strict,rfc,dns,spoof,filter',
'max:255',
'unique:users',
function ($attribute, $value, $fail) {

Loading…
Cancel
Save