修改用户信息
This commit is contained in:
parent
b41121e35b
commit
cf4ef949b5
@ -4,6 +4,7 @@ namespace catchAdmin\index\controller;
|
|||||||
use catchAdmin\permissions\model\Permissions;
|
use catchAdmin\permissions\model\Permissions;
|
||||||
use catchAdmin\user\Auth;
|
use catchAdmin\user\Auth;
|
||||||
use catcher\base\CatchController;
|
use catcher\base\CatchController;
|
||||||
|
use catcher\CatchAuth;
|
||||||
use catcher\Tree;
|
use catcher\Tree;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
@ -19,7 +20,9 @@ class Index extends CatchController
|
|||||||
*/
|
*/
|
||||||
public function index(): string
|
public function index(): string
|
||||||
{
|
{
|
||||||
$permissionIds = Auth::user()->getPermissionsBy();
|
$user = (new CatchAuth())->user();
|
||||||
|
|
||||||
|
$permissionIds = $user->getPermissionsBy();
|
||||||
|
|
||||||
$menus = Permissions::whereIn('id', $permissionIds)
|
$menus = Permissions::whereIn('id', $permissionIds)
|
||||||
->where('type', Permissions::MENU_TYPE)
|
->where('type', Permissions::MENU_TYPE)
|
||||||
@ -28,7 +31,7 @@ class Index extends CatchController
|
|||||||
|
|
||||||
return $this->fetch([
|
return $this->fetch([
|
||||||
'menus' => Tree::done($menus),
|
'menus' => Tree::done($menus),
|
||||||
'username' => Auth::user()->username,
|
'username' => $user->username,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,4 +59,4 @@ class Index extends CatchController
|
|||||||
'mysql_version' => $mysqlVersion['0']['version'],
|
'mysql_version' => $mysqlVersion['0']['version'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class Index extends CatchController
|
|||||||
public function login(LoginRequest $request, CatchAuth $auth)
|
public function login(LoginRequest $request, CatchAuth $auth)
|
||||||
{
|
{
|
||||||
$params = $request->param();
|
$params = $request->param();
|
||||||
|
|
||||||
$token = $auth->attempt($params);
|
$token = $auth->attempt($params);
|
||||||
|
|
||||||
$user = $auth->user();
|
$user = $auth->user();
|
||||||
|
@ -1,34 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace catchAdmin\user;
|
namespace catchAdmin\user;
|
||||||
|
|
||||||
use catcher\Code;
|
use catcher\Code;
|
||||||
use catcher\exceptions\FailedException;
|
use catcher\exceptions\FailedException;
|
||||||
use thans\jwt\exception\TokenBlacklistException;
|
use thans\jwt\exception\TokenBlacklistException;
|
||||||
use thans\jwt\exception\TokenExpiredException;
|
use thans\jwt\exception\TokenExpiredException;
|
||||||
use thans\jwt\exception\TokenInvalidException;
|
use thans\jwt\exception\TokenInvalidException;
|
||||||
use thans\jwt\facade\JWTAuth;
|
use thans\jwt\facade\JWTAuth;
|
||||||
use think\Middleware;
|
use think\Middleware;
|
||||||
|
|
||||||
class AuthTokenMiddleware extends Middleware
|
class AuthTokenMiddleware extends Middleware
|
||||||
{
|
{
|
||||||
public function handle($request, \Closure $next)
|
public function handle($request, \Closure $next)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
JWTAuth::auth();
|
JWTAuth::auth();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
if ($e instanceof TokenExpiredException) {
|
if ($e instanceof TokenExpiredException) {
|
||||||
throw new FailedException('token 过期', Code::LOST_LOGIN);
|
throw new FailedException('token 过期', Code::LOST_LOGIN);
|
||||||
}
|
}
|
||||||
if ($e instanceof TokenBlacklistException) {
|
if ($e instanceof TokenBlacklistException) {
|
||||||
throw new FailedException('token 被加入黑名单', Code::LOST_LOGIN);
|
throw new FailedException('token 被加入黑名单', Code::LOST_LOGIN);
|
||||||
}
|
}
|
||||||
if ($e instanceof TokenInvalidException) {
|
if ($e instanceof TokenInvalidException) {
|
||||||
throw new FailedException('token 不合法', Code::LOST_LOGIN);
|
throw new FailedException('token 不合法', Code::LOST_LOGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new FailedException('登录用户不合法', Code::LOST_LOGIN);
|
throw new FailedException('登录用户不合法', Code::LOST_LOGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ class User extends CatchController
|
|||||||
*/
|
*/
|
||||||
public function info(CatchAuth $auth)
|
public function info(CatchAuth $auth)
|
||||||
{
|
{
|
||||||
|
|
||||||
$user = $auth->user();
|
$user = $auth->user();
|
||||||
|
|
||||||
$roles = $user->getRoles();
|
$roles = $user->getRoles();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user