first commit
This commit is contained in:
41
app/Models/ThemeParkUser.php
Normal file
41
app/Models/ThemeParkUser.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Http\Services\PhantasialandApi;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ThemeParkUser extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'username',
|
||||
'password',
|
||||
];
|
||||
|
||||
|
||||
public function authenticate(): void
|
||||
{
|
||||
if(!$this->isTokenExpired()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->refreshToken();
|
||||
}
|
||||
|
||||
private function refreshToken(): void
|
||||
{
|
||||
$api = app(PhantasialandApi::class);
|
||||
$token = $api->getAccessToken($this);
|
||||
$this->access_token = $token;
|
||||
$this->access_token_expires_at = now()->addMonths(11);
|
||||
$this->save();
|
||||
}
|
||||
|
||||
private function isTokenExpired(): bool
|
||||
{
|
||||
return $this?->access_token_expires_at < now();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user