mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-14 02:24: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,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();
|
||||||
|
|
Loading…
Reference in a new issue