This commit is contained in:
2021-03-19 16:04:08 +08:00
parent c074b37e2b
commit fc18533f7c
+32 -6
View File
@@ -384,9 +384,36 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
* @return mixed * @return mixed
* @throws * @throws
*/ */
public function getCurrentOnlineUser(): mixed public function getCurrentOnlineUser(): int
{ {
$this->data = request()->headers->getHeaders(); $this->data = request()->headers->getHeaders();
return $this->loadByCache();
}
/**
* @param string $token
* @param string $source
* @return mixed
* @throws AuthException
*/
public function getOnlineUserByToken(string $token, string $source = 'BROWSER'): int
{
$this->data['token'] = $token;
$this->data['source'] = $source;
return $this->loadByCache();
}
/**
* @return int
* @throws AuthException
* @throws Exception
*/
private function loadByCache(): int
{
$model = $this->getUserModel(); $model = $this->getUserModel();
if (empty($model)) { if (empty($model)) {
throw new AuthException('授权信息已过期!'); throw new AuthException('授权信息已过期!');
@@ -397,16 +424,17 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
if (!$this->check($this->data, (int)$model['user'])) { if (!$this->check($this->data, (int)$model['user'])) {
throw new AuthException('授权信息不合法!'); throw new AuthException('授权信息不合法!');
} }
$this->expireRefresh(); $this->expireRefresh();
return $model['user']; return (int)$model['user'];
} }
/** /**
* @param array $header * @param array $header
* @return mixed * @return mixed
* @throws AuthException * @throws AuthException
* @throws ComponentException
* @throws Exception * @throws Exception
*/ */
public static function checkAuth(array $header = []): mixed public static function checkAuth(array $header = []): mixed
@@ -454,9 +482,7 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
/** /**
* @return Redis|\Redis * @return Redis|\Redis
* @throws ComponentException * @throws
* @throws ReflectionException
* @throws NotFindClassException
*/ */
private function getRedis(): Redis|\Redis private function getRedis(): Redis|\Redis
{ {