diff --git a/backend/app/Controllers/AuthController.php b/backend/app/Controllers/AuthController.php
index b4a8e30..d35ea34 100644
--- a/backend/app/Controllers/AuthController.php
+++ b/backend/app/Controllers/AuthController.php
@@ -7,6 +7,7 @@ use App\Core\Database;
use App\Core\Validator;
use App\Services\JwtService;
use App\Services\TurnstileService;
+use App\Services\CaptchaService;
/**
* 认证控制器
@@ -53,11 +54,17 @@ class AuthController extends Controller
$this->error('请输入用户名或邮箱');
}
- // Cloudflare Turnstile(按系统配置开关与入口白名单)
- $portalKey = $portal === 'agent' ? 'agent_login' : 'admin_login';
- $turnstileToken = trim((string) ($input['turnstile_token'] ?? ''));
- if (!TurnstileService::verifyFor($portalKey, $turnstileToken !== '' ? $turnstileToken : null, clientIp())) {
- $this->error('人机验证失败,请完成验证后重试');
+ // 人机验证:代理入口用图形数字验证码,管理员入口用 Cloudflare Turnstile(按配置开关)
+ if ($portal === 'agent') {
+ $captchaCode = trim((string) ($input['captcha_code'] ?? ''));
+ if (!CaptchaService::verify($captchaCode)) {
+ $this->error('图形验证码错误或已过期,请刷新后重试');
+ }
+ } else {
+ $turnstileToken = trim((string) ($input['turnstile_token'] ?? ''));
+ if (!TurnstileService::verifyFor('admin_login', $turnstileToken !== '' ? $turnstileToken : null, clientIp())) {
+ $this->error('人机验证失败,请完成验证后重试');
+ }
}
$db = Database::getInstance();
@@ -133,10 +140,10 @@ class AuthController extends Controller
$this->error('两次输入的密码不一致');
}
- // Cloudflare Turnstile(按系统配置开关与入口白名单)
- $turnstileToken = trim((string) ($input['turnstile_token'] ?? ''));
- if (!TurnstileService::verifyFor('agent_register', $turnstileToken !== '' ? $turnstileToken : null, clientIp())) {
- $this->error('人机验证失败,请完成验证后重试');
+ // 图形数字验证码(代理注册)
+ $captchaCode = trim((string) ($input['captcha_code'] ?? ''));
+ if (!CaptchaService::verify($captchaCode)) {
+ $this->error('图形验证码错误或已过期,请刷新后重试');
}
// 手机号格式验证
diff --git a/backend/app/Controllers/PublicController.php b/backend/app/Controllers/PublicController.php
index f563f24..ff02839 100644
--- a/backend/app/Controllers/PublicController.php
+++ b/backend/app/Controllers/PublicController.php
@@ -832,6 +832,22 @@ class PublicController extends Controller
], 'ok');
}
+ /**
+ * 图形数字验证码(SVG,代理登录/注册用)
+ * GET /api/public/captcha
+ */
+ public function captcha(): void
+ {
+ [, $svg] = \App\Services\CaptchaService::generate();
+
+ header('Content-Type: image/svg+xml; charset=UTF-8');
+ header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
+ header('Pragma: no-cache');
+ header('Expires: 0');
+ echo $svg;
+ exit;
+ }
+
/**
* 获取公告列表(公开/客户端)
* GET /api/public/announcements?target=client&project_id=1&limit=10
diff --git a/backend/app/Services/CaptchaService.php b/backend/app/Services/CaptchaService.php
new file mode 100644
index 0000000..0cd1f7e
--- /dev/null
+++ b/backend/app/Services/CaptchaService.php
@@ -0,0 +1,132 @@
+ self::TTL) {
+ return false;
+ }
+
+ $input = trim((string) $input);
+ if ($input === '') {
+ return false;
+ }
+
+ return hash_equals($code, $input);
+ }
+
+ /**
+ * 渲染 SVG 图形
+ */
+ private static function render(string $code): string
+ {
+ $w = 132;
+ $h = 40;
+
+ $textColors = ['#1f2937', '#374151', '#1e3a8a', '#3f3f46', '#4c1d95', '#7c2d12', '#065f46'];
+ $bgColors = ['#f8fafc', '#f1f5f9', '#fdf4ff', '#ecfeff', '#f7fee7'];
+ $lineColors = ['#c7d2fe', '#fbcfe8', '#a5f3fc', '#bbf7d0'];
+
+ $bg = $bgColors[random_int(0, count($bgColors) - 1)];
+ $line = $lineColors[random_int(0, count($lineColors) - 1)];
+
+ $svg = [];
+ $svg[] = sprintf(
+ '';
+
+ return implode('', $svg);
+ }
+}
diff --git a/backend/routes/api.php b/backend/routes/api.php
index e26117d..0ae36c8 100644
--- a/backend/routes/api.php
+++ b/backend/routes/api.php
@@ -50,6 +50,9 @@ $router->group('api/public', function ($router) {
// 人机验证公开配置(登录页用;客户端激活/验证接口从不校验)
$router->get('turnstile-config', [PublicController::class, 'turnstileConfig']);
+ // 图形数字验证码(代理登录/注册用)
+ $router->get('captcha', [PublicController::class, 'captcha']);
+
// 支付方式(前台展示用)
$router->get('payment/options', [PublicController::class, 'paymentOptions']);
diff --git a/frontend/src/components/ImageCaptcha.vue b/frontend/src/components/ImageCaptcha.vue
new file mode 100644
index 0000000..6707dd4
--- /dev/null
+++ b/frontend/src/components/ImageCaptcha.vue
@@ -0,0 +1,69 @@
+
+
+
+
+
![图形验证码]()
+
+
+
+
+
+
+
diff --git a/frontend/src/stores/user.js b/frontend/src/stores/user.js
index fd89126..a0844a9 100644
--- a/frontend/src/stores/user.js
+++ b/frontend/src/stores/user.js
@@ -11,12 +11,11 @@ export const useUserStore = defineStore('user', () => {
* @param {string} account 用户名或邮箱
* @param {string} password 密码
* @param {'admin'|'agent'} portal 登录入口
- * @param {string} turnstileToken Turnstile 人机验证 token
+ * @param {object} extra 附加参数(admin: {turnstile_token} / agent: {captcha_code})
*/
- async function login(account, password, portal = 'admin', turnstileToken = '') {
+ async function login(account, password, portal = 'admin', extra = {}) {
const endpoint = portal === 'agent' ? '/auth/agent-login' : '/auth/admin-login'
- const body = { username: account, password }
- if (turnstileToken) body.turnstile_token = turnstileToken
+ const body = { username: account, password, ...(extra || {}) }
const res = await request.post(endpoint, body)
user.value = res.data.user
token.value = res.data.token.access_token
diff --git a/frontend/src/styles/common.css b/frontend/src/styles/common.css
index 600f421..a4bfd5a 100644
--- a/frontend/src/styles/common.css
+++ b/frontend/src/styles/common.css
@@ -69,9 +69,12 @@
/* 全局公共样式 - 列表页统一显示方式 */
-/* 页面容器 */
-[class$="-page"] {
- max-width: 1600px;
+/* 页面容器:后台内容全屏铺满右侧内容区
+ (去掉历史 1600px 限宽;!important 用于覆盖各页面 scoped 样式中的限宽) */
+[class$="-page"],
+.page-container {
+ width: 100%;
+ max-width: none !important;
margin: 0 auto;
}
diff --git a/frontend/src/views/Login.vue b/frontend/src/views/Login.vue
index 8b8144a..ec76ed4 100644
--- a/frontend/src/views/Login.vue
+++ b/frontend/src/views/Login.vue
@@ -91,7 +91,7 @@ async function handleLogin() {
}
loading.value = true
try {
- await userStore.login(form.username, form.password, 'admin', turnstileToken.value)
+ await userStore.login(form.username, form.password, 'admin', { turnstile_token: turnstileToken.value })
ElMessage.success('登录成功')
router.push('/dashboard')
} catch (e) {
diff --git a/frontend/src/views/agent/AgentLogin.vue b/frontend/src/views/agent/AgentLogin.vue
index 3a7f241..27c59f8 100644
--- a/frontend/src/views/agent/AgentLogin.vue
+++ b/frontend/src/views/agent/AgentLogin.vue
@@ -43,8 +43,8 @@
忘记密码?
-
-
+
+
@@ -69,60 +69,47 @@ import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { User, Lock, Avatar } from '@element-plus/icons-vue'
import { useUserStore } from '@/stores/user'
-import TurnstileWidget from '@/components/TurnstileWidget.vue'
-import { TURNSTILE_SITE_KEY } from '@/config/turnstile'
-import request from '@/api'
+import ImageCaptcha from '@/components/ImageCaptcha.vue'
const router = useRouter()
const userStore = useUserStore()
const loading = ref(false)
const formRef = ref(null)
-const turnstileRef = ref(null)
-const turnstileToken = ref('')
-const tsEnabled = ref(false)
-
-function onToken(t) {
- turnstileToken.value = t || ''
-}
+const captchaRef = ref(null)
const form = reactive({
account: '',
password: '',
+ captcha: '',
remember: false,
})
const rules = {
account: [{ required: true, message: '请输入用户名或邮箱', trigger: 'blur' }],
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
+ captcha: [{ required: true, message: '请输入图形验证码', trigger: 'blur' }],
}
-onMounted(async () => {
+onMounted(() => {
const saved = localStorage.getItem('agent_remember_account')
if (saved) {
form.account = saved
form.remember = true
}
- try {
- const res = await request.get('/public/turnstile-config')
- const d = res.data || {}
- tsEnabled.value = !!d.enabled && Array.isArray(d.endpoints) && d.endpoints.includes('agent_login')
- } catch {
- tsEnabled.value = false
- }
})
async function handleLogin() {
if (!formRef.value) return
await formRef.value.validate(async (valid) => {
if (!valid) return
- if (tsEnabled.value && !turnstileToken.value) {
- ElMessage.warning('请先完成人机验证')
- turnstileRef.value?.reset?.()
+ if (!form.captcha.trim()) {
+ ElMessage.warning('请输入图形验证码')
+ captchaRef.value?.refresh?.()
return
}
loading.value = true
try {
- await userStore.login(form.account, form.password, 'agent', turnstileToken.value)
+ await userStore.login(form.account, form.password, 'agent', { captcha_code: form.captcha.trim() })
if (form.remember) {
localStorage.setItem('agent_remember_account', form.account)
} else {
@@ -131,8 +118,8 @@ async function handleLogin() {
ElMessage.success('登录成功')
router.push('/dashboard')
} catch (e) {
- turnstileRef.value?.reset?.()
- turnstileToken.value = ''
+ // 登录失败:验证码已失效,刷新图片
+ captchaRef.value?.refresh?.()
} finally {
loading.value = false
}
diff --git a/frontend/src/views/agent/AgentRegister.vue b/frontend/src/views/agent/AgentRegister.vue
index a046612..3f0c858 100644
--- a/frontend/src/views/agent/AgentRegister.vue
+++ b/frontend/src/views/agent/AgentRegister.vue
@@ -73,8 +73,8 @@
-
-
+
+
@@ -94,34 +94,17 @@