mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 14:25:40 +08:00
feat : common redis cache and common logger
This commit is contained in:
@@ -10,15 +10,20 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\AdminUser;
|
||||
|
||||
use App\Cache\Redis\Lua\RateLimit;
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Lib\Jwt\RequestScopedTokenTrait;
|
||||
use App\Repository\AdminUserRepository;
|
||||
use App\Service\Admin\BaseAdminService;
|
||||
use App\Service\BaseTokenService;
|
||||
use App\Trait\AdminUserTrait;
|
||||
use Hyperf\Collection\Arr;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Lcobucci\JWT\Token\RegisteredClaims;
|
||||
|
||||
class UserService extends BaseAdminService
|
||||
{
|
||||
use RequestScopedTokenTrait;
|
||||
use AdminUserTrait;
|
||||
|
||||
/**
|
||||
* @var BaseTokenService
|
||||
@@ -26,13 +31,26 @@ class UserService extends BaseAdminService
|
||||
#[Inject]
|
||||
protected BaseTokenService $tokenService;
|
||||
|
||||
#[Inject]
|
||||
protected RedisCache $redisCache;
|
||||
|
||||
public function handle(): array
|
||||
{
|
||||
var_dump($this->getToken()->claims()->all());
|
||||
var_dump($this->getToken()->claims()->get(RegisteredClaims::ID));
|
||||
var_dump($this->getToken()->claims()->get(RegisteredClaims::AUDIENCE));
|
||||
$this->redisCache->with()->set('123',1);
|
||||
$this->redisCache->with()->lua(RateLimit::class)->check('user:123', 10, 60);
|
||||
|
||||
return $this->adminReturn->success(
|
||||
'success',
|
||||
Arr::only(
|
||||
$this->getAdminUserInfo($this->adminId) ?: [],
|
||||
['username', 'nickname', 'avatar', 'signed', 'backend_setting', 'phone', 'email']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function user()
|
||||
{
|
||||
|
||||
return $this->adminReturn->success();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,13 +10,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin;
|
||||
|
||||
use App\Lib\Jwt\RequestScopedTokenTrait;
|
||||
use App\Lib\Return\AdminReturn;
|
||||
use Hyperf\Context\Context;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
use Lcobucci\JWT\Token\RegisteredClaims;
|
||||
|
||||
abstract class BaseAdminService
|
||||
{
|
||||
use RequestScopedTokenTrait;
|
||||
|
||||
/**
|
||||
* 请求对象注入
|
||||
* @var RequestInterface
|
||||
@@ -42,7 +45,7 @@ abstract class BaseAdminService
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->adminId = Context::get('admin_id',0);
|
||||
$this->adminId = (int) $this->getToken()?->claims()?->get(RegisteredClaims::ID) ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,8 +19,6 @@ use Lcobucci\JWT\UnencryptedToken;
|
||||
|
||||
class RefreshService extends BaseAdminService
|
||||
{
|
||||
use RequestScopedTokenTrait;
|
||||
|
||||
/**
|
||||
* @var BaseTokenService
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user