Migration complete
This commit is contained in:
@@ -5,32 +5,60 @@ namespace App\Auth;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Xenforo authentification bridge.
|
||||
*/
|
||||
class XenForoGuard implements Guard
|
||||
{
|
||||
|
||||
/**
|
||||
* Authenticated user.
|
||||
* @var XenForoUser|null
|
||||
*/
|
||||
private ?XenForoUser $user = null;
|
||||
|
||||
public function __construct(private readonly Request $request) {}
|
||||
|
||||
/**
|
||||
* Check if user is logged in.
|
||||
* @return bool
|
||||
*/
|
||||
public function check(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is a guest.
|
||||
* @return bool
|
||||
*/
|
||||
public function guest(): bool
|
||||
{
|
||||
return ! $this->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user ID.
|
||||
* @return mixed
|
||||
*/
|
||||
public function id(): mixed
|
||||
{
|
||||
return $this->user()?->getAuthIdentifier();
|
||||
}
|
||||
|
||||
/**
|
||||
* If user is defined.
|
||||
* @return bool
|
||||
*/
|
||||
public function hasUser(): bool
|
||||
{
|
||||
return $this->user !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Login user.
|
||||
* @return XenForoUser|null
|
||||
*/
|
||||
public function user(): ?XenForoUser
|
||||
{
|
||||
if ($this->hasUser())
|
||||
@@ -64,6 +92,13 @@ class XenForoGuard implements Guard
|
||||
return $this->user = new XenForoUser($xfUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unused.
|
||||
*
|
||||
* @param array $credentials
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate(array $credentials = []): bool
|
||||
{
|
||||
return false;
|
||||
@@ -74,6 +109,10 @@ class XenForoGuard implements Guard
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unused.
|
||||
* @return void
|
||||
*/
|
||||
public function logout(): void
|
||||
{
|
||||
redirect('/');
|
||||
|
||||
@@ -10,11 +10,67 @@ use Filament\Panel;
|
||||
use Illuminate\Contracts\Auth\Access\Authorizable;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
|
||||
/**
|
||||
* Xenforo user custom model used for authentification.
|
||||
*
|
||||
* @property-read int $user_id
|
||||
* @property-read string $username
|
||||
* @property-read int $username_date
|
||||
* @property-read int $username_date_visible
|
||||
* @property-read string $email
|
||||
* @property-read string $custom_title
|
||||
* @property-read int $language_id
|
||||
* @property-read int $style_id
|
||||
* @property-read string $style_variation
|
||||
* @property-read string $timezone
|
||||
* @property-read int $visible
|
||||
* @property-read int $activity_visible
|
||||
* @property-read int $user_group_id
|
||||
* @property-read array $secondary_group_ids
|
||||
* @property-read int $display_style_group_id
|
||||
* @property-read int $permission_combination_id
|
||||
* @property-read int $message_count
|
||||
* @property-read int $question_solution_count
|
||||
* @property-read int $conversations_unread
|
||||
* @property-read int $register_date
|
||||
* @property-read int $last_activity
|
||||
* @property-read int $last_summary_email_date
|
||||
* @property-read int $trophy_points
|
||||
* @property-read int $alerts_unviewed
|
||||
* @property-read int $alerts_unread
|
||||
* @property-read int $avatar_date
|
||||
* @property-read int $avatar_width
|
||||
* @property-read int $avatar_height
|
||||
* @property-read int $avatar_highdpi
|
||||
* @property-read int $avatar_optimized
|
||||
* @property-read string $gravatar
|
||||
* @property-read string $user_state
|
||||
* @property-read string $security_lock
|
||||
* @property-read int $is_moderator
|
||||
* @property-read int $is_admin
|
||||
* @property-read int $is_banned
|
||||
* @property-read int $reaction_score
|
||||
* @property-read int $vote_score
|
||||
* @property-read int $warning_points
|
||||
* @property-read int $is_staff
|
||||
* @property-read string $secret_key
|
||||
* @property-read int $privacy_policy_accepted
|
||||
* @property-read int $terms_accepted
|
||||
*
|
||||
* Custom properties.
|
||||
*
|
||||
* @property-read int $rhpz_entry_count
|
||||
*/
|
||||
class XenForoUser extends XenForoData implements Authenticatable, Authorizable, FilamentUser, HasName {
|
||||
|
||||
use \Illuminate\Foundation\Auth\Access\Authorizable;
|
||||
|
||||
/**
|
||||
* Permissions identifier array.
|
||||
* @var array|null
|
||||
*/
|
||||
public ?array $permissions = null;
|
||||
|
||||
public function getAuthIdentifierName(): string
|
||||
{
|
||||
return 'user_id';
|
||||
@@ -51,9 +107,9 @@ class XenForoUser extends XenForoData implements Authenticatable, Authorizable,
|
||||
}
|
||||
|
||||
/**
|
||||
* Get XenForo avatar if it exist.
|
||||
* Get XenForo avatar if it exists.
|
||||
*
|
||||
* @param string $xfSize
|
||||
* @param string $xfSize s/m/...
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
@@ -70,6 +126,14 @@ class XenForoUser extends XenForoData implements Authenticatable, Authorizable,
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom can function. Check XF user permissions.
|
||||
*
|
||||
* @param string $permissionGroup
|
||||
* @param string $permissionName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function _can(string $permissionGroup, string $permissionName): bool
|
||||
{
|
||||
if( !$this->permissions ){
|
||||
@@ -105,4 +169,9 @@ class XenForoUser extends XenForoData implements Authenticatable, Authorizable,
|
||||
{
|
||||
return 'user_id';
|
||||
}
|
||||
|
||||
public function validState(): bool
|
||||
{
|
||||
return $this->user_state === 'valid';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user