From 8a1fa3855074ac58056ce1e591cb31c190fe3b7b Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 19 Dec 2022 22:43:45 -0700 Subject: [PATCH] Update AdminInviteCommand, improve expiration logic --- app/Console/Commands/AdminInviteCommand.php | 26 +++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/AdminInviteCommand.php b/app/Console/Commands/AdminInviteCommand.php index a89779b0e..6efede1c8 100644 --- a/app/Console/Commands/AdminInviteCommand.php +++ b/app/Console/Commands/AdminInviteCommand.php @@ -136,6 +136,11 @@ class AdminInviteCommand extends Command { $this->info('View Invites'); $this->line('============='); + if(AdminInvite::count() == 0) { + $this->line(' '); + $this->error('No invites found!'); + return; + } $this->table( ['Invite Code', 'Uses Left', 'Expires'], AdminInvite::all(['invite_code', 'max_uses', 'uses', 'expires_at'])->map(function($invite) { @@ -151,13 +156,24 @@ class AdminInviteCommand extends Command protected function expire() { $token = $this->anticipate('Enter invite code to expire', function($val) { + if(!$val || empty($val)) { + return []; + } return AdminInvite::where('invite_code', 'like', '%' . $val . '%')->pluck('invite_code')->toArray(); }); - $invite = AdminInvite::whereInviteCode($token)->firstOrFail(); - $invite->max_uses = 1; - $invite->expires_at = now()->subHours(2); - $invite->save(); - $this->info('Expired the following invite: ' . $invite->url()); + if(!$token || empty($token)) { + $this->error('Invalid invite code'); + return; + } + $invite = AdminInvite::whereInviteCode($token)->first(); + if(!$invite) { + $this->error('Invalid invite code'); + return; + } + $invite->max_uses = 1; + $invite->expires_at = now()->subHours(2); + $invite->save(); + $this->info('Expired the following invite: ' . $invite->url()); } }