mirror of
https://gitee.com/technical-laohu/mpay_v2_webman.git
synced 2026-04-04 17:14:26 +08:00
更新项目结构
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
namespace app\http\admin\controller;
|
||||
|
||||
use support\Request;
|
||||
|
||||
26
app/http/admin/middleware/UserAuthMiddleware.php
Normal file
26
app/http/admin/middleware/UserAuthMiddleware.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\admin\middleware;
|
||||
|
||||
use Webman\MiddlewareInterface;
|
||||
use Webman\Http\Response;
|
||||
use Webman\Http\Request;
|
||||
|
||||
/**
|
||||
* Class UserAuthMiddleware
|
||||
* @package app\http\admin\middleware
|
||||
*/
|
||||
class UserAuthMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public function process(Request $request, callable $handler): Response
|
||||
{
|
||||
// 检查用户是否已经登录,这里假设通过 session 中的 'user_id' 判断
|
||||
if (!$request->session()->has('user_id')) {
|
||||
// 用户未登录,重定向到登录页面
|
||||
return redirect('/login');
|
||||
}
|
||||
|
||||
// 用户已登录,继续处理请求
|
||||
return $handler($request);
|
||||
}
|
||||
}
|
||||
8
app/http/admin/route/route.php
Normal file
8
app/http/admin/route/route.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Webman\Route;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
39
app/http/admin/validate/UserValidator.php
Normal file
39
app/http/admin/validate/UserValidator.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace app\http\admin\validate;
|
||||
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
class UserValidator
|
||||
{
|
||||
/**
|
||||
* 验证用户数据
|
||||
*
|
||||
* @param array $data 包含用户信息的数组,应包含 'username', 'email', 'password' 键
|
||||
* @return array 包含验证错误信息的数组,若验证通过则返回空数组
|
||||
*/
|
||||
public function validate(array $data)
|
||||
{
|
||||
$errors = [];
|
||||
|
||||
// 验证用户名
|
||||
$usernameValidator = v::stringType()->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;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ use Webman\Route;
|
||||
|
||||
|
||||
|
||||
Route::disableDefaultRoute();
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user