109 lines
2.4 KiB
PHP
109 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Auth;
|
|
|
|
use App\Services\XenforoService;
|
|
use App\XenForoDataTypes\XenForoData;
|
|
use Filament\Models\Contracts\FilamentUser;
|
|
use Filament\Models\Contracts\HasName;
|
|
use Filament\Panel;
|
|
use Illuminate\Contracts\Auth\Access\Authorizable;
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
|
|
class XenForoUser extends XenForoData implements Authenticatable, Authorizable, FilamentUser, HasName {
|
|
|
|
use \Illuminate\Foundation\Auth\Access\Authorizable;
|
|
|
|
public ?array $permissions = 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;
|
|
}
|
|
|
|
/* FILAMENT COMPATIBILITY */
|
|
|
|
public function canAccessPanel(Panel $panel): bool
|
|
{
|
|
return $this->is_admin === 1;
|
|
}
|
|
|
|
public function getFilamentName(): string
|
|
{
|
|
return $this->username ?? "XF";
|
|
}
|
|
|
|
public function getAttributeValue($key)
|
|
{
|
|
return $this->{$key} ?? null;
|
|
}
|
|
|
|
public function getKey()
|
|
{
|
|
return $this->data->user_id;
|
|
}
|
|
|
|
public function getKeyName()
|
|
{
|
|
return 'user_id';
|
|
}
|
|
}
|