first commit
This commit is contained in:
33
backend/app/Console/Kernel.php
Normal file
33
backend/app/Console/Kernel.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Models\Auth\Users;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
50
backend/app/Exceptions/Handler.php
Normal file
50
backend/app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of exception types with their corresponding custom log levels.
|
||||
*
|
||||
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
|
||||
*/
|
||||
protected $levels = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the exception types that are not reported.
|
||||
*
|
||||
* @var array<int, class-string<\Throwable>>
|
||||
*/
|
||||
protected $dontReport = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed to the session on validation exceptions.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
24
backend/app/Http/Controllers/Auth/Department.php
Normal file
24
backend/app/Http/Controllers/Auth/Department.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Services\Auth\UsersService;
|
||||
use App\Http\Controllers\Base;
|
||||
|
||||
class Department extends Base{
|
||||
|
||||
/**
|
||||
* @title 部门数据
|
||||
*/
|
||||
public function index(){
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
79
backend/app/Http/Controllers/Auth/Index.php
Normal file
79
backend/app/Http/Controllers/Auth/Index.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Http\Controllers\Base;
|
||||
use App\Services\Auth\AuthService;
|
||||
|
||||
class Index extends Base{
|
||||
/**
|
||||
* Create a new AuthController instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(){
|
||||
$this->middleware('auth:api', ['except' => ['login']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a JWT via given credentials.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function login(AuthService $auth){
|
||||
try {
|
||||
$this->data['data'] = $auth->login();
|
||||
$this->data['code'] = 1;
|
||||
} catch (\Throwable $th) {
|
||||
$this->data['message'] = $th->getMessage();
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authenticated User.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function me(){
|
||||
$this->data['data'] = auth()->user()->load(['roles', 'department']);
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the user out (Invalidate the token).
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function logout(){
|
||||
auth()->logout();
|
||||
|
||||
return response()->json(['message' => 'Successfully logged out']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh a token.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function refresh(){
|
||||
return $this->respondWithToken(auth()->refresh());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the token array structure.
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
protected function respondWithToken($token){
|
||||
return response()->json([
|
||||
'access_token' => $token,
|
||||
'token_type' => 'bearer',
|
||||
'expires_in' => auth()->factory()->getTTL() * 60
|
||||
]);
|
||||
}
|
||||
}
|
||||
63
backend/app/Http/Controllers/Auth/Permission.php
Normal file
63
backend/app/Http/Controllers/Auth/Permission.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Base;
|
||||
use App\Services\Auth\AuthService;
|
||||
|
||||
class Permission extends Base{
|
||||
|
||||
/**
|
||||
* @title 菜单列表
|
||||
*
|
||||
* @param AuthService $service
|
||||
* @return void
|
||||
*/
|
||||
public function index(AuthService $service){
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = $service->getAuthMenu();
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 我的菜单及权限
|
||||
*
|
||||
* @param AuthService $service
|
||||
* @return void
|
||||
*/
|
||||
public function my(AuthService $service){
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = ['menu' => $service->getAuthMenu(), 'permissions' => $service->getAuthPermissions()];
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加菜单
|
||||
*
|
||||
* @param AuthService $service
|
||||
* @return void
|
||||
*/
|
||||
public function add(AuthService $service){
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = $service->getAuthMenu();
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 更新菜单
|
||||
*
|
||||
* @param AuthService $service
|
||||
* @return void
|
||||
*/
|
||||
public function edit(AuthService $service){
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = $service->getAuthMenu();
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
121
backend/app/Http/Controllers/Auth/User.php
Normal file
121
backend/app/Http/Controllers/Auth/User.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Services\Auth\UsersService;
|
||||
use App\Http\Controllers\Base;
|
||||
|
||||
class User extends Base{
|
||||
/**
|
||||
* @title 用户列表
|
||||
* @param int $uid
|
||||
* @return array
|
||||
*/
|
||||
public function index(UsersService $user){
|
||||
$list = $user->getUserList();
|
||||
$this->data['data'] = $list;
|
||||
return $this->data;
|
||||
}
|
||||
/**
|
||||
* @title 添加用户
|
||||
* @param int $uid
|
||||
* @return array
|
||||
*/
|
||||
public function add(){
|
||||
try {
|
||||
$res = app()->make(UsersService::class)->createUsers($this->request);
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = $res;
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
/**
|
||||
* @title 修改用户信息
|
||||
* @param int $uid
|
||||
* @return array
|
||||
*/
|
||||
public function edit(){
|
||||
try {
|
||||
$res = app()->make(UsersService::class)->updateUsers($this->request);
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = $res;
|
||||
$this->data['message'] = "更新成功!";
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改密码
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function passwd(){
|
||||
try {
|
||||
$res = app()->make(UsersService::class)->updateUserPassword($this->request);
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = $res;
|
||||
$this->data['message'] = "修改成功";
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
/**
|
||||
* @title 批量导入用户
|
||||
* @param int $uid
|
||||
* @return array
|
||||
*/
|
||||
public function insert(){
|
||||
try {
|
||||
$users = app()->make(UsersService::class)->insertAll($this->request);
|
||||
$this->data['data'] = $users;
|
||||
$this->data['code'] = 1;
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 用户信息
|
||||
* @param int $uid
|
||||
* @return array
|
||||
*/
|
||||
public function info(){
|
||||
$this->data['data'] = auth()->user()->load(['department', 'roles']);
|
||||
$this->data['code'] = 1;
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 用户授权
|
||||
* @return array
|
||||
*/
|
||||
public function auth(){
|
||||
try {
|
||||
$uid = $this->request->param('uid');
|
||||
$role = $this->request->param('role');
|
||||
app()->make(UsersService::class)->updateRoles($uid, $role);
|
||||
$this->data['message'] = '更新成功!';
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
9
backend/app/Http/Controllers/Base.php
Normal file
9
backend/app/Http/Controllers/Base.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class Base extends Controller{
|
||||
|
||||
public $data = ['code' => 0, 'data' => '', 'message' => ''];
|
||||
}
|
||||
13
backend/app/Http/Controllers/Controller.php
Normal file
13
backend/app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
41
backend/app/Http/Controllers/System/Index.php
Normal file
41
backend/app/Http/Controllers/System/Index.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Http\Controllers\System;
|
||||
|
||||
use App\Http\Controllers\Base;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\Auth\UsersLogService;
|
||||
|
||||
class Index extends Base{
|
||||
|
||||
/**
|
||||
* @title 版权信息
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function version(){
|
||||
$system_info_mysql = DB::select("select version() as version;");
|
||||
$this->data['data'] = [
|
||||
['label' => '内核版本', 'values' => app()->version()],
|
||||
['label' => '系统版本', 'values' => env('SYSTEM_VERSION')],
|
||||
['label' => '服务器操作系统', 'values' => PHP_OS],
|
||||
['label' => '运行环境', 'values' => $_SERVER['SERVER_SOFTWARE']],
|
||||
['label' => 'MYSQL版本', 'values' => $system_info_mysql[0]->version],
|
||||
// ['label' => '上传限制', 'values' => '10']
|
||||
];
|
||||
$this->data['code'] = 1;
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function log(UsersLogService $service){
|
||||
$this->data['data'] = $service->getUserLogList(request());
|
||||
$this->data['code'] = 1;
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
0
backend/app/Http/Controllers/System/Setting.php
Normal file
0
backend/app/Http/Controllers/System/Setting.php
Normal file
68
backend/app/Http/Kernel.php
Normal file
68
backend/app/Http/Kernel.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array<int, class-string|string>
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Illuminate\Http\Middleware\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array<string, array<int, class-string|string>>
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
||||
'throttle:api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array<string, class-string|string>
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'auth:api' => \App\Http\Middleware\AuthMiddleware::class,
|
||||
];
|
||||
}
|
||||
24
backend/app/Http/Middleware/AuthMiddleware.php
Normal file
24
backend/app/Http/Middleware/AuthMiddleware.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Throwable;
|
||||
|
||||
class AuthMiddleware{
|
||||
|
||||
public function handle(Request $request, \Closure $next, ...$guards){
|
||||
try {
|
||||
if (! $user = Auth::guard($guards)->user()) {
|
||||
throw new AuthenticationException();
|
||||
}
|
||||
return $next($request);
|
||||
} catch (Exception|Throwable $e) {
|
||||
return response()->json(['code' => 2000, 'message' => '请重新登录!']);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
backend/app/Http/Middleware/Authenticate.php
Normal file
21
backend/app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (! $request->expectsJson()) {
|
||||
return route('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
17
backend/app/Http/Middleware/EncryptCookies.php
Normal file
17
backend/app/Http/Middleware/EncryptCookies.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
32
backend/app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
32
backend/app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||
* @param string|null ...$guards
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$guards)
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
19
backend/app/Http/Middleware/TrimStrings.php
Normal file
19
backend/app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
20
backend/app/Http/Middleware/TrustHosts.php
Normal file
20
backend/app/Http/Middleware/TrustHosts.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array<int, string|null>
|
||||
*/
|
||||
public function hosts()
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
28
backend/app/Http/Middleware/TrustProxies.php
Normal file
28
backend/app/Http/Middleware/TrustProxies.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array<int, string>|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers =
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
||||
22
backend/app/Http/Middleware/ValidateSignature.php
Normal file
22
backend/app/Http/Middleware/ValidateSignature.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
|
||||
|
||||
class ValidateSignature extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the query string parameters that should be ignored.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
// 'fbclid',
|
||||
// 'utm_campaign',
|
||||
// 'utm_content',
|
||||
// 'utm_medium',
|
||||
// 'utm_source',
|
||||
// 'utm_term',
|
||||
];
|
||||
}
|
||||
17
backend/app/Http/Middleware/VerifyCsrfToken.php
Normal file
17
backend/app/Http/Middleware/VerifyCsrfToken.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
56
backend/app/Listeners/RequestHandledListener.php
Normal file
56
backend/app/Listeners/RequestHandledListener.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Foundation\Http\Events\RequestHandled;
|
||||
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class RequestHandledListener{
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param \App\Events\RequestHandled $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(RequestHandled $event){
|
||||
$response = $event->response;
|
||||
|
||||
if ($response instanceof JsonResponse) {
|
||||
$exception = $response->exception;
|
||||
|
||||
if ($response->getStatusCode() == SymfonyResponse::HTTP_OK && ! $exception) {
|
||||
$response->setData($this->formatData($response->getData()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
* @return array
|
||||
*/
|
||||
protected function formatData(mixed $responseData): array{
|
||||
$result = [];
|
||||
$data = isset($responseData->data) ? $responseData->data : '';
|
||||
|
||||
if (is_object($data) && property_exists($data, 'per_page')
|
||||
&& property_exists($data, 'total')
|
||||
&& property_exists($data, 'current_page')) {
|
||||
$result['data'] = [
|
||||
'data' => $data->data,
|
||||
'total' => $data->total,
|
||||
'limit' => $data->per_page,
|
||||
'page' => $data->current_page,
|
||||
];
|
||||
$result['code'] = isset($responseData->code) ? $responseData->code : 0;
|
||||
}else{
|
||||
$result = [
|
||||
'code' => isset($responseData->code) ? $responseData->code : 0,
|
||||
'message' => isset($responseData->message) ? $responseData->message : '',
|
||||
'data' => isset($responseData->data) ? $responseData->data : '',
|
||||
];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
15
backend/app/Models/Auth/Departments.php
Normal file
15
backend/app/Models/Auth/Departments.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Departments extends Model{
|
||||
}
|
||||
32
backend/app/Models/Auth/Permissions.php
Normal file
32
backend/app/Models/Auth/Permissions.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Permissions extends Model{
|
||||
|
||||
protected $casts = [
|
||||
'hidden' => 'integer',
|
||||
'hiddenBreadcrumb' => 'integer',
|
||||
'affix' => 'integer',
|
||||
'fullpage' => 'integer',
|
||||
];
|
||||
protected $appends = ['meta'];
|
||||
|
||||
protected function meta(): Attribute{
|
||||
return Attribute::make(
|
||||
get: fn ($value, $data) => [
|
||||
'title' => $data['title'],
|
||||
'type' => $data['type'],
|
||||
'icon' => $data['icon'],
|
||||
'color' => $data['color'],
|
||||
'hidden' => $data['hidden'],
|
||||
'hiddenBreadcrumb' => $data['hiddenBreadcrumb'],
|
||||
'affix' => $data['affix'],
|
||||
'fullpage' => $data['fullpage'],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
15
backend/app/Models/Auth/RoleHasPermissions.php
Normal file
15
backend/app/Models/Auth/RoleHasPermissions.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RoleHasPermissions extends Model{
|
||||
}
|
||||
19
backend/app/Models/Auth/Roles.php
Normal file
19
backend/app/Models/Auth/Roles.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Roles extends Model{
|
||||
|
||||
public function permissions(){
|
||||
return $this->belongsToMany(Permissions::class, RoleHasPermissions::class, 'permission_id', 'role_id');
|
||||
}
|
||||
}
|
||||
15
backend/app/Models/Auth/UserHasRoles.php
Normal file
15
backend/app/Models/Auth/UserHasRoles.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserHasRoles extends Model{
|
||||
}
|
||||
57
backend/app/Models/Auth/Users.php
Normal file
57
backend/app/Models/Auth/Users.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class Users extends Authenticatable implements JWTSubject{
|
||||
use Notifiable;
|
||||
|
||||
protected $primaryKey = 'uid';
|
||||
|
||||
// Rest omitted for brevity
|
||||
|
||||
/**
|
||||
* Get the identifier that will be stored in the subject claim of the JWT.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getJWTIdentifier(){
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a key value array, containing any custom claims to be added to the JWT.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJWTCustomClaims(){
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 角色关联
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function roles(){
|
||||
return $this->belongsToMany(Roles::class, UserHasRoles::class, 'role_id', 'uid');
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 部门关联
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function department(){
|
||||
return $this->hasOne(Departments::class, 'id', 'department_id');
|
||||
}
|
||||
}
|
||||
20
backend/app/Models/Auth/UsersLog.php
Normal file
20
backend/app/Models/Auth/UsersLog.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UsersLog extends Model{
|
||||
|
||||
protected $table = 'users_log';
|
||||
|
||||
public function user(){
|
||||
return $this->hasOne(Users::class, 'uid', 'uid');
|
||||
}
|
||||
}
|
||||
28
backend/app/Providers/AppServiceProvider.php
Normal file
28
backend/app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
30
backend/app/Providers/AuthServiceProvider.php
Normal file
30
backend/app/Providers/AuthServiceProvider.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
// use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The model to policy mappings for the application.
|
||||
*
|
||||
* @var array<class-string, class-string>
|
||||
*/
|
||||
protected $policies = [
|
||||
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerPolicies();
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
21
backend/app/Providers/BroadcastServiceProvider.php
Normal file
21
backend/app/Providers/BroadcastServiceProvider.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
require base_path('routes/channels.php');
|
||||
}
|
||||
}
|
||||
47
backend/app/Providers/EventServiceProvider.php
Normal file
47
backend/app/Providers/EventServiceProvider.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Foundation\Http\Events\RequestHandled;
|
||||
use App\Listeners\RequestHandledListener;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event to listener mappings for the application.
|
||||
*
|
||||
* @var array<class-string, array<int, class-string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
RequestHandled::class => [
|
||||
RequestHandledListener::class,
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if events and listeners should be automatically discovered.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldDiscoverEvents()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
52
backend/app/Providers/RouteServiceProvider.php
Normal file
52
backend/app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The path to the "home" route for your application.
|
||||
*
|
||||
* Typically, users are redirected here after authentication.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/home';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, and other route configuration.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->configureRateLimiting();
|
||||
|
||||
$this->routes(function () {
|
||||
Route::middleware('api')
|
||||
->prefix('api')
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the rate limiters for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configureRateLimiting()
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
||||
});
|
||||
}
|
||||
}
|
||||
58
backend/app/Services/Auth/AuthService.php
Normal file
58
backend/app/Services/Auth/AuthService.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Models\Auth\Permissions;
|
||||
|
||||
class AuthService{
|
||||
|
||||
/**
|
||||
* @title 用户登录
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function login(){
|
||||
$credentials = request(['username', 'password']);
|
||||
|
||||
if (! $token = auth()->attempt($credentials)) {
|
||||
abort(0, 'Unauthorized');
|
||||
}
|
||||
$user = auth()->user();
|
||||
$user['token'] = $token;
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取已授权菜单
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getAuthMenu(){
|
||||
$order = "sort asc, id desc";
|
||||
$map = [];
|
||||
if(auth()->user()['uid'] != env('ADMIN_ROOT')){
|
||||
$map[] = ['name', 'IN', auth()->user()['permission']];
|
||||
}
|
||||
$map[] = ['type', '<>', 'button'];
|
||||
$list = Permissions::where($map)->orderBy('sort', 'asc')->orderBy('id', 'desc')->get();
|
||||
return (new \App\Support\Tree())->listToTree($list->toArray(), 'id', 'parent_id', 'children');
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取已授权菜单
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getAuthPermissions(){
|
||||
$map = [];
|
||||
if(auth()->user()['uid'] != env('ADMIN_ROOT')){
|
||||
$map[] = ['name', 'IN', request()->auth()['permission']];
|
||||
}
|
||||
$list = Permissions::where($map)->get();
|
||||
$data = [];
|
||||
foreach($list as $item){
|
||||
$data[] = $item['name'];
|
||||
};
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
139
backend/app/Services/Auth/UsersLogService.php
Normal file
139
backend/app/Services/Auth/UsersLogService.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Models\Auth\Users;
|
||||
use App\Models\Auth\UsersLog;
|
||||
// use xin\helper\Server;
|
||||
// use xin\helper\Time;
|
||||
|
||||
class UsersLogService{
|
||||
|
||||
/**
|
||||
* @title 获取用户操作日志
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getUserLogList($request){
|
||||
$param = $request->all();
|
||||
$map = [];
|
||||
if(isset($param['date_type']) && $param['date_type']){
|
||||
$time = Time::today();
|
||||
if($param['date_type'] == 'seven'){
|
||||
$time = Time::dayToNow(7);
|
||||
}elseif($param['date_type'] == 'yesterday'){
|
||||
$time = Time::yesterday(7);
|
||||
}elseif($param['date_type'] == 'week'){
|
||||
$time = Time::week(7);
|
||||
}
|
||||
$map[] = ['create_time', 'BETWEEN TIME', $time];
|
||||
}
|
||||
if(isset($param['method']) && $param['method']){
|
||||
$map[] = ['method', '=', strtoupper($param['method'])];
|
||||
}
|
||||
if(isset($param['date']) && $param['date'] && count($param['date']) == 2){
|
||||
$map[] = ['create_time', 'BETWEEN TIME', $param['date']];
|
||||
}
|
||||
|
||||
$list = UsersLog::with(['user'])->where($map)->orderBy('create_time', 'desc')->paginate($param['pageSize']);
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取用户操作日志
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getMyLogList($request){
|
||||
$param = $request->param();
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $request->user['uid']];
|
||||
if(isset($param['method']) && $param['method']){
|
||||
$map[] = ['method', '=', strtoupper($param['method'])];
|
||||
}
|
||||
if(isset($param['date_type']) && $param['date_type']){
|
||||
$time = Time::today();
|
||||
if($param['date_type'] == 'seven'){
|
||||
$time = Time::dayToNow(7);
|
||||
}elseif($param['date_type'] == 'yesterday'){
|
||||
$time = Time::yesterday(7);
|
||||
}elseif($param['date_type'] == 'week'){
|
||||
$time = Time::week(7);
|
||||
}
|
||||
$map[] = ['create_time', 'BETWEEN TIME', $time];
|
||||
}
|
||||
if(isset($param['date']) && $param['date'] && count($param['date']) == 2){
|
||||
$map[] = ['create_time', 'BETWEEN TIME', $param['date']];
|
||||
}
|
||||
|
||||
$list = UsersLog::with(['user'])->where($map)->order('create_time desc')->paginate($request->pageConfig);
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 用户操作记录
|
||||
*
|
||||
* @param [type] $request
|
||||
* @param integer $code
|
||||
* @return void
|
||||
*/
|
||||
public function record($request, $code = 200){
|
||||
$param = array_merge($request->get(), $request->post());
|
||||
|
||||
if(!isset($request->user['uid'])){
|
||||
return false;
|
||||
}
|
||||
$param = strlen(json_encode($param)) > 1000 ? 'param to loog' : json_encode($param);
|
||||
$data = [
|
||||
'uid' => isset($request->user['uid']) ? $request->user['uid'] : '',
|
||||
'title' => self::getCurrentTitle($request),
|
||||
'route' => $request->baseUrl(),
|
||||
'params' => $param,
|
||||
'method' => $request->method(),
|
||||
'client_ip' => Server::getRemoteIp(),
|
||||
'browser' => $request->header('user-agent'),
|
||||
'code' => $code
|
||||
];
|
||||
if($data['route'] == '/admin/system/log/index'){
|
||||
return false;
|
||||
}
|
||||
UsersLog::create($data);
|
||||
}
|
||||
|
||||
protected static function getCurrentTitle($request) {
|
||||
$mate = '';
|
||||
$controller = strtr(strtolower($request->controller()), '.', '\\');
|
||||
$action = $request->action();
|
||||
$class = "\\app\\controller\\" . $controller;
|
||||
if (class_exists($class)) {
|
||||
$reflection = new \ReflectionClass($class);
|
||||
$group_doc = self::Parser($reflection->getDocComment());
|
||||
if (isset($group_doc['title'])) {
|
||||
$mate = $group_doc['title'];
|
||||
}
|
||||
$method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC);
|
||||
foreach ($method as $key => $v) {
|
||||
if ($action == $v->name) {
|
||||
$title_doc = self::Parser($v->getDocComment());
|
||||
if (isset($title_doc['title'])) {
|
||||
$mate = isset($title_doc['title']) ? $title_doc['title'] : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $mate;
|
||||
}
|
||||
|
||||
protected static function Parser($text) {
|
||||
$doc = new \doc\Doc();
|
||||
return $doc->parse($text);
|
||||
}
|
||||
}
|
||||
195
backend/app/Services/Auth/UsersService.php
Normal file
195
backend/app/Services/Auth/UsersService.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Models\Auth\Users;
|
||||
use App\Models\Auth\RolesAccess;
|
||||
use think\facade\Config;
|
||||
|
||||
class UsersService{
|
||||
|
||||
/**
|
||||
* @title 获取管理员列表
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getUserList(){
|
||||
$param = request()->input();
|
||||
$map = [];
|
||||
if(isset($param['name']) && $param['name']){
|
||||
$map[] = ["username|nickname", "like", "%{$param['name']}%"];
|
||||
}
|
||||
if(isset($param['department_id']) && $param['department_id']){
|
||||
$map[] = ["department_id", "IN", getDepartmentChild($param['department_id'])];
|
||||
}
|
||||
if(isset($param['role_id']) && $param['role_id']){
|
||||
$exp = is_array($param['role_id']) ? "IN" : "=";
|
||||
$subMap = [['role_id', $exp, $param['role_id']]];
|
||||
$map[] = ['uid', "IN", function($q) use($subMap){
|
||||
$q->name('user_has_roles')->where($subMap)->field('uid');
|
||||
}];
|
||||
}
|
||||
$list = Users::with(['roles', 'department'])->where($map)->orderBy('uid')->paginate()->each(function($item){
|
||||
$roleId = [];
|
||||
$roleName = [];
|
||||
$identify = [];
|
||||
foreach($item->roles as $val){
|
||||
$roleId[] = $val['id'];
|
||||
$roleName[] = $val['title'];
|
||||
$identify[] = $val['identify'];
|
||||
}
|
||||
$item->role_id = $roleId;
|
||||
$item->roleName = $roleName;
|
||||
$item->identify = $identify;
|
||||
});
|
||||
return $list;
|
||||
}
|
||||
/**
|
||||
* 创建用户
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function createUsers($request){
|
||||
$param = $request->param();
|
||||
$data = [
|
||||
'username' => $param['username'],
|
||||
'nickname' => $param['nickname'],
|
||||
'password' => $param['password'],
|
||||
'department_id' => $param['department_id']
|
||||
];
|
||||
|
||||
$user = Users::create($data);
|
||||
return $user;
|
||||
}
|
||||
/**
|
||||
* @title 批量导入
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function insertAll($request){
|
||||
$data = $request->param('data');
|
||||
$users = [];
|
||||
foreach($data as $item){
|
||||
$user = Users::where('uid', $item['XH'])->findOrEmpty();
|
||||
if($user->isEmpty()){
|
||||
$users = [
|
||||
'uid' => $item['XH'],
|
||||
'username' => $item['XH'],
|
||||
'nickname' => $item['XM'],
|
||||
'password' => md5(''),
|
||||
'email' => "e@mail.cn",
|
||||
'avatar' => $this->request->domain() . str_replace("/pic", "/", $item['RXZP']),
|
||||
'creator_id' => 1,
|
||||
'department_id' => 3,
|
||||
'user_type' => $item['PYCC'],
|
||||
'status' => 1,
|
||||
'sex' => $item['XB'],
|
||||
'xueyuan' => $item['XY'],
|
||||
'student_class' => $item['BJMC'],
|
||||
];
|
||||
Users::create($users);
|
||||
}
|
||||
}
|
||||
return $users;
|
||||
}
|
||||
public function updateUsers($request){
|
||||
$param = $request->param();
|
||||
$roles = isset($param['role_id']) ? $param['role_id'] : [];
|
||||
$user = Users::where('uid', '=', $param['uid'])->findOrEmpty();
|
||||
if(!$user->isEmpty()){
|
||||
if(isset($param['nickname']) && $param['nickname']){
|
||||
$data['nickname'] = $param['nickname'];
|
||||
}
|
||||
if(isset($param['email']) && $param['email']){
|
||||
$data['email'] = $param['email'];
|
||||
}
|
||||
if(isset($param['avatar']) && $param['avatar']){
|
||||
$data['avatar'] = $param['avatar'];
|
||||
}
|
||||
if(isset($param['department_id']) && $param['department_id']){
|
||||
$data['department_id'] = is_array($param['department_id']) ? end($param['department_id']) : $param['department_id'];
|
||||
}
|
||||
$user->save($data);
|
||||
}
|
||||
if(!empty($roles)){
|
||||
$this->updateRoles($param['uid'], $roles); //更新角色
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function updateUserPassword($request){
|
||||
$user = Users::where('uid', '=', $request->user['uid'])->findOrEmpty();
|
||||
$params = $request->param();
|
||||
if(!$user->isEmpty()){
|
||||
if(password_verify($params['oldpassword'], $user->password)){
|
||||
$user->save(['password' => $params['password']]);
|
||||
}else{
|
||||
throw new \think\Exception("当前密码错误!", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取用户权限信息
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getUserAuth($uid){
|
||||
$user = Users::with(['roles', 'roles.permissions', 'department'])->where('uid', '=', $uid)->findOrEmpty();
|
||||
if(!$user->isEmpty()){
|
||||
$permission = [];
|
||||
$apiList = [];
|
||||
$data_range = [];
|
||||
$mobile_module = [];
|
||||
foreach ($user->roles as $role) {
|
||||
$data_range[] = $role['data_range'];
|
||||
$mobile_module = array_merge($mobile_module, $role['mobile_module']);
|
||||
foreach($role->permissions as $item){
|
||||
$permission[] = $item['name'];
|
||||
$apiList = array_merge($apiList, $item['api_list']);
|
||||
}
|
||||
}
|
||||
$user['permission'] = $permission;
|
||||
$user['data_range'] = isset($data_range[0]) ? $data_range[0] : 1; //暂时适配到过角色的数据权限问题 后续调整
|
||||
$user['mobile_module'] = $mobile_module;
|
||||
$user['apiList'] = $apiList;
|
||||
return $user;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function userInfo($uid){
|
||||
$user = $this->getUserAuth($uid);
|
||||
return $user->append(['access_token']);
|
||||
}
|
||||
/**
|
||||
* @title 更新用户角色
|
||||
*
|
||||
* @param int $uid
|
||||
* @param array $roles
|
||||
* @param int $manage_class 用户班级权限
|
||||
* @return void
|
||||
*/
|
||||
public function updateRoles($uid, $roles, $manage_class = 0){
|
||||
RolesAccess::where('uid', '=', $uid)->delete();
|
||||
$save = [];
|
||||
foreach ($roles as $role) {
|
||||
$save[] = ['role_id' => $role, 'uid' => $uid];
|
||||
}
|
||||
(new RolesAccess())->saveAll($save);
|
||||
if($uid && $manage_class){
|
||||
Users::update(['manage_class' => $manage_class], ['uid' => $uid]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
153
backend/app/Support/Tree.php
Normal file
153
backend/app/Support/Tree.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
class Tree{
|
||||
|
||||
protected $formatTree;
|
||||
|
||||
/**
|
||||
* 把返回的数据集转换成Tree
|
||||
* @param array $list 要转换的数据集
|
||||
* @param string $pid parent标记字段
|
||||
* @param string $level level标记字段
|
||||
* @return array
|
||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||
*/
|
||||
public function listToTree($list, $pk = 'id', $pid = 'pid', $child = '_child', $root = 0) {
|
||||
// 创建Tree
|
||||
$tree = array();
|
||||
if (is_array($list)) {
|
||||
// 创建基于主键的数组引用
|
||||
$refer = array();
|
||||
foreach ($list as $key => $data) {
|
||||
$refer[$data[$pk]] = &$list[$key];
|
||||
}
|
||||
foreach ($list as $key => $data) {
|
||||
// 判断是否存在parent
|
||||
$parentId = $data[$pid];
|
||||
if ($root == $parentId) {
|
||||
$tree[] = &$list[$key];
|
||||
} else {
|
||||
if (isset($refer[$parentId])) {
|
||||
$parent = &$refer[$parentId];
|
||||
$parent['childs'][] = $data['id'];
|
||||
$parent[$child][] = &$list[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得所有的子
|
||||
* @param [type] $id [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function getChilds($data, $id = 0, $pk = 'id', $pid = 'pid') {
|
||||
|
||||
$array = [];
|
||||
foreach ($data as $k => $v) {
|
||||
if ($v[$pid] == $id) {
|
||||
$array[] = $v[$pk];
|
||||
array_merge($array, $this->getChilds($data, $v[$pk]));
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取id的所有父,包含自己
|
||||
* @param [type] $id [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function getParents($data, $id = 0, $pk = 'id', $pid = 'pid') {
|
||||
static $ids = [];
|
||||
foreach ($data as $k => $v) {
|
||||
if ($v[$pk] == $id) {
|
||||
array_unshift($ids, $id);
|
||||
if ($v['pid'] == 0) {
|
||||
break;
|
||||
}
|
||||
$this->getParents($data, $v[$pid]);
|
||||
}
|
||||
}
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将树子节点加层级成列表
|
||||
* @param [type] $tree [description]
|
||||
* @param integer $level [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
protected function _toFormatTree($tree, $level = 1) {
|
||||
foreach ($tree as $key => $value) {
|
||||
$temp = $value;
|
||||
if (isset($temp['_child'])) {
|
||||
$temp['_child'] = true;
|
||||
$temp['level'] = $level;
|
||||
} else {
|
||||
$temp['_child'] = false;
|
||||
$temp['level'] = $level;
|
||||
}
|
||||
array_push($this->formatTree, $temp);
|
||||
if (isset($value['_child'])) {
|
||||
$this->_toFormatTree($value['_child'], ($level + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function catEmptyDeal($cat, $next_parentid, $pid = 'pid', $empty = " ") {
|
||||
$str = "";
|
||||
if ($cat[$pid]) {
|
||||
for ($i = 2; $i < $cat['level']; $i++) {
|
||||
$str .= $empty . "│";
|
||||
}
|
||||
if ($cat[$pid] != $next_parentid && !$cat['_child']) {
|
||||
$str .= $empty . "└─ ";
|
||||
} else {
|
||||
$str .= $empty . "├─ ";
|
||||
}
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化树
|
||||
* @param [type] $list [description]
|
||||
* @param string $title [description]
|
||||
* @param string $pk [description]
|
||||
* @param string $pid [description]
|
||||
* @param integer $root [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function toFormatTree($list, $title = 'title', $pk = 'id', $pid = 'pid', $root = 0) {
|
||||
if (empty($list)) {
|
||||
return false;
|
||||
}
|
||||
$list = $this->listToTree($list, $pk, $pid, '_child', $root);
|
||||
$this->formatTree = array();
|
||||
$this->_toFormatTree($list);
|
||||
$data = array();
|
||||
foreach ($this->formatTree as $key => $value) {
|
||||
$index = ($key + 1);
|
||||
$next_parentid = isset($this->formatTree[$index][$pid]) ? $this->formatTree[$index][$pid] : '';
|
||||
$value['level_show'] = $this->catEmptyDeal($value, $next_parentid);
|
||||
$value['title_show'] = $value['level_show'] . $value[$title];
|
||||
$data[] = $value;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user