2023-06-09 13:55:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
|
|
class TeamInvitation extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'team_id',
|
2023-06-12 10:00:01 +00:00
|
|
|
'uuid',
|
2023-06-09 13:55:21 +00:00
|
|
|
'email',
|
|
|
|
|
'role',
|
|
|
|
|
'link',
|
2023-06-12 10:00:01 +00:00
|
|
|
'via',
|
2023-06-09 13:55:21 +00:00
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2025-09-16 14:31:48 +00:00
|
|
|
/**
|
|
|
|
|
* Set the email attribute to lowercase.
|
|
|
|
|
*/
|
2025-09-25 09:33:32 +00:00
|
|
|
public function setEmailAttribute(string $value): void
|
2025-09-16 14:31:48 +00:00
|
|
|
{
|
|
|
|
|
$this->attributes['email'] = strtolower($value);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-09 13:55:21 +00:00
|
|
|
public function team()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Team::class);
|
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-10-24 11:44:38 +00:00
|
|
|
public static function ownedByCurrentTeam()
|
|
|
|
|
{
|
|
|
|
|
return TeamInvitation::whereTeamId(currentTeam()->id);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
public function isValid()
|
|
|
|
|
{
|
2023-09-15 09:19:36 +00:00
|
|
|
$createdAt = $this->created_at;
|
2024-11-07 11:32:23 +00:00
|
|
|
$diff = $createdAt->diffInDays(now());
|
|
|
|
|
if ($diff <= config('constants.invitation.link.expiration_days')) {
|
2023-09-15 09:19:36 +00:00
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
$this->delete();
|
2025-06-26 10:23:08 +00:00
|
|
|
$user = User::whereEmail($this->email)->first();
|
|
|
|
|
if (filled($user)) {
|
|
|
|
|
$user->deleteIfNotVerifiedAndForcePasswordReset();
|
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-03-05 08:19:15 +00:00
|
|
|
return false;
|
2023-09-15 09:19:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-06-09 13:55:21 +00:00
|
|
|
}
|