mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-12 17:44:31 +00:00
Update AdminInviteCommand, improve expiration logic
This commit is contained in:
parent
d3e6229946
commit
8a1fa38550
1 changed files with 21 additions and 5 deletions
|
@ -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,13 +156,24 @@ 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)) {
|
||||||
$invite->max_uses = 1;
|
$this->error('Invalid invite code');
|
||||||
$invite->expires_at = now()->subHours(2);
|
return;
|
||||||
$invite->save();
|
}
|
||||||
$this->info('Expired the following invite: ' . $invite->url());
|
$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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue