Update AdminInviteCommand, improve expiration logic

This commit is contained in:
Daniel Supernault 2022-12-19 22:43:45 -07:00
parent d3e6229946
commit 8a1fa38550
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -136,6 +136,11 @@ class AdminInviteCommand extends Command
{ {
$this->info('View Invites'); $this->info('View Invites');
$this->line('============='); $this->line('=============');
if(AdminInvite::count() == 0) {
$this->line(' ');
$this->error('No invites found!');
return;
}
$this->table( $this->table(
['Invite Code', 'Uses Left', 'Expires'], ['Invite Code', 'Uses Left', 'Expires'],
AdminInvite::all(['invite_code', 'max_uses', 'uses', 'expires_at'])->map(function($invite) { AdminInvite::all(['invite_code', 'max_uses', 'uses', 'expires_at'])->map(function($invite) {
@ -151,10 +156,21 @@ class AdminInviteCommand extends Command
protected function expire() protected function expire()
{ {
$token = $this->anticipate('Enter invite code to expire', function($val) { $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(); return AdminInvite::where('invite_code', 'like', '%' . $val . '%')->pluck('invite_code')->toArray();
}); });
$invite = AdminInvite::whereInviteCode($token)->firstOrFail(); 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->max_uses = 1;
$invite->expires_at = now()->subHours(2); $invite->expires_at = now()->subHours(2);
$invite->save(); $invite->save();