mirror of https://github.com/pixelfed/pixelfed
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.1 KiB
PHP
53 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Str;
|
|
|
|
class AdminInvite extends Model
|
|
{
|
|
protected $casts = [
|
|
'used_by' => 'array',
|
|
'expires_at' => 'datetime',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'description',
|
|
'message',
|
|
'max_uses',
|
|
'uses',
|
|
'skip_email_verification',
|
|
'expires_at',
|
|
'admin_user_id',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (AdminInvite $invite) {
|
|
$invite->invite_code = Str::uuid().Str::random(random_int(1, 6));
|
|
});
|
|
}
|
|
|
|
public function url(): string
|
|
{
|
|
return url('/auth/invite/a/'.$this->invite_code);
|
|
}
|
|
|
|
public function isActive(): bool
|
|
{
|
|
return $this->hasUsesRemaining() && ! $this->hasExpired();
|
|
}
|
|
|
|
public function hasExpired(): bool
|
|
{
|
|
return $this->expires_at?->isPast() ?? false;
|
|
}
|
|
|
|
public function hasUsesRemaining(): bool
|
|
{
|
|
return $this->max_uses === 0 || is_null($this->max_uses) || $this->uses < $this->max_uses;
|
|
}
|
|
}
|