OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
63
app/Domain/Auth/Models/AuthenticatableUser.php
Normal file
63
app/Domain/Auth/Models/AuthenticatableUser.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Auth\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
|
||||
/**
|
||||
* Lightweight Authenticatable wrapper around a user-data row.
|
||||
*
|
||||
* Replaces the `(object) $userRow` stdClass casts in AuthUser/ApiGuard so the provider/guard
|
||||
* methods satisfy their `?Authenticatable` contracts. It uses dynamic properties on purpose so it
|
||||
* stays a behavioural drop-in for the old stdClass cast — same property reads, same json/array
|
||||
* serialization, truthy even when empty — and merely ADDS the Authenticatable accessor methods.
|
||||
*/
|
||||
#[\AllowDynamicProperties]
|
||||
class AuthenticatableUser implements Authenticatable
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $attributes A user row (column => value).
|
||||
*/
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
foreach ($attributes as $key => $value) {
|
||||
$this->{$key} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAuthIdentifierName(): string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
public function getAuthIdentifier(): mixed
|
||||
{
|
||||
return $this->id ?? null;
|
||||
}
|
||||
|
||||
public function getAuthPasswordName(): string
|
||||
{
|
||||
return 'password';
|
||||
}
|
||||
|
||||
public function getAuthPassword(): string
|
||||
{
|
||||
return $this->password ?? '';
|
||||
}
|
||||
|
||||
public function getRememberToken(): string
|
||||
{
|
||||
return $this->remember_token ?? '';
|
||||
}
|
||||
|
||||
public function setRememberToken($value): void
|
||||
{
|
||||
// No-op: Leantime does not persist remember tokens (mirrors Auth::setRememberToken and
|
||||
// AuthUser::updateRememberToken, which are likewise not implemented).
|
||||
}
|
||||
|
||||
public function getRememberTokenName(): string
|
||||
{
|
||||
return 'remember_token';
|
||||
}
|
||||
}
|
||||
24
app/Domain/Auth/Models/CurrentUser.php
Normal file
24
app/Domain/Auth/Models/CurrentUser.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Auth\Models;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
class CurrentUser
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public string $name,
|
||||
public string $profileId,
|
||||
public string $mail,
|
||||
public int $clientId,
|
||||
public string $role,
|
||||
public mixed $settings,
|
||||
public bool $twoFAEnabled,
|
||||
public bool $twoFAVerified,
|
||||
public string $twoFASecret,
|
||||
public bool $isExternalAuth,
|
||||
public CarbonImmutable $createdOn,
|
||||
public CarbonImmutable $modified,
|
||||
) {}
|
||||
}
|
||||
61
app/Domain/Auth/Models/Roles.php
Normal file
61
app/Domain/Auth/Models/Roles.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Auth\Models;
|
||||
|
||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||
use Leantime\Core\Events\DispatchesEvents;
|
||||
|
||||
/**
|
||||
* @TODO: Role names should be converted into an enum.
|
||||
*/
|
||||
class Roles
|
||||
{
|
||||
use DispatchesEvents;
|
||||
|
||||
public static string $readonly = 'readonly';
|
||||
|
||||
public static string $commenter = 'commenter';
|
||||
|
||||
public static string $editor = 'editor';
|
||||
|
||||
public static string $manager = 'manager';
|
||||
|
||||
public static string $admin = 'admin';
|
||||
|
||||
public static string $owner = 'owner';
|
||||
|
||||
private static array $roleKeys = [
|
||||
5 => 'readonly', // prev: none
|
||||
10 => 'commenter', // prev: client
|
||||
20 => 'editor', // prev: developer
|
||||
30 => 'manager', // prev: clientmanager
|
||||
40 => 'admin', // prev: manager
|
||||
50 => 'owner', // prev: admin
|
||||
];
|
||||
|
||||
/**
|
||||
* @throws BindingResolutionException
|
||||
*/
|
||||
private static function getFilteredRoles(): mixed
|
||||
{
|
||||
return self::dispatch_filter('available_roles', self::$roleKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|mixed
|
||||
*
|
||||
* @throws BindingResolutionException
|
||||
*/
|
||||
public static function getRoleString(mixed $key): mixed
|
||||
{
|
||||
return self::getFilteredRoles()[$key] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BindingResolutionException
|
||||
*/
|
||||
public static function getRoles(): mixed
|
||||
{
|
||||
return self::getFilteredRoles();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user