diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 23d4001..ef9cc3a 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -7,7 +7,13 @@ namespace App\Exceptions; +use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Illuminate\Http\JsonResponse; +use Illuminate\Http\RedirectResponse; +use Illuminate\Http\Request; +use Illuminate\Http\Response; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Throwable; class Handler extends ExceptionHandler @@ -37,10 +43,26 @@ class Handler extends ExceptionHandler * * @return void */ - public function register() + public function register(): void { $this->reportable(function (Throwable $e) { // }); } + + /** + * 处理发现页面找不到之后返回内容 + * + * @param Request $request 获取请求内容 + * @param Throwable $e 抛出错误 + * @return Response|JsonResponse|\Symfony\Component\HttpFoundation\Response|RedirectResponse + * @throws Throwable + */ + public function render($request, Throwable $e): Response|JsonResponse|\Symfony\Component\HttpFoundation\Response|RedirectResponse + { + if ($e instanceof ModelNotFoundException || $e instanceof NotFoundHttpException) { + return response()->redirectToRoute('404'); + } + return parent::render($request, $e); + } } diff --git a/app/Http/Controllers/Console/Link.php b/app/Http/Controllers/Console/Link.php index c3f8fc2..9c89b3f 100644 --- a/app/Http/Controllers/Console/Link.php +++ b/app/Http/Controllers/Console/Link.php @@ -12,10 +12,15 @@ use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\View; +use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Mail\Message; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Response; +use Illuminate\Support\Facades\Validator; class Link extends Controller { @@ -27,9 +32,476 @@ public function __construct() $this->data = $data->data; } - public function ViewEdit(Request $request, $userId): Application|Factory|View|RedirectResponse + public function apiConsoleAdd(Request $request): JsonResponse + { + // 检查数据 + if (Auth::check()) { + if (Auth::user()->admin) { + // 处理获取数据 + $dataCheck = Validator::make($request->all(), [ + 'userEmail' => 'email', + 'userServerHost' => 'required|string', + 'userBlog' => 'required|string', + 'userUrl' => 'required|regex:#[a-zA-z]+://[^\s]*#', + 'userDescription' => 'required|string', + 'userIcon' => 'required|regex:#[a-zA-z]+://[^\s]*#', + 'checkRssJudge' => 'boolean', + 'userRss' => 'string|regex:#[a-zA-z]+://[^\s]*#', + 'userSelColor' => 'required|int', + 'userLocation' => 'required|string', + ]); + if ($dataCheck->fails()) { + $errorType = array_keys($dataCheck->failed()); + $i = 0; + foreach ($dataCheck->failed() as $valueData) { + $errorInfo[$errorType[$i]] = array_keys($valueData); + if ($i == 0) { + $errorSingle = [ + 'info' => $errorType[$i], + 'need' => $errorInfo[$errorType[$i]], + ]; + } + $i++; + } + $returnData = [ + 'output' => 'DataFormatError', + 'code' => 403, + 'data' => [ + 'message' => '输入内容有错误', + 'errorSingle' => $errorSingle, + 'error' => $errorInfo, + ], + ]; + } else { + if (empty($request->userEmail)) $request->userEmail = null; + if (empty($request->checkRssJudge)) $request->checkRssJudge = 0; + if (empty($request->userRss)) $request->userRss = null; + // 更新数据库 + DB::table('blog_link') + ->insert([ + 'blogOwnEmail' => $request->userEmail, + 'blogServerHost' => $request->userServerHost, + 'blogName' => $request->userBlog, + 'blogUrl' => $request->userUrl, + 'blogDescription' => $request->userDescription, + 'blogIcon' => $request->userIcon, + 'blogRssJudge' => $request->checkRssJudge, + 'blogRSS' => $request->userRss, + 'blogSetColor' => $request->userSelColor, + 'blogLocation' => $request->userLocation, + 'created_at' => date('Y-m-d H:i:s'), + ]); + $returnData = [ + 'output' => 'Success', + 'code' => 200, + 'data' => [ + 'message' => '数据插入成功', + ], + ]; + } + } else { + $returnData = [ + 'output' => 'NoPermission', + 'code' => 403, + 'data' => [ + 'message' => '没有权限', + ], + ]; + } + } else { + $returnData = [ + 'output' => 'PleaseLogin', + 'code' => 403, + 'data' => [ + 'message' => '请登录', + ], + ]; + } + return Response::json($returnData, $returnData['code']); + } + + public function apiConsoleEdit(Request $request): JsonResponse + { + // 检查用户是否登录 + if (Auth::check()) { + if (Auth::user()->admin) { + // 处理获取数据 + $dataCheck = Validator::make($request->all(), [ + 'userId' => 'required|int', + 'userEmail' => 'email', + 'userServerHost' => 'required|string', + 'userBlog' => 'required|string', + 'userUrl' => 'required|regex:#[a-zA-z]+://[^\s]*#', + 'userDescription' => 'required|string', + 'userIcon' => 'required|regex:#[a-zA-z]+://[^\s]*#', + 'checkRssJudge' => 'boolean', + 'userRss' => 'string|regex:#[a-zA-z]+://[^\s]*#', + 'userSelColor' => 'required|int', + 'userLocation' => 'required|string', + ]); + if ($dataCheck->fails()) { + $errorType = array_keys($dataCheck->failed()); + $i = 0; + foreach ($dataCheck->failed() as $valueData) { + $errorInfo[$errorType[$i]] = array_keys($valueData); + if ($i == 0) { + $errorSingle = [ + 'info' => $errorType[$i], + 'need' => $errorInfo[$errorType[$i]], + ]; + } + $i++; + } + $returnData = [ + 'output' => 'DataFormatError', + 'code' => 403, + 'data' => [ + 'message' => '输入内容有错误', + 'errorSingle' => $errorSingle, + 'error' => $errorInfo, + ], + ]; + } else { + if (empty($request->userEmail)) $request->userEmail = null; + if (empty($request->checkRssJudge)) $request->checkRssJudge = 0; + if (empty($request->userRss)) $request->userRss = null; + // 更新数据库 + DB::table('blog_link') + ->where([['id', '=', $request->userId]]) + ->update([ + 'blogOwnEmail' => $request->userEmail, + 'blogServerHost' => $request->userServerHost, + 'blogName' => $request->userBlog, + 'blogUrl' => $request->userUrl, + 'blogDescription' => $request->userDescription, + 'blogIcon' => $request->userIcon, + 'blogRssJudge' => $request->checkRssJudge, + 'blogRSS' => $request->userRss, + 'blogSetColor' => $request->userSelColor, + 'blogLocation' => $request->userLocation, + 'updated_at' => date('Y-m-d H:i:s') + ]); + $returnData = [ + 'output' => 'Success', + 'code' => 200, + 'data' => [ + 'message' => '数据成功更新', + ], + ]; + } + } else { + $returnData = [ + 'output' => 'NoPermission', + 'code' => 403, + 'data' => [ + 'message' => '没有权限', + ], + ]; + } + } else { + $returnData = [ + 'output' => 'PleaseLogin', + 'code' => 403, + 'data' => [ + 'message' => '请登录', + ], + ]; + } + return Response::json($returnData, $returnData['code']); + } + + public function apiConsoleCheck(Request $request): JsonResponse + { + // 检查用户是否登录 + if (Auth::check()) { + if (Auth::user()->admin) { + // 处理获取数据 + $dataCheck = Validator::make($request->all(), [ + 'userId' => 'required|int', + 'userEmail' => 'required|email', + 'userServerHost' => 'required|string', + 'userBlog' => 'required|string', + 'userUrl' => 'required|regex:#[a-zA-z]+://[^\s]*#', + 'userDescription' => 'required|string', + 'userIcon' => 'required|regex:#[a-zA-z]+://[^\s]*#', + 'checkRssJudge' => 'boolean', + 'userRss' => 'string|regex:#[a-zA-z]+://[^\s]*#', + 'userSelColor' => 'required|int', + 'userLocation' => 'required|string', + ]); + if ($dataCheck->fails()) { + $errorType = array_keys($dataCheck->failed()); + $i = 0; + foreach ($dataCheck->failed() as $valueData) { + $errorInfo[$errorType[$i]] = array_keys($valueData); + if ($i == 0) { + $errorSingle = [ + 'info' => $errorType[$i], + 'need' => $errorInfo[$errorType[$i]], + ]; + } + $i++; + } + $returnData = [ + 'output' => 'DataFormatError', + 'code' => 403, + 'data' => [ + 'message' => '输入内容有错误', + 'errorSingle' => $errorSingle, + 'error' => $errorInfo, + ], + ]; + } else { + // 更新数据库 + DB::table('blog_link') + ->where([['id', '=', $request->userId]]) + ->update([ + 'blogOwnEmail' => $request->userEmail, + 'blogServerHost' => $request->userServerHost, + 'blogName' => $request->userBlog, + 'blogUrl' => $request->userUrl, + 'blogDescription' => $request->userDescription, + 'blogIcon' => $request->userIcon, + 'blogRssJudge' => $request->checkRssJudge, + 'blogRSS' => $request->userRss, + 'blogSetColor' => $request->userSelColor, + 'blogLocation' => $request->userLocation, + 'updated_at' => date('Y-m-d H:i:s') + ]); + Mail::send('mail.link-console-verify', $request->all(), function (Message $mail) { + global $request; + $mail->from(env('MAIL_USERNAME'), env('APP_NAME')); + $mail->to($request->userEmail); + $mail->subject(env('APP_NAME') . '-友链审核通过通知'); + }); + $returnData = [ + 'output' => 'Success', + 'code' => 200, + 'data' => [ + 'message' => '数据成功更新', + ], + ]; + } + } else { + $returnData = [ + 'output' => 'NoPermission', + 'code' => 403, + 'data' => [ + 'message' => '没有权限', + ], + ]; + } + } else { + $returnData = [ + 'output' => 'PleaseLogin', + 'code' => 403, + 'data' => [ + 'message' => '请登录', + ], + ]; + } + return Response::json($returnData, $returnData['code']); + } + + public function apiConsoleCheckFail(Request $request): JsonResponse + { + // 检查用户是否登录 + if (Auth::check()) { + if (Auth::user()->admin) { + // 处理获取数据 + $dataCheck = Validator::make($request->all(), [ + 'userId' => 'required|int', + 'sendMail' => 'int', + 'sendReason' => 'string', + ]); + if ($dataCheck->fails()) { + $errorType = array_keys($dataCheck->failed()); + $i = 0; + foreach ($dataCheck->failed() as $valueData) { + $errorInfo[$errorType[$i]] = array_keys($valueData); + if ($i == 0) { + $errorSingle = [ + 'info' => $errorType[$i], + 'need' => $errorInfo[$errorType[$i]], + ]; + } + $i++; + } + $returnData = [ + 'output' => 'DataFormatError', + 'code' => 403, + 'data' => [ + 'message' => '输入内容有错误', + 'errorSingle' => $errorSingle, + 'error' => $errorInfo, + ], + ]; + } else { + // 获取数据 + $this->data['blog'] = DB::table('blog_link') + ->where([['id', '=', $request->userId]]) + ->get() + ->toArray(); + $this->data['reason'] = $request->sendReason; + if (!empty($this->data['blog'][0]->id)) { + // 更新数据库 + DB::table('blog_link') + ->where([['id', '=', $this->data['blog'][0]->id]]) + ->delete(); + if (!empty($request->sendMail) && !empty($this->data['blog'][0]->blogOwnEmail)) { + Mail::send('mail.link-console-refuse-verify', $this->data, function (Message $mail) { + global $request; + $mail->from(env('MAIL_USERNAME'), env('APP_NAME')); + $mail->to($this->data['blog'][0]->blogOwnEmail); + $mail->subject(env('APP_NAME') . '-友链审核未通过通知'); + }); + } + $returnData = [ + 'output' => 'Success', + 'code' => 200, + 'data' => [ + 'message' => '删除成功', + ], + ]; + } else { + $returnData = [ + 'output' => 'NoBlog', + 'code' => 403, + 'data' => [ + 'message' => '没有对应博客序列', + ], + ]; + } + } + } else { + $returnData = [ + 'output' => 'NoPermission', + 'code' => 403, + 'data' => [ + 'message' => '没有权限', + ], + ]; + } + } else { + $returnData = [ + 'output' => 'PleaseLogin', + 'code' => 403, + 'data' => [ + 'message' => '请登录', + ], + ]; + } + return Response::json($returnData, $returnData['code']); + } + + public function apiConsoleDelete(Request $request): JsonResponse + { + // 检查用户是否登录 + if (Auth::check()) { + if (Auth::user()->admin) { + // 处理获取数据 + $dataCheck = Validator::make($request->all(), [ + 'userId' => 'required|int', + 'sendMail' => 'int', + ]); + if ($dataCheck->fails()) { + $errorType = array_keys($dataCheck->failed()); + $i = 0; + foreach ($dataCheck->failed() as $valueData) { + $errorInfo[$errorType[$i]] = array_keys($valueData); + if ($i == 0) { + $errorSingle = [ + 'info' => $errorType[$i], + 'need' => $errorInfo[$errorType[$i]], + ]; + } + $i++; + } + $returnData = [ + 'output' => 'DataFormatError', + 'code' => 403, + 'data' => [ + 'message' => '输入内容有错误', + 'errorSingle' => $errorSingle, + 'error' => $errorInfo, + ], + ]; + } else { + // 获取数据 + $this->data['blog'] = DB::table('blog_link') + ->where([['id', '=', $request->userId]]) + ->get() + ->toArray(); + if (!empty($this->data['blog'][0]->id)) { + // 更新数据库 + DB::table('blog_link') + ->where([['id', '=', $this->data['blog'][0]->id]]) + ->delete(); + if (!empty($request->sendMail) && !empty($this->data['blog'][0]->blogOwnEmail)) { + Mail::send('mail.link-console-delete', $request->all(), function (Message $mail) { + global $request; + $mail->from(env('MAIL_USERNAME'), env('APP_NAME')); + $mail->to($this->data['blog'][0]->blogOwnEmail); + $mail->subject(env('APP_NAME') . '-友链被删除'); + }); + } + $returnData = [ + 'output' => 'Success', + 'code' => 200, + 'data' => [ + 'message' => '删除成功', + ], + ]; + } else { + $returnData = [ + 'output' => 'NoBlog', + 'code' => 403, + 'data' => [ + 'message' => '没有对应博客序列', + ], + ]; + } + } + } else { + $returnData = [ + 'output' => 'NoPermission', + 'code' => 403, + 'data' => [ + 'message' => '没有权限', + ], + ]; + } + } else { + $returnData = [ + 'output' => 'PleaseLogin', + 'code' => 403, + 'data' => [ + 'message' => '请登录', + ], + ]; + } + return Response::json($returnData, $returnData['code']); + } + + protected function viewEdit($userId): Application|Factory|View|RedirectResponse + { + $this->setDataForViewEditAndCheckAdmin($userId); + if ($this->data['blog'][0] != null) { + // 没有查询到执行删除 + $this->data['subDescriptionForLine'] = '友链修改'; + if ($this->data['blog'][0] == null) return Response::redirectTo(route('console.friends-link.list')); + return view('console.friends-link.edit', $this->data); + } else { + return Response::redirectTo(route('console.friends-link.check')); + } + } + + /** + * @param $userId + * @return void + */ + private function setDataForViewEditAndCheckAdmin($userId): void { - // 查找友链 $resultBlog = DB::table('blog_link') ->find($userId); $this->data['blog'] = [ @@ -39,16 +511,35 @@ public function ViewEdit(Request $request, $userId): Application|Factory|View|Re ->orderBy('sort') ->get() ->toArray(); - $this->data['blogColor'] = DB::table('blog_color') + $blogColor = DB::table('blog_color') ->orderBy('id') ->get() ->toArray(); - // 没有查询到执行删除 - if ($this->data['blog'][0] == null) return Response::redirectTo(route('console.friends-link.list')); - return view('console.friends-link.edit', $this->data); + for ($i = 0; !empty($blogColor[$i]->id); $i++) { + $blogColor[$i]->colorDarkType = str_replace('dark:', '', $blogColor[$i]->colorDarkType); + } + $this->data['blogColor'] = $blogColor; } - protected function ViewList(Request $request): Factory|View|Application|RedirectResponse + protected function viewCheckAdmin($userId): View|Factory|Application|RedirectResponse + { + $this->setDataForViewEditAndCheckAdmin($userId); + if ($this->data['blog'][0] != null) { + if ($this->data['blog'][0]->blogLocation == 0) { + // 用户期望位置替换显示 + $this->data['blog'][0]->blogLocation = $this->data['blog'][0]->blogUserLocation;// 没有查询到执行删除 + $this->data['subDescriptionForLine'] = '友链审核'; + if ($this->data['blog'][0] == null) return Response::redirectTo(route('console.friends-link.list')); + return view('console.friends-link.edit', $this->data); + } else { + return Response::redirectTo(route('console.friends-link.check')); + } + } else { + return Response::redirectTo(route('console.friends-link.check')); + } + } + + protected function viewList(Request $request): Factory|View|Application|RedirectResponse { $this->data['request'] = $request; $dataMarge = [ @@ -86,36 +577,62 @@ protected function ViewList(Request $request): Factory|View|Application|Redirect $this->data['blog'] = DB::select("SELECT * FROM xf_index.blog_link WHERE blogName LIKE '%$request->search%' OR blogUrl LIKE '%$request->search%' ORDER BY id"); } $this->data = array_merge($this->data, $dataMarge); + $blogColor = DB::table('blog_color') + ->orderBy('id') + ->get() + ->toArray(); + for ($i = 0; !empty($blogColor[$i]->id); $i++) { + $blogColor[$i]->colorLightType = str_replace('border-', 'ring-', $blogColor[$i]->colorLightType); + $blogColor[$i]->colorDarkType = str_replace('border-', 'ring-', $blogColor[$i]->colorDarkType); + } + $this->data['blogColor'] = $blogColor; return view('console.friends-link.list', $this->data); } - protected function ViewCheck(Request $request): Factory|View|Application + protected function viewCheck(): Factory|View|Application { // 检查是否存在含有未在本站分配位置 $this->data['blog'] = DB::table('blog_link') - ->whereIn('blog_link.blogLocation',[0]) + ->whereIn('blog_link.blogLocation', [0]) + ->orderBy('id', 'desc') ->get() ->toArray(); + $blogColor = DB::table('blog_color') + ->orderBy('id') + ->get() + ->toArray(); + for ($i = 0; !empty($blogColor[$i]->id); $i++) { + $blogColor[$i]->colorLightType = str_replace('border-', 'ring-', $blogColor[$i]->colorLightType); + $blogColor[$i]->colorDarkType = str_replace('border-', 'ring-', $blogColor[$i]->colorDarkType); + } + $this->data['blogColor'] = $blogColor; return view('console.friends-link.check', $this->data); } - protected function ViewAdd(Request $request): Factory|View|Application + protected function viewAdd(): Factory|View|Application { + $this->data['blogSort'] = DB::table('blog_sort') + ->orderBy('sort') + ->get() + ->toArray(); + $blogColor = DB::table('blog_color') + ->orderBy('id') + ->get() + ->toArray(); + for ($i = 0; !empty($blogColor[$i]->id); $i++) { + $blogColor[$i]->colorDarkType = str_replace('dark:', '', $blogColor[$i]->colorDarkType); + } + $this->data['blogColor'] = $blogColor; return view('console.friends-link.add', $this->data); } - protected function ViewSort(): Factory|View|Application + protected function viewSort(): Factory|View|Application { - return view('console.friends-link.sort',$this->data); + return view('console.friends-link.sort', $this->data); } - protected function ViewColor(): Factory|View|Application + protected function viewColor(): Factory|View|Application { - return view('console.friends-link.color',$this->data); - } - - protected function apiConsoleAdd() { - // 检查数据 - + return view('console.friends-link.color', $this->data); } } diff --git a/app/Http/Controllers/DataBase.php b/app/Http/Controllers/DataBase.php index fc73829..bfce5eb 100644 --- a/app/Http/Controllers/DataBase.php +++ b/app/Http/Controllers/DataBase.php @@ -21,6 +21,10 @@ public function __construct() ->toArray(); foreach ($result as $value) { $value->blog_rss_judge ? $value->blog_rss_judge = 1 : $value->blog_rss_judge = 0; + if ($value->blog_sel_color == 8) $value->blog_sel_color = 6; + if ($value->blog_sel_color == 2) $value->blog_sel_color = 8; + if ($value->blog_sel_color == 7) $value->blog_sel_color = 4; + if ($value->blog_sel_color == 5) $value->blog_sel_color = 3; DB::table('blog_link') ->insert([ 'blogName' => $value->blog_name, diff --git a/app/Http/Controllers/Function/Link.php b/app/Http/Controllers/Function/Link.php index 43b2e06..ec89271 100644 --- a/app/Http/Controllers/Function/Link.php +++ b/app/Http/Controllers/Function/Link.php @@ -99,6 +99,8 @@ public function apiCustomAdd(HttpRequest $request): JsonResponse ])->get()->toArray(); if (empty($resultBlog)) { + if (empty($request->checkRssJudge)) $request->checkRssJudge = 0; + if (empty($request->userRss)) $request->userRss = null; // 数据写入数据库 $insertData = DB::table('blog_link') ->insert([ @@ -113,6 +115,7 @@ public function apiCustomAdd(HttpRequest $request): JsonResponse 'blogSetColor' => $request->userSelColor, 'blogRemark' => $request->userRemark, 'blogServerHost' => $request->userServerHost, + 'created_at' => date('Y-m-d H:i:s'), ]); if ($insertData) { // 邮件发送系统 @@ -120,6 +123,12 @@ public function apiCustomAdd(HttpRequest $request): JsonResponse global $request; $mail->from(env('MAIL_USERNAME'), env('APP_NAME')); $mail->to($request->userEmail); + $mail->subject(env('APP_NAME') . '-友链申请成功'); + }); + Mail::send('mail.link-console-add', $request->toArray(), function (Message $mail) { + global $request; + $mail->from(env('MAIL_USERNAME'), env('APP_NAME')); + $mail->to($this->data['sqlEmail']); $mail->subject(env('APP_NAME') . '-友链等待审核通知'); }); // 消息成功通知 @@ -784,16 +793,21 @@ protected function viewEditFriend(HttpRequest $request, $friendId): Application| protected function viewLink(): Factory|View|Application { $this->data['webSubTitle'] = '友链'; - $this->getFriendsLink($this->data); + $this->data['blogLink'] = DB::table('blog_link') + ->whereNotIn('blog_link.blogLocation', [0]) + ->get() + ->toArray(); + $this->data['blogSort'] = DB::table('blog_sort') + ->orderBy('blog_sort.sort') + ->get() + ->toArray(); + $this->data['blogColor'] = DB::table('blog_color') + ->orderBy('id') + ->get() + ->toArray(); return view('function.link', $this->data); } - private function getFriendsLink(array &$data): void - { - $data['blogLink'] = DB::table('blog_link')->whereNotIn('blog_link.blogLocation', [0])->get()->toArray(); - $data['blogSort'] = DB::table('blog_sort')->orderBy('blog_sort.sort')->get()->toArray(); - } - protected function viewMakeFriend(): Factory|View|Application { $this->data['webSubTitle'] = '添加友链'; @@ -805,6 +819,8 @@ protected function viewMakeFriend(): Factory|View|Application ->orderBy('sort') ->get() ->toArray(); + $this->data['applicationRule'] = DB::table('info')->find(15)->data; + $this->data['applicationInfo'] = (new Index())->MarkdownToStringReplace(DB::table('info')->find(16)->data); return view('function.make-friend', $this->data); } diff --git a/app/Http/Controllers/Index.php b/app/Http/Controllers/Index.php index 8141898..e0c33be 100644 --- a/app/Http/Controllers/Index.php +++ b/app/Http/Controllers/Index.php @@ -25,7 +25,7 @@ public function __construct() 'webDescription' => empty($tempStorage = DB::table('info')->find(2)->data) ? '未定义副标题' : $tempStorage, 'webSubTitle' => empty($tempStorage = DB::table('info')->find(3)->data) ? '未定义小标题' : $tempStorage, 'webSubTitleDescription' => empty($tempStorage = DB::table('info')->find(4)->data) ? '未定义小标题内容' : $tempStorage, - 'webIcon' => empty($tempStorage = DB::table('info')->find(5)->data) ? asset('images/logo.jpg') : $tempStorage, + 'webIcon' => empty($tempStorage = DB::table('info')->find(5)->data) ? asset('images/favicon.png') : $tempStorage, 'webHeader' => DB::table('info')->find(7)->data, 'webFooter' => DB::table('info')->find(8)->data, 'webKeyword' => empty($tempStorage = DB::table('info')->find(6)->data) ? '筱锋,凌中的锋雨,xiao_lfeng' : $tempStorage, @@ -41,10 +41,11 @@ public function __construct() $this->data = array_merge($this->data, ['GonganCode' => $data[0]]); } if (Auth::check()) { - $this->data = array_merge($this->data,[ + $this->data = array_merge($this->data, [ 'userName' => Auth::user()->username, 'userEmail' => Auth::user()->email, - 'userIcon' => Auth::user()->icon]); + 'userIcon' => Auth::user()->icon, + 'userAdmin' => Auth::user()->admin]); } } @@ -63,7 +64,19 @@ protected function ViewAboutMe(): Factory|View|Application return view('about', $this->data); } - private function MarkdownToStringReplace(string $dataBase): string + protected function viewPageNotFounded(): Factory|View|Application + { + $this->data['webSubTitle'] = '页面未找到'; + return view('modules.404', $this->data); + } + + protected function viewNoPermission(): Factory|View|Application + { + $this->data['webSubTitle'] = '没有权限'; + return view('modules.no-permission', $this->data); + } + + public function MarkdownToStringReplace(string $dataBase): string { $decodeText = MarkdownExtra::defaultTransform($dataBase); $decodeText = str_replace('

', '

', $decodeText); diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index b9872f6..516aded 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -8,6 +8,7 @@ namespace App\Http; use App\Http\Middleware\Authenticate; +use App\Http\Middleware\CheckConsoleUser; use App\Http\Middleware\EncryptCookies; use App\Http\Middleware\RedirectIfAuthenticated; use App\Http\Middleware\VerifyCsrfToken; @@ -76,6 +77,7 @@ class Kernel extends HttpKernel * @var array */ protected $routeMiddleware = [ + 'authConsole' => CheckConsoleUser::class, 'auth' => Authenticate::class, 'auth.basic' => AuthenticateWithBasicAuth::class, 'cache.headers' => SetCacheHeaders::class, diff --git a/app/Http/Middleware/CheckConsoleUser.php b/app/Http/Middleware/CheckConsoleUser.php new file mode 100644 index 0000000..4b9ab24 --- /dev/null +++ b/app/Http/Middleware/CheckConsoleUser.php @@ -0,0 +1,37 @@ +admin == 1) { + return $next($request); + } else { + return redirect()->route('no-permission'); + } + } else { + return redirect()->route('login'); + } + } +} diff --git a/database/migrations/2023_06_12_051939_update_users_table.php b/database/migrations/2023_06_12_051939_update_users_table.php index 06141e8..0d446f4 100644 --- a/database/migrations/2023_06_12_051939_update_users_table.php +++ b/database/migrations/2023_06_12_051939_update_users_table.php @@ -21,6 +21,7 @@ public function up() Schema::table('users', function (Blueprint $table) { $table->integer('linkId')->unique()->nullable()->default(null)->after('remember_token'); $table->string('icon')->default('https://api.x-lf.cn/avatar/?uid=1')->after('remember_token'); + $table->boolean('admin')->default(0)->after('email')->comment('判别用户是否是管理员'); }); } diff --git a/resources/images/favicon.png b/resources/images/favicon.png new file mode 100644 index 0000000..b4a0b2f Binary files /dev/null and b/resources/images/favicon.png differ diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 87c791a..81286fb 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -87,7 +87,7 @@ function user_change() { dataType: "json", success: function (returnData) { if (returnData.output === "Success") { - window.location.href = '{{ route('console.dashboard') }}' + window.location.href = '{{ route('account.dashboard') }}' } else { window.alert("错误!") } diff --git a/resources/views/console/friends-link/add.blade.php b/resources/views/console/friends-link/add.blade.php new file mode 100644 index 0000000..ef04abe --- /dev/null +++ b/resources/views/console/friends-link/add.blade.php @@ -0,0 +1,434 @@ + + + + + + + + + @include('modules.head') + {!! $webHeader !!} + + + + + +@include('console.modules.aside') + +

+
+ @include('console.modules.personal') +
+
友链添加
+
+
+
+
+

当前友链

+

超级友链

+

待审友链

+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+ +
+
+ +
+ +
+
+
+ + +
+
+ +
+ +
+
+
+
+
+
+ +
+
+ +
+ +
+
+
+ + +
+
+ +
+ +
+
+
+
+ + +
+
+ +
+ +
+
+
+ + +
+
+ +
+ +
+
+
+
+ +
+
+ + +
+
+ +
+ +
+
+
+
+
+
+ + +
+
+ + + +
+ +
+
+ +
+
+ +
+ +
+
+
+
+
+
+
+
+ + +
+
+
+
+
+ + 参考样式 +
+
+ +
+ Bordered avatar +
+

标题

+

副标题

+
+
+
+
+ +
+ Bordered avatar +
+

标题

+

副标题

+
+
+
+
+
+
+
+
+
+ + + + + + + diff --git a/resources/views/console/friends-link/check.blade.php b/resources/views/console/friends-link/check.blade.php index b7713c2..522e7ee 100644 --- a/resources/views/console/friends-link/check.blade.php +++ b/resources/views/console/friends-link/check.blade.php @@ -35,32 +35,38 @@ class="inline-flex items-center p-2 mt-2 ml-3 text-sm text-gray-500 rounded-lg s
@if(!empty($blog))
+ + @endforeach @else -

暂无待审核用户

+

+ 暂无待审核用户

去去其他地方逛逛吧

@endif @@ -85,17 +91,18 @@ class="inline-flex items-center p-2 mt-2 ml-3 text-sm text-gray-500 rounded-lg s + diff --git a/resources/views/console/friends-link/edit.blade.php b/resources/views/console/friends-link/edit.blade.php index 20a5b82..a47ffd4 100644 --- a/resources/views/console/friends-link/edit.blade.php +++ b/resources/views/console/friends-link/edit.blade.php @@ -28,32 +28,56 @@ class="inline-flex items-center p-2 mt-2 ml-3 text-sm text-gray-500 rounded-lg s
@include('console.modules.personal')
-
友链修改
+
{{ $subDescriptionForLine }}
-

当前友链

-

超级友链

-

待审友链

+

当前友链

+

超级友链

+

待审友链

+
+
+
+
+
+ + +
-
+
- +
- +
- -

- +
- +
- -
- -
- -
- -

-
+
- - @if(empty($blogSort[0])) @else @foreach($blogSort as $blogValue) - + @endforeach @endif
- - + +
+
+ +
+
+ +
+ +
-
- -
-
+
参考样式
-
-
+
+ +
Bordered avatar @@ -215,9 +314,14 @@ class="w-16 h-16 p-1 rounded-full ring-2 ring-gray-300 dark:ring-gray-500 me-2 s
-
-
+
+ +
Bordered avatar @@ -233,21 +337,258 @@ class="w-16 h-16 p-1 rounded-full ring-2 ring-gray-300 dark:ring-gray-500 me-2 s
+ + + + + + + + diff --git a/resources/views/console/friends-link/list.blade.php b/resources/views/console/friends-link/list.blade.php index ab90e90..57bcf80 100644 --- a/resources/views/console/friends-link/list.blade.php +++ b/resources/views/console/friends-link/list.blade.php @@ -33,20 +33,27 @@ class="inline-flex items-center p-2 mt-2 ml-3 text-sm text-gray-500 rounded-lg s
-

当前友链 {{ $blogFriendsTotal }}

-

超级友链 {{ $blogFriendsBest }}

-

待审友链 {{ $blogFriendsCheck }}

+

当前友链 {{ $blogFriendsTotal }}

+

超级友链 {{ $blogFriendsBest }}

+

待审友链 {{ $blogFriendsCheck }}

@if(!empty($blog) && empty($request->search))
    - @foreach($blog as $blogValue) + @foreach($blog as $blogValue)
  • - Neil image + Bordered avatar

    @@ -57,21 +64,27 @@ class="inline-flex items-center p-2 mt-2 ml-3 text-sm text-gray-500 rounded-lg s

    - + 编辑
  • - @endforeach + @endforeach
@elseif(!empty($request->search)) - 返回友链列表 + 返回友链列表 @if(!empty($blog))
+
-

当前友链 {{ $blogFriendsTotal }}

-

超级友链 {{ $blogFriendsBest }}

-

待审友链 {{ $blogFriendsCheck }}

+

当前友链 {{ $blogFriendsTotal }}

+

超级友链 {{ $blogFriendsBest }}

+

待审友链 {{ $blogFriendsCheck }}

diff --git a/resources/views/console/modules/aside.blade.php b/resources/views/console/modules/aside.blade.php index 9a0b0a7..56d7942 100644 --- a/resources/views/console/modules/aside.blade.php +++ b/resources/views/console/modules/aside.blade.php @@ -2,7 +2,17 @@ class="fixed top-0 left-0 z-40 w-64 h-screen transition-transform -translate-x-full sm:translate-x-0" aria-label="Sidebar"> diff --git a/resources/views/function/edit-friend.blade.php b/resources/views/function/edit-friend.blade.php index e01ef71..e28bf74 100644 --- a/resources/views/function/edit-friend.blade.php +++ b/resources/views/function/edit-friend.blade.php @@ -213,7 +213,8 @@ class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus: @else @foreach($blogColor as $blogValue) + @if($blogValue->id == $blog->blogSetColor)selected @endif @if($blogValue->onlyAdminUse)disabled @endif> + {!! $blogValue->comment !!} @endforeach @endif diff --git a/resources/views/function/link.blade.php b/resources/views/function/link.blade.php index 9679d47..28c312b 100644 --- a/resources/views/function/link.blade.php +++ b/resources/views/function/link.blade.php @@ -23,14 +23,23 @@ class="relative left-[calc(50%-11rem)] aspect-[1155/678] w-[36.125rem] -translat @foreach($blogSort as $valueSort)
{!! $valueSort->title !!}
- @if(!empty($valueSort->description))
{{ $valueSort->description }}
@endif + @if(!empty($valueSort->description)) +
{{ $valueSort->description }}
+ @endif
- @if(empty($blogColor[0])) @else @foreach($blogColor as $blogValue) - + @endforeach @endif @@ -170,17 +171,29 @@ class="w-16 h-16 p-1 rounded-full ring-2 ring-gray-300 dark:ring-gray-500 me-2 s
- +

- +
@@ -235,17 +248,50 @@ class="ml-auto -mx-1.5 -my-1.5 bg-white text-gray-400 hover:text-gray-900 rounde
- + + + +{!! $webFooter !!} + diff --git a/resources/views/modules/head.blade.php b/resources/views/modules/head.blade.php index af08ffb..31c29aa 100644 --- a/resources/views/modules/head.blade.php +++ b/resources/views/modules/head.blade.php @@ -6,5 +6,9 @@ - + + + + + diff --git a/resources/views/modules/navbar.blade.php b/resources/views/modules/navbar.blade.php index c35bfab..39b1f56 100644 --- a/resources/views/modules/navbar.blade.php +++ b/resources/views/modules/navbar.blade.php @@ -46,23 +46,29 @@ class="-m-2.5 inline-flex items-center justify-center rounded-md p-2.5 text-gray
{{ $userName }}
- +