Files
firefly-iii/app/Models/InvitedUser.php

70 lines
2.1 KiB
PHP
Raw Normal View History

2022-10-01 12:21:42 +02:00
<?php
2022-10-16 19:29:53 +02:00
2022-10-01 12:21:42 +02:00
/*
* InvitedUser.php
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2022-10-16 19:29:53 +02:00
declare(strict_types=1);
2022-10-01 12:21:42 +02:00
namespace FireflyIII\Models;
2024-11-09 12:19:01 +01:00
use FireflyIII\Casts\SeparateTimezoneCaster;
2023-12-10 06:51:59 +01:00
use FireflyIII\Support\Models\ReturnsIntegerIdTrait;
2023-11-05 19:41:37 +01:00
use FireflyIII\Support\Models\ReturnsIntegerUserIdTrait;
2022-10-01 12:21:42 +02:00
use FireflyIII\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
2023-03-09 06:33:23 +01:00
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2023-12-10 06:51:59 +01:00
2022-10-01 12:21:42 +02:00
class InvitedUser extends Model
{
2023-11-05 19:41:37 +01:00
use ReturnsIntegerIdTrait;
use ReturnsIntegerUserIdTrait;
2022-10-01 12:21:42 +02:00
protected $casts
2023-02-22 18:14:14 +01:00
= [
2024-11-09 12:19:01 +01:00
'expires' => SeparateTimezoneCaster::class,
'redeemed' => 'boolean',
];
2024-11-06 12:01:29 +01:00
protected $fillable = ['user_id', 'email', 'invite_code', 'expires', 'expires_tz', 'redeemed'];
2022-10-01 12:21:42 +02:00
2023-03-09 06:33:23 +01:00
/**
* Route binder. Converts the key in the URL to the specified object (or throw 404).
*/
2023-11-04 14:18:49 +01:00
public static function routeBinder(string $value): self
2023-03-09 06:33:23 +01:00
{
if (auth()->check()) {
2024-12-22 08:43:12 +01:00
$attemptId = (int) $value;
2023-12-20 19:35:52 +01:00
/** @var null|InvitedUser $attempt */
$attempt = self::find($attemptId);
2023-03-09 06:33:23 +01:00
if (null !== $attempt) {
return $attempt;
}
}
2023-12-20 19:35:52 +01:00
2023-03-09 06:33:23 +01:00
throw new NotFoundHttpException();
}
2023-05-29 13:56:55 +02:00
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
2022-10-01 12:21:42 +02:00
}