Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
chinagxwei committed Mar 1, 2024
1 parent ab1f089 commit ebf03d3
Show file tree
Hide file tree
Showing 145 changed files with 4,481 additions and 401 deletions.
35 changes: 25 additions & 10 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace App\Http\Controllers;

use App\Models\Member\Member;
use App\Models\System\SystemAdmin;
use App\Models\System\SystemNavigation;
use App\Models\System\SystemRouter;
use App\Models\User;

use App\Services\User\LoginService;
Expand Down Expand Up @@ -174,11 +177,13 @@ public function info()
{
/** @var User $user */
$user = auth('api')->user();
if ($admin = $user->admin) {
$admin->role->navigations;
return self::successJsonResponse($admin);
}

if ($user && ($user->isSuperManager() || $user->isManager() || $user->isEnterpriseManager())) {
$navigation_str = Cache::get(SystemNavigation::USER_NAVIGATION_KEY . "_{$user->id}");
$info = $user->admin->toArray();
$info['navigations'] = json_decode($navigation_str) ?? [];
return self::successJsonResponse($info);
}
return self::failJsonResponse('Not Found');
}

Expand Down Expand Up @@ -224,17 +229,27 @@ protected function respondWithToken($token)
'expires_in' => time() + auth('api')->factory()->getTTL() * 60
];

// /** @var Admin $admin */
// if ($admin = $user->admin) {
// $admin->role->navigations;
// $result_array['userinfo'] = $admin;
// $result_array['im_token'] = ImService::setAdminSession($user->id);
// }
/** @var SystemAdmin $admin */
if ($admin = $user->admin) {
if ($user->isSuperManager()) {
$navigations = SystemNavigation::getParentAll([SystemNavigation::DEFAULT_WITH_CHILDREN_FIELD]);
} else {
$navigations = $admin->role->navigations;
}
Cache::put(SystemNavigation::USER_NAVIGATION_KEY . "_{$user->id}", json_encode($navigations->toArray()));
}
//
// /** @var Member $member */
// if ($member = $user->member) {
// $result_array['im_token'] = ImService::setMemberSession($member->id, $user->id);
// }
if (!$user->isSuperManager()) {
$routers = $admin->role->routers;
$routers_array = $routers->map(function ($v) {
return $v->router;
});
Cache::put(SystemRouter::USER_ROUTER_KEY . "_{$user->id}", json_encode($routers_array));
}

return self::successJsonResponse($result_array);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function index(Request $request){
* @return \Illuminate\Http\JsonResponse
*/
public function view(Request $request){
if ($request->isMethod('POST') && $id = $request->input('id')) {
if ($id = $request->input('id')) {
if ($model = SystemAdminMessage::findOneByID($id)) {
return self::successJsonResponse($model);
}
Expand Down
85 changes: 0 additions & 85 deletions app/Http/Controllers/Backend/System/SystemAdminRoleController.php

This file was deleted.

16 changes: 8 additions & 8 deletions app/Http/Controllers/Backend/System/SystemMessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Http\Controllers\Backend\System;

use App\Http\Controllers\PlatformController;
use App\Models\System\SystemAdminMessage;
use App\Models\System\SystemMessage;
use Illuminate\Http\Request;

class SystemMessageController extends PlatformController
Expand All @@ -15,7 +15,7 @@ class SystemMessageController extends PlatformController
* @return \Illuminate\Http\JsonResponse
*/
public function index(Request $request){
$res = (new SystemAdminMessage())->searchBuild($request->all())->paginate();
$res = (new SystemMessage())->searchBuild($request->all())->paginate();
return self::successJsonResponse($res);
}

Expand All @@ -24,8 +24,8 @@ public function index(Request $request){
* @return \Illuminate\Http\JsonResponse
*/
public function view(Request $request){
if ($request->isMethod('POST') && $id = $request->input('id')) {
if ($model = SystemAdminMessage::findOneByID($id)) {
if ($id = $request->input('id')) {
if ($model = SystemMessage::findOneByID($id)) {
return self::successJsonResponse($model);
}
}
Expand All @@ -48,9 +48,9 @@ public function save(Request $request){
]);

if ($id > 0) {
$model = SystemAdminMessage::findOneByID($id);
$model = SystemMessage::findOneByID($id);
} else {
$model = new SystemAdminMessage();
$model = new SystemMessage();
}

if ($model->fill($request->all())->save()) {
Expand All @@ -70,7 +70,7 @@ public function save(Request $request){
*/
public function delete(Request $request){
if ($id = $request->input('id')) {
if ($model = SystemAdminMessage::findOneByID($id)) {
if ($model = SystemMessage::findOneByID($id)) {
$this->deleteEvent($model->title);
$model->delete();
return self::successJsonResponse();
Expand All @@ -86,7 +86,7 @@ public function delete(Request $request){
*/
public function send(Request $request){
if ($id = $request->input('id')) {
SystemMessageService::send($id);
// SystemMessageService::send($id);
return self::successJsonResponse();
}

Expand Down
26 changes: 25 additions & 1 deletion app/Http/Controllers/Backend/System/SystemRouterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Controllers\PlatformController;
use App\Models\System\SystemRouter;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

class SystemRouterController extends PlatformController
{
Expand All @@ -27,7 +28,7 @@ public function index(Request $request)
public function save(Request $request)
{
if ($request->isMethod('POST')) {
$id = $request->input('id',0);
$id = $request->input('id', 0);
try {
$this->validate($request, [
'router_name' => 'required|min:3',
Expand Down Expand Up @@ -69,4 +70,27 @@ public function delete(Request $request)
return self::failJsonResponse();
}

/**
* @return \Illuminate\Http\JsonResponse
*/
public function registeredRoute()
{

$user = auth('api')->user();

if ($user && $user->isSuperManager()) {

$routes = Route::getRoutes();

foreach ($routes as $k => $value) {
$route_path[$k]['uri'] = $value->uri;
$methods = join('|', $value->methods);
$route_path[$k]['method'] = ($methods == 'GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS' ? 'ANY' : $methods);
}

return self::successJsonResponse($route_path);
}

return self::failJsonResponse('权限不足');
}
}
18 changes: 9 additions & 9 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class Kernel extends HttpKernel
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'admin' => [
'throttle:api',
'auth.admin'
],
'client' => [
'throttle:api',
'auth'
],
// 'admin' => [
// 'throttle:api',
// 'auth.admin'
// ],
// 'client' => [
// 'throttle:api',
// 'auth'
// ],
];

/**
Expand All @@ -62,7 +62,7 @@ class Kernel extends HttpKernel
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.admin' => \App\Http\Middleware\AdminAuthenticate::class,
// 'auth.admin' => \App\Http\Middleware\AdminAuthenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
Expand Down
39 changes: 29 additions & 10 deletions app/Http/Middleware/AdminAuthenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Middleware;

use App\Models\User;
use App\Services\System\RouterCheckService;
use Closure;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\JsonResponse;
Expand All @@ -25,23 +26,41 @@ public function handle($request, Closure $next, ...$guards)
return response()->json(['code' => 401, 'message' => '请先登录']);
}

$path = "/" . $request->path();

Log::info($path);

/** @var User $user */
if ($user = auth('api')->user()){
if ($user = auth('api')->user()) {
// 检测是否是管理员
if (!$user->isManager()&& !$user->isSuperManager()){
if ($user->isMember()) {
return response()->json(['code' => 403, 'message' => '没有访问内容的权限']);
}
}

$route = Route::current();

$action = $route->getActionMethod();

$path = $route->getPrefix() . "/{$action}";
if ($user->isSuperManager()) {
return $next($request);
}
}

Log::info($path);

Log::info(explode('/', $path));
// $route = Route::current();
//
// $action = $route->getActionMethod();
//
// $path = "/" . $route->getPrefix() . "/{$action}";
//
// Log::info($path);
//
// Log::info(explode('/', $path));
//
// /** @var RouterCheckService $service */
// $service = app(RouterCheckService::class);
//
// $res = $service->setAllowedRoutes([
// '/api/v1/auth/info2',
// ])->can($path);
//
// Log::info("type:" . ($res ? '1' : '0'));

return $next($request);
}
Expand Down
Loading

0 comments on commit ebf03d3

Please sign in to comment.