fixed bug
This commit is contained in:
parent
9da4072b30
commit
64ce1243b4
@ -4,6 +4,11 @@ namespace app;
|
|||||||
// 应用请求对象类
|
// 应用请求对象类
|
||||||
|
|
||||||
use catcher\CatchAuth;
|
use catcher\CatchAuth;
|
||||||
|
use catcher\Code;
|
||||||
|
use catcher\exceptions\FailedException;
|
||||||
|
use thans\jwt\exception\TokenBlacklistException;
|
||||||
|
use thans\jwt\exception\TokenExpiredException;
|
||||||
|
use thans\jwt\exception\TokenInvalidException;
|
||||||
|
|
||||||
class Request extends \think\Request
|
class Request extends \think\Request
|
||||||
{
|
{
|
||||||
@ -21,6 +26,21 @@ class Request extends \think\Request
|
|||||||
$this->auth = new CatchAuth;
|
$this->auth = new CatchAuth;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->auth->user();
|
try {
|
||||||
|
$user = $this->auth->user();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
if ($e instanceof TokenExpiredException) {
|
||||||
|
throw new FailedException('token 过期', Code::LOGIN_EXPIRED);
|
||||||
|
}
|
||||||
|
if ($e instanceof TokenBlacklistException) {
|
||||||
|
throw new FailedException('token 被加入黑名单', Code::LOGIN_BLACKLIST);
|
||||||
|
}
|
||||||
|
if ($e instanceof TokenInvalidException) {
|
||||||
|
throw new FailedException('token 不合法', Code::LOST_LOGIN);
|
||||||
|
}
|
||||||
|
throw new FailedException('auth failed', Code::LOST_LOGIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ class AuthTokenMiddleware extends Middleware
|
|||||||
throw new FailedException('token 过期', Code::LOGIN_EXPIRED);
|
throw new FailedException('token 过期', Code::LOGIN_EXPIRED);
|
||||||
}
|
}
|
||||||
if ($e instanceof TokenBlacklistException) {
|
if ($e instanceof TokenBlacklistException) {
|
||||||
throw new FailedException('token 被加入黑名单', Code::LOST_LOGIN);
|
throw new FailedException('token 被加入黑名单', Code::LOGIN_BLACKLIST);
|
||||||
}
|
}
|
||||||
if ($e instanceof TokenInvalidException) {
|
if ($e instanceof TokenInvalidException) {
|
||||||
throw new FailedException('token 不合法', Code::LOST_LOGIN);
|
throw new FailedException('token 不合法', Code::LOST_LOGIN);
|
||||||
|
@ -10,4 +10,5 @@ class Code
|
|||||||
public const LOGIN_FAILED = 10004; // 登录失败
|
public const LOGIN_FAILED = 10004; // 登录失败
|
||||||
public const FAILED = 10005; // 操作失败
|
public const FAILED = 10005; // 操作失败
|
||||||
public const LOGIN_EXPIRED = 10006; // 登录失效
|
public const LOGIN_EXPIRED = 10006; // 登录失效
|
||||||
|
public const LOGIN_BLACKLIST = 10007; // 黑名单
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user