From efc05e0c5af3920342a51a010aebc9d0f814ebc7 Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Thu, 29 Jun 2023 22:00:20 +0800 Subject: [PATCH 01/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0Unit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/laravel.yaml | 47 +++++++++++++++++++++++++++++++++++ phpunit.xml | 18 +++++++------- 2 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 .gitea/workflows/laravel.yaml diff --git a/.gitea/workflows/laravel.yaml b/.gitea/workflows/laravel.yaml new file mode 100644 index 0000000..1640e63 --- /dev/null +++ b/.gitea/workflows/laravel.yaml @@ -0,0 +1,47 @@ +name: Tests + +on: + push: + branches: + - master + - '*.x' + pull_request: + schedule: + - cron: '0 0 * * *' + +permissions: + contents: read + +jobs: + tests: + runs-on: centos + + strategy: + fail-fast: true + matrix: + php: [8.1, 8.2] + + name: PHP + + steps: + - name: 检查代码 + uses: actions/checkout@v3 + + - name: 配置PHP + uses: XiaoLFeng/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite + coverage: none + + - name: 安装PHP Composer依赖 + run: composer install --prefer-dist --no-interaction --no-progress + + - name: 复制配置文件 + run: cp .env.example .env + + - name: 生成应用程序密钥 + run: php artisan key:generate + +# - name: Execute tests +# run: /phpunit diff --git a/phpunit.xml b/phpunit.xml index e4386c4..531beb9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -24,14 +24,14 @@ - - - - - - - - - + + + + + + + + + From 7bf090d6e6366329fc4c8702aff96688b526dfd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E9=94=8Bxiao=5Flfeng?= Date: Fri, 30 Jun 2023 08:37:20 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E5=9B=9E=E6=BB=9A=E8=A1=A5=E4=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- app/Http/Controllers/Function/Link.php | 3 +-- routes/api.php | 1 + routes/web.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Function/Link.php b/app/Http/Controllers/Function/Link.php index ee85a7d..214b9a9 100644 --- a/app/Http/Controllers/Function/Link.php +++ b/app/Http/Controllers/Function/Link.php @@ -386,8 +386,7 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse /** * 站长认证邮件发送模板 * - * @param array $data - * @return void + * @return void 发送链接,不做返回内容 */ private function apiCustomBlogCheckSendEmail(): void { diff --git a/routes/api.php b/routes/api.php index c538bc5..1ee2714 100644 --- a/routes/api.php +++ b/routes/api.php @@ -46,5 +46,6 @@ Route::post('add',[Link::class,'apiCustomAdd'])->name('api.link.custom.add'); Route::get('search',[Link::class, 'apiCustomSearch'])->name('api.link.custom.search'); Route::post('blogCheck',[Link::class,'apiCustomBlogCheck'])->name('api.link.custom.blogCheck'); + Route::post('blogVerify',[Link::class,'apiCustomBlogVerify'])->name('api.link.custom.blogVerify'); }); }); diff --git a/routes/web.php b/routes/web.php index 7d18a0c..c42e6c4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -31,7 +31,7 @@ Route::prefix('function')->group(function () { Route::get('link',[UserLink::class, 'viewLink'])->name('function.link'); Route::get('make-friend',[UserLink::class, 'viewMakeFriend'])->name('function.make-friend'); - Route::get('edit-search',[UserLink::class, 'viewSearchFriends'])->name('function.edit-search'); + Route::get ('edit-search',[UserLink::class, 'viewSearchFriends'])->name('function.edit-search'); Route::get('edit-search/{friendId}',[UserLink::class,'viewSearchFriend'])->name('function.edit-searchOnly'); Route::get('edit-friend/{friendId}',function ($friendId) { $userLink = new UserLink(); From 01a3c71f022d75fa7b623024cc01171616a3b543 Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Fri, 30 Jun 2023 10:01:41 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E5=8D=9A=E5=AE=A2=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=B7=BB=E5=8A=A0=E6=A0=A1=E9=AA=8C=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- app/Http/Controllers/Function/Link.php | 188 ++++++++++++++----------- 1 file changed, 109 insertions(+), 79 deletions(-) diff --git a/app/Http/Controllers/Function/Link.php b/app/Http/Controllers/Function/Link.php index 214b9a9..f48ec26 100644 --- a/app/Http/Controllers/Function/Link.php +++ b/app/Http/Controllers/Function/Link.php @@ -264,119 +264,149 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse { /** @var array $returnData Json的 return 返回值 */ // 验证数据 - $resultBlog = DB::table('blog_link') - ->select('id', 'blogOwnEmail') - ->find((int)$request->id); - if (!empty($resultBlog->id)) { - // 检查输入博客是否对应 - if (!empty($resultBlog->blogOwnEmail)) { - if (strcmp($resultBlog->blogOwnEmail, $request->email) == 0) { - // 生成验证码(筛查内容) - $resultVerifyCode = DB::table('code') - ->where([ - ['email', '=', $resultBlog->blogOwnEmail], - ['type', '=', 'CODE-CUSTOM-CHECK'], - ['time', '>', time()]]) - ->get() - ->toArray(); - // 不存在验证码,生成验证码并存入数据库中 - if (empty($resultVerifyCode[0]->id)) { - // 生成6位数验证码 - $verifyCode = null; - for ($i = 0; $i < 6; $i++) - $verifyCode .= rand(0, 9); + $dataCheck = Validator::make($request->all(),[ + 'id' => 'required|int', + 'userEmail' => 'required|email', + 'userCode' => 'string|min:6|max:64|regex:#^[0-9A-Za-z]+$#', + ]); - // 存入数据库 - DB::table('code') - ->insert([ - 'email' => $resultBlog->blogOwnEmail, - 'code' => $verifyCode, - 'type' => 'CODE-CUSTOM-CHECK', - 'sendTime' => time(), - 'time' => time()+900, - ]); - // 数据整理 - $this->sendEmail = [ - 'userEmail' => $resultBlog->blogOwnEmail, - 'verifyCode' => $verifyCode, - 'sendTime' => time(), - ]; - $this->apiCustomBlogCheckSendEmail(); - $returnData = [ - 'output' => 'Success', - 'code' => 200, - 'data' => [ - 'message' => '发送成功', - ], - ]; - } else { - // 存在验证码,检查验证码是否需要重新发送 - $data = DB::table('code') + if ($dataCheck->fails()) { + $resultBlog = DB::table('blog_link') + ->select('id', 'blogOwnEmail') + ->find((int)$request->id); + if (!empty($resultBlog->id)) { + // 检查输入博客是否对应 + if (!empty($resultBlog->blogOwnEmail)) { + if (strcmp($resultBlog->blogOwnEmail, $request->email) == 0) { + // 生成验证码(筛查内容) + $resultVerifyCode = DB::table('code') ->where([ - ['email','=',$resultBlog->blogOwnEmail], - ['type','=','CODE-CUSTOM-CHECK'], - ['time','>',time()]]) + ['email', '=', $resultBlog->blogOwnEmail], + ['type', '=', 'CODE-CUSTOM-CHECK'], + ['time', '>', time()]]) ->get() ->toArray(); - $this->sendEmail = [ - 'userEmail' => $data[0]->email, - 'verifyCode' => $data[0]->code, - 'sendTime' => time(), - ]; - if ($resultVerifyCode[0]->sendTime < time()-60) { - // 发送验证码 + // 不存在验证码,生成验证码并存入数据库中 + if (empty($resultVerifyCode[0]->id)) { + // 生成6位数验证码 + $verifyCode = null; + for ($i = 0; $i < 6; $i++) + $verifyCode .= rand(0, 9); + + // 存入数据库 DB::table('code') - ->where([ - ['email','=',$resultBlog->blogOwnEmail], - ['type','=','CODE-CUSTOM-CHECK'], - ['time','>',time()]]) - ->update(['sendTime' => time()]); + ->insert([ + 'email' => $resultBlog->blogOwnEmail, + 'code' => $verifyCode, + 'type' => 'CODE-CUSTOM-CHECK', + 'sendTime' => time(), + 'time' => time() + 900, + ]); + // 数据整理 + $this->sendEmail = [ + 'userEmail' => $resultBlog->blogOwnEmail, + 'verifyCode' => $verifyCode, + 'sendTime' => time(), + ]; $this->apiCustomBlogCheckSendEmail(); $returnData = [ 'output' => 'Success', 'code' => 200, 'data' => [ - 'message' => '重新发送成功', + 'message' => '发送成功', ], ]; } else { - // 避免重复发送 - $returnData = [ - 'output' => 'SendingTimeTooFast', - 'code' => 403, - 'data' => [ - 'message' => '邮件重新发送时间过快', - 'data' => [ - 'time' => 60 - (time() - $resultVerifyCode[0]->sendTime), - ], - ], + // 存在验证码,检查验证码是否需要重新发送 + $data = DB::table('code') + ->where([ + ['email', '=', $resultBlog->blogOwnEmail], + ['type', '=', 'CODE-CUSTOM-CHECK'], + ['time', '>', time()]]) + ->get() + ->toArray(); + $this->sendEmail = [ + 'userEmail' => $data[0]->email, + 'verifyCode' => $data[0]->code, + 'sendTime' => time(), ]; + if ($resultVerifyCode[0]->sendTime < time() - 60) { + // 发送验证码 + DB::table('code') + ->where([ + ['email', '=', $resultBlog->blogOwnEmail], + ['type', '=', 'CODE-CUSTOM-CHECK'], + ['time', '>', time()]]) + ->update(['sendTime' => time()]); + $this->apiCustomBlogCheckSendEmail(); + $returnData = [ + 'output' => 'Success', + 'code' => 200, + 'data' => [ + 'message' => '重新发送成功', + ], + ]; + } else { + // 避免重复发送 + $returnData = [ + 'output' => 'SendingTimeTooFast', + 'code' => 403, + 'data' => [ + 'message' => '邮件重新发送时间过快', + 'data' => [ + 'time' => 60 - (time() - $resultVerifyCode[0]->sendTime), + ], + ], + ]; + } } + } else { + $returnData = [ + 'output' => 'EmailMismatch', + 'code' => 403, + 'data' => [ + 'message' => '邮箱与对应ID不匹配', + ], + ]; } } else { $returnData = [ - 'output' => 'EmailMismatch', + 'output' => 'NoEmail', 'code' => 403, 'data' => [ - 'message' => '邮箱与对应ID不匹配', + 'message' => '对应ID没有绑定邮箱,请联系管理员', ], ]; } } else { $returnData = [ - 'output' => 'NoEmail', + 'output' => 'NoBlog', 'code' => 403, 'data' => [ - 'message' => '对应ID没有绑定邮箱,请联系管理员', + 'message' => '没有ID对应博客', ], ]; } } else { + $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' => 'NoBlog', + 'output' => 'DataFormatError', 'code' => 403, 'data' => [ - 'message' => '没有ID对应博客', + 'message' => '输入内容有错误', + 'errorSingle' => $errorSingle, + 'error' => $errorInfo, ], ]; } From a87693ac6d6b05831d46e4cace106a8d233aa833 Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Fri, 30 Jun 2023 10:09:39 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E6=B7=BB=E5=8A=A0workFlows=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- .gitea/workflows/laravel.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/laravel.yaml b/.gitea/workflows/laravel.yaml index 1640e63..068324f 100644 --- a/.gitea/workflows/laravel.yaml +++ b/.gitea/workflows/laravel.yaml @@ -25,7 +25,7 @@ jobs: steps: - name: 检查代码 - uses: actions/checkout@v3 + uses: https://github.com/actions/checkout@v3 - name: 配置PHP uses: XiaoLFeng/setup-php@v2 @@ -43,5 +43,5 @@ jobs: - name: 生成应用程序密钥 run: php artisan key:generate -# - name: Execute tests -# run: /phpunit + - name: Execute tests + run: /phpunit From 0e192b962e23d62653a5c694f81e46266f598dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E9=94=8Bxiao=5Flfeng?= Date: Fri, 30 Jun 2023 10:18:54 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=9B=B4=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- app/Http/Controllers/Function/Link.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Function/Link.php b/app/Http/Controllers/Function/Link.php index f48ec26..e0b69e4 100644 --- a/app/Http/Controllers/Function/Link.php +++ b/app/Http/Controllers/Function/Link.php @@ -270,14 +270,14 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse 'userCode' => 'string|min:6|max:64|regex:#^[0-9A-Za-z]+$#', ]); - if ($dataCheck->fails()) { + if (!$dataCheck->fails()) { $resultBlog = DB::table('blog_link') ->select('id', 'blogOwnEmail') ->find((int)$request->id); if (!empty($resultBlog->id)) { // 检查输入博客是否对应 if (!empty($resultBlog->blogOwnEmail)) { - if (strcmp($resultBlog->blogOwnEmail, $request->email) == 0) { + if (strcmp($resultBlog->blogOwnEmail, $request->userEmail) == 0) { // 生成验证码(筛查内容) $resultVerifyCode = DB::table('code') ->where([ From 3e71ba79fb4bc0499ddc20d8b2bcfd8e730f794b Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Fri, 30 Jun 2023 11:36:59 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E7=AB=99=E9=95=BF=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E9=80=9A=E8=BF=87=EF=BC=88=E9=AA=8C=E8=AF=81=E7=A0=81=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- app/Http/Controllers/Function/Link.php | 135 +++++++- resources/views/function/edit-check.blade.php | 287 ++++++++++++++++++ 2 files changed, 420 insertions(+), 2 deletions(-) create mode 100644 resources/views/function/edit-check.blade.php diff --git a/app/Http/Controllers/Function/Link.php b/app/Http/Controllers/Function/Link.php index e0b69e4..eaa5388 100644 --- a/app/Http/Controllers/Function/Link.php +++ b/app/Http/Controllers/Function/Link.php @@ -15,6 +15,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request as HttpRequest; +use Illuminate\Http\Response as HttpResponse; use Illuminate\Mail\Message; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Mail; @@ -264,7 +265,7 @@ public function apiCustomBlogCheck(HttpRequest $request): JsonResponse { /** @var array $returnData Json的 return 返回值 */ // 验证数据 - $dataCheck = Validator::make($request->all(),[ + $dataCheck = Validator::make($request->all(), [ 'id' => 'required|int', 'userEmail' => 'required|email', 'userCode' => 'string|min:6|max:64|regex:#^[0-9A-Za-z]+$#', @@ -428,6 +429,120 @@ private function apiCustomBlogCheckSendEmail(): void }); } + /** + * 验证是否为站长 + * + * @param HttpRequest $request 获取HTTP中 Request 数据 + * @return JsonResponse 返回JSON数据 + */ + public function apiCustomBlogVerify(HttpRequest $request): JsonResponse + { + /** @var array $returnData Json的 return 返回值 */ + //数据验证 + $dataCheck = Validator::make($request->all(), [ + 'id' => 'required|int', + 'userEmail' => 'required|email', + 'userCode' => 'required|string|min:6|max:64|regex:#^[0-9A-Za-z]+$#', + ]); + // 验证数据是否合法 + if (!$dataCheck->fails()) { + // 检查内容是否存在 + $resultBlog = DB::table('blog_link') + ->select('id', 'blogOwnEmail') + ->find((int)$request->id); + if (!empty($resultBlog->id)) { + if (!empty($resultBlog->blogOwnEmail)) { + // 验证此邮箱是否与该博客一致 + if (strcmp($resultBlog->blogOwnEmail, $request->userEmail) == 0) { + // 检查验证码是否存在 + $resultCode = DB::table('code') + ->select('id') + ->where([ + ['code.code', '=', $request->userCode], + ['email', '=', $request->userEmail], + ['type', '=', 'CODE-CUSTOM-CHECK'], + ['time', '>', time()]]) + ->get() + ->toArray(); + if (!empty($resultCode[0]->id)) { + // 配置Cookie + $Response = new HttpResponse(); + $Response->withCookie(cookie('friend_edit', password_hash($resultBlog->id, PASSWORD_DEFAULT), 15, '/')); + // 完成验证删除验证码 + DB::table('code') + ->delete((int)$resultCode[0]->id); + // Json + $returnData = [ + 'output' => 'Success', + 'code' => 200, + 'data' => [ + 'message' => '验证成功', + 'id' => $resultBlog->id + ], + ]; + } else { + // 验证码验证失败 + $returnData = [ + 'output' => 'NoVerifyCode', + 'code' => 403, + 'data' => [ + 'message' => '没有这个验证码', + ], + ]; + } + } else { + $returnData = [ + 'output' => 'EmailMismatch', + 'code' => 403, + 'data' => [ + 'message' => '邮箱与对应ID不匹配', + ], + ]; + } + } else { + $returnData = [ + 'output' => 'NoEmail', + 'code' => 403, + 'data' => [ + 'message' => '对应ID没有绑定邮箱,请联系管理员', + ], + ]; + } + } else { + $returnData = [ + 'output' => 'NoBlog', + 'code' => 403, + 'data' => [ + 'message' => '没有ID对应博客', + ], + ]; + } + } else { + $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, + ], + ]; + } + return Response::json($returnData, $returnData['code']); + } + public function viewEditFriend($friendId): Application|Factory|View|RedirectResponse { // 检查内容是否为空 @@ -498,13 +613,29 @@ protected function viewSearchFriends(): Factory|View|Application protected function viewSearchFriend($friendId): Factory|View|Application|RedirectResponse { + /** @var $dataEmail array 获取修改邮箱后的值 */ $this->data['webSubTitle'] = '查询列表'; if (!empty($friendId)) { // 检查 friendId 是否存在 $resultBlog = DB::table('blog_link') - ->select('id','blogOwnEmail') + ->select('id', 'blogOwnEmail', 'blogName') ->find($friendId); if (!empty($resultBlog->id)) { + // 处理加密邮箱 + $strlenEmail = strlen($resultBlog->blogOwnEmail); + ($strlenEmail > 4) ? $j = 1 : $j = 0; + for ($i = 0; $i < $strlenEmail; $i++) { + if ($resultBlog->blogOwnEmail[$i] != '@') { + if ($i > $j && $i < $strlenEmail - ($j + 1)) { + $dataEmail[$i] = '*'; + } else { + $dataEmail[$i] = $resultBlog->blogOwnEmail[$i]; + } + } else { + $dataEmail[$i] = $resultBlog->blogOwnEmail[$i]; + } + } + $resultBlog->blogOwnEmail = implode($dataEmail); $this->data['blog'] = $resultBlog; return view('function.edit-check', $this->data); } else { diff --git a/resources/views/function/edit-check.blade.php b/resources/views/function/edit-check.blade.php new file mode 100644 index 0000000..a1ee5b5 --- /dev/null +++ b/resources/views/function/edit-check.blade.php @@ -0,0 +1,287 @@ + + + + + + + + + @include('modules.head') + {!! $webHeader !!} + + +
+ @include('modules.navbar') +
+ +
+
+ + + +
+ + +
+
+
+
+
+
+
+

+ 身份验证

+

+ 您好 {{ $blog->blogName }} 的站长

+ +
+ + +
+
+ +
+ +
+
+
+ +
+
+ +
+ + +
+
+
+ +
+
+
+
+
+
+ + @include('modules.footer') +
+
+ + + + + + +{!! $webFooter !!} + From eede9543706b3d9f06e02c38c86b76c059a83c77 Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Fri, 30 Jun 2023 11:50:56 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0workFlows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- .gitea/workflows/laravel.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/laravel.yaml b/.gitea/workflows/laravel.yaml index 068324f..3f98d9b 100644 --- a/.gitea/workflows/laravel.yaml +++ b/.gitea/workflows/laravel.yaml @@ -43,5 +43,5 @@ jobs: - name: 生成应用程序密钥 run: php artisan key:generate - - name: Execute tests - run: /phpunit + - name: 执行测试 + run: vendor/bin/phpunit From 0941d9482d571720eec8f6e2abdfb82502ebbf57 Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Fri, 30 Jun 2023 11:51:29 +0800 Subject: [PATCH 08/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- routes/web.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/routes/web.php b/routes/web.php index c42e6c4..d3e3e34 100644 --- a/routes/web.php +++ b/routes/web.php @@ -33,10 +33,7 @@ Route::get('make-friend',[UserLink::class, 'viewMakeFriend'])->name('function.make-friend'); Route::get ('edit-search',[UserLink::class, 'viewSearchFriends'])->name('function.edit-search'); Route::get('edit-search/{friendId}',[UserLink::class,'viewSearchFriend'])->name('function.edit-searchOnly'); - Route::get('edit-friend/{friendId}',function ($friendId) { - $userLink = new UserLink(); - return $userLink->viewEditFriend($friendId); - })->name('function.edit-friend'); + Route::get('edit-friend/{friendId}',[UserLink::class,'viewEditFriend'])->name('function.edit-friend'); Route::get('sponsor',function () { return view('function.sponsor'); })->name('function.sponsor'); From 12d634b5931e34e807bc73e8f5a12faaefbdd9aa Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Fri, 30 Jun 2023 13:12:43 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E5=A4=84=E7=90=86=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- .gitea/workflows/laravel.yaml | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/.gitea/workflows/laravel.yaml b/.gitea/workflows/laravel.yaml index 3f98d9b..eadc137 100644 --- a/.gitea/workflows/laravel.yaml +++ b/.gitea/workflows/laravel.yaml @@ -16,32 +16,18 @@ jobs: tests: runs-on: centos - strategy: - fail-fast: true - matrix: - php: [8.1, 8.2] - name: PHP steps: - - name: 检查代码 + - name: '检查代码' uses: https://github.com/actions/checkout@v3 - - name: 配置PHP + - name: '安装PHP' uses: XiaoLFeng/setup-php@v2 with: - php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite coverage: none + tools: phpmd - - name: 安装PHP Composer依赖 - run: composer install --prefer-dist --no-interaction --no-progress - - - name: 复制配置文件 - run: cp .env.example .env - - - name: 生成应用程序密钥 - run: php artisan key:generate - - - name: 执行测试 - run: vendor/bin/phpunit + - name: '运行PHPMD' + run: phpmd ./ text codesize + continue-on-error: true From 721e1e90c5504d14476b210ce459f0c091fa9bd8 Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Fri, 30 Jun 2023 13:20:56 +0800 Subject: [PATCH 10/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- .gitea/workflows/laravel.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/laravel.yaml b/.gitea/workflows/laravel.yaml index eadc137..67d135d 100644 --- a/.gitea/workflows/laravel.yaml +++ b/.gitea/workflows/laravel.yaml @@ -28,6 +28,15 @@ jobs: coverage: none tools: phpmd - - name: '运行PHPMD' + - name: '检查是否存在未使用代码' + run: phpmd ./ text unusedcode + + - name: '检查命名问题' + run: phpmd ./ text naming + + - name: '检查设计问题' + run: phpmd ./ text naming design + + - name: '检查代码规模是否过大' run: phpmd ./ text codesize continue-on-error: true From 30150f5db03d17e52a7b5ee7b022dfa046ae6e1e Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Fri, 30 Jun 2023 13:22:57 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- .gitea/workflows/laravel.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitea/workflows/laravel.yaml b/.gitea/workflows/laravel.yaml index 67d135d..eb8a4b7 100644 --- a/.gitea/workflows/laravel.yaml +++ b/.gitea/workflows/laravel.yaml @@ -28,9 +28,6 @@ jobs: coverage: none tools: phpmd - - name: '检查是否存在未使用代码' - run: phpmd ./ text unusedcode - - name: '检查命名问题' run: phpmd ./ text naming From 6aa7f978665cee67533115d8aa4c18e10c3f8a6b Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Fri, 30 Jun 2023 13:24:55 +0800 Subject: [PATCH 12/15] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- .gitea/workflows/laravel.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitea/workflows/laravel.yaml b/.gitea/workflows/laravel.yaml index eb8a4b7..b70db22 100644 --- a/.gitea/workflows/laravel.yaml +++ b/.gitea/workflows/laravel.yaml @@ -30,9 +30,11 @@ jobs: - name: '检查命名问题' run: phpmd ./ text naming + continue-on-error: true - name: '检查设计问题' run: phpmd ./ text naming design + continue-on-error: true - name: '检查代码规模是否过大' run: phpmd ./ text codesize From f0d0dc6db3d36eb0f2ffff567c6e92d7b4838033 Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Fri, 30 Jun 2023 16:22:05 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E5=8F=8B=E9=93=BE=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- .../views/function/edit-friend.blade.php | 390 ++++++++++++++++++ 1 file changed, 390 insertions(+) create mode 100644 resources/views/function/edit-friend.blade.php diff --git a/resources/views/function/edit-friend.blade.php b/resources/views/function/edit-friend.blade.php new file mode 100644 index 0000000..39dce30 --- /dev/null +++ b/resources/views/function/edit-friend.blade.php @@ -0,0 +1,390 @@ + + + + + + + + + @include('modules.head') + {!! $webHeader !!} + + +
+ @include('modules.navbar') +
+ +
+
+

+ 自助友链修改系统

+

+ 您好 {{ $blog->blogName }} 的站长

+
+
+
+ +
+
+ +
+ +
+
+
+ + +
+
+ +
+ +
+
+
+
+
+
+ +
+
+ +
+ +
+
+
+ + +
+
+ +
+ +
+
+
+
+ + +
+
+ +
+ +
+
+
+ + +
+
+ +
+ +
+
+
+
+ +
+
+ + +
+
+ +
+ +
+
+
+
+
+
+ + +
+
+ + + +
+
+
+ + +
+
+
+
+ + @include('modules.footer') +
+
+ + + + + + + + +{!! $webFooter !!} + From 3c72e92a62b0aea6f23084ce26ad4051168d7389 Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Fri, 30 Jun 2023 16:22:20 +0800 Subject: [PATCH 14/15] =?UTF-8?q?=E5=AF=B9friend=5Fedit=E7=9A=84COOKIE?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E4=B8=8D=E8=BF=9B=E8=A1=8C=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- app/Http/Middleware/EncryptCookies.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Middleware/EncryptCookies.php b/app/Http/Middleware/EncryptCookies.php index 6839135..1fe6b81 100644 --- a/app/Http/Middleware/EncryptCookies.php +++ b/app/Http/Middleware/EncryptCookies.php @@ -17,6 +17,6 @@ class EncryptCookies extends Middleware * @var array */ protected $except = [ - // + 'friend_edit', ]; } From dd061e26f8fe0cc89f2b6e16aec131035389aecd Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Fri, 30 Jun 2023 16:22:42 +0800 Subject: [PATCH 15/15] =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=EF=BC=8CCookie=E7=9A=84=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XiaoLFeng --- app/Http/Controllers/Function/Link.php | 34 ++++++++++++------- .../views/function/make-friend.blade.php | 19 ++++++++--- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/Function/Link.php b/app/Http/Controllers/Function/Link.php index eaa5388..f60de43 100644 --- a/app/Http/Controllers/Function/Link.php +++ b/app/Http/Controllers/Function/Link.php @@ -15,11 +15,9 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request as HttpRequest; -use Illuminate\Http\Response as HttpResponse; use Illuminate\Mail\Message; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Mail; -use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Response; use Illuminate\Support\Facades\Validator; @@ -438,6 +436,7 @@ private function apiCustomBlogCheckSendEmail(): void public function apiCustomBlogVerify(HttpRequest $request): JsonResponse { /** @var array $returnData Json的 return 返回值 */ + /** @var mixed $cookie 保存Cookie数据 */ //数据验证 $dataCheck = Validator::make($request->all(), [ 'id' => 'required|int', @@ -446,6 +445,7 @@ public function apiCustomBlogVerify(HttpRequest $request): JsonResponse ]); // 验证数据是否合法 if (!$dataCheck->fails()) { + $cookie = cookie('friend_edit', '', -1, '/'); // 检查内容是否存在 $resultBlog = DB::table('blog_link') ->select('id', 'blogOwnEmail') @@ -466,8 +466,7 @@ public function apiCustomBlogVerify(HttpRequest $request): JsonResponse ->toArray(); if (!empty($resultCode[0]->id)) { // 配置Cookie - $Response = new HttpResponse(); - $Response->withCookie(cookie('friend_edit', password_hash($resultBlog->id, PASSWORD_DEFAULT), 15, '/')); + $cookie = cookie('friend_edit', password_hash($resultBlog->id, PASSWORD_DEFAULT), 15, '/',); // 完成验证删除验证码 DB::table('code') ->delete((int)$resultCode[0]->id); @@ -540,10 +539,11 @@ public function apiCustomBlogVerify(HttpRequest $request): JsonResponse ], ]; } - return Response::json($returnData, $returnData['code']); + return Response::json($returnData, $returnData['code']) + ->cookie($cookie); } - public function viewEditFriend($friendId): Application|Factory|View|RedirectResponse + protected function viewEditFriend(HttpRequest $request, $friendId): Application|Factory|View|RedirectResponse { // 检查内容是否为空 if (!empty($friendId)) { @@ -554,19 +554,27 @@ public function viewEditFriend($friendId): Application|Factory|View|RedirectResp ->find($friendId); if (!empty($resultBlog->id)) { // 检查是否存在Cookie作为已验证 - if (Request::hasCookie('friend_edit')) { + if ($request->hasCookie('friend_edit')) { // 检查COOKIE与所验证ID是否匹配 - if (password_verify($friendId, Request::cookie('friend_edit'))) { + if (password_verify($resultBlog->id, $request->cookie('friend_edit'))) { + $this->data['blog'] = $resultBlog; + $this->data['blogColor'] = DB::table('blog_color') + ->orderBy('id') + ->get() + ->toArray(); + $this->data['blogSort'] = DB::table('blog_sort') + ->orderBy('sort') + ->get() + ->toArray(); return view('function.edit-friend', $this->data); } else { - response()->withCookie(cookie('friend_edit', null, time() - 1)); - return Response::redirectTo(route('function.edit-search')); + $cookie = cookie('friend_edit', '', -1, '/'); + return Response::redirectTo(route('function.edit-search')) + ->cookie($cookie); } } else { // 验证页面 - // 加密用户邮箱 - $this->data['blog'] = $resultBlog; - return view('function.edit-check', $this->data); + return Response::redirectTo(route('function.edit-searchOnly', $resultBlog->id)); } } else { // 不存在这一个ID用户 diff --git a/resources/views/function/make-friend.blade.php b/resources/views/function/make-friend.blade.php index 1a6ecc4..05383bd 100644 --- a/resources/views/function/make-friend.blade.php +++ b/resources/views/function/make-friend.blade.php @@ -210,19 +210,28 @@ class="relative left-[calc(50%+3rem)] aspect-[1155/678] w-[36.125rem] -translate
友链已登记 -
已经存有该博客(博客名字、博客地址、博主邮箱不得重复),请确认您没有输入错误吗?(如果想修改已登记博客,请使用在友链登记邮箱进行注册/登录进行修改)
+
已经存有该博客(博客名字、博客地址、博主邮箱不得重复),请确认您没有输入错误吗?(如果想修改已登记博客,请使用在友链登记邮箱进行注册/登录进行修改) +
-