From 68dfc68cb617b86d011f743f2a16be119fc9aeac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8A=80=E6=9C=AF=E8=80=81=E8=83=A1?= <1094551889@qq.com> Date: Fri, 27 Jun 2025 13:09:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A1=B9=E7=9B=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin}/controller/IndexController.php | 2 +- .../admin/middleware/UserAuthMiddleware.php | 26 +++++++++++++ app/http/admin/route/route.php | 8 ++++ app/http/admin/validate/UserValidator.php | 39 +++++++++++++++++++ config/route.php | 1 + 5 files changed, 75 insertions(+), 1 deletion(-) rename app/{ => http/admin}/controller/IndexController.php (94%) create mode 100644 app/http/admin/middleware/UserAuthMiddleware.php create mode 100644 app/http/admin/route/route.php create mode 100644 app/http/admin/validate/UserValidator.php diff --git a/app/controller/IndexController.php b/app/http/admin/controller/IndexController.php similarity index 94% rename from app/controller/IndexController.php rename to app/http/admin/controller/IndexController.php index ef309f4..e172421 100644 --- a/app/controller/IndexController.php +++ b/app/http/admin/controller/IndexController.php @@ -1,6 +1,6 @@ session()->has('user_id')) { + // 用户未登录,重定向到登录页面 + return redirect('/login'); + } + + // 用户已登录,继续处理请求 + return $handler($request); + } +} \ No newline at end of file diff --git a/app/http/admin/route/route.php b/app/http/admin/route/route.php new file mode 100644 index 0000000..82e7e27 --- /dev/null +++ b/app/http/admin/route/route.php @@ -0,0 +1,8 @@ +length(3, 20)->alnum(); + if (!$usernameValidator->validate($data['username'] ?? '')) { + $errors['username'] = '用户名必须为 3 到 20 个字母或数字字符'; + } + + // 验证邮箱 + $emailValidator = v::email(); + if (!$emailValidator->validate($data['email'] ?? '')) { + $errors['email'] = '请输入有效的邮箱地址'; + } + + // 验证密码 + $passwordValidator = v::stringType()->length(6, null); + if (!$passwordValidator->validate($data['password'] ?? '')) { + $errors['password'] = '密码至少需要 6 个字符'; + } + + return $errors; + } +} diff --git a/config/route.php b/config/route.php index a5064fc..4689583 100644 --- a/config/route.php +++ b/config/route.php @@ -16,6 +16,7 @@ use Webman\Route; +Route::disableDefaultRoute();