85 lines
1.9 KiB
PHP
85 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Auth;
|
|
|
|
use App\Services\XenforoService;
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
|
|
class XenForoUser implements Authenticatable {
|
|
|
|
public ?array $permissions = null;
|
|
private XenforoService $services;
|
|
|
|
public function __construct(public readonly object $data) {
|
|
$this->services = app(XenforoService::class);
|
|
}
|
|
|
|
public function __get(string $name): mixed {
|
|
return $this->data->$name ?? null;
|
|
}
|
|
|
|
public function getAuthIdentifierName(): string
|
|
{
|
|
return 'user_id';
|
|
}
|
|
|
|
public function getAuthIdentifier(): mixed
|
|
{
|
|
return $this->data->user_id;
|
|
}
|
|
|
|
public function getAuthPasswordName(): string
|
|
{
|
|
return 'password';
|
|
}
|
|
|
|
public function getAuthPassword(): string
|
|
{
|
|
return '';
|
|
}
|
|
|
|
public function getRememberToken(): string
|
|
{
|
|
return '';
|
|
}
|
|
|
|
public function setRememberToken($value): void
|
|
{
|
|
return;
|
|
}
|
|
|
|
public function getRememberTokenName(): string
|
|
{
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* Get XenForo avatar if it exist.
|
|
*
|
|
* @param string $xfSize
|
|
*
|
|
* @return string|null
|
|
*/
|
|
public function getAvatarUrl( string $xfSize = 'm' ): ?string
|
|
{
|
|
$userId = $this->data->user_id;
|
|
$avatarDate = $this->data->avatar_date;
|
|
|
|
if( $avatarDate ){
|
|
$group = floor($userId / 1000);
|
|
return config('app.forum_url') . "/data/avatars/{$xfSize}/{$group}/{$userId}.jpg?{$avatarDate}";
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function can(string $permissionGroup, string $permissionName): bool
|
|
{
|
|
if( !$this->permissions ){
|
|
$this->permissions = $this->services->getPermissions($this->data->user_id, $this->data->permission_combination_id);
|
|
}
|
|
|
|
return ($this->permissions[$permissionGroup][$permissionName] ?? 0) === true;
|
|
}
|
|
}
|