关闭验证码功能

This commit is contained in:
2026-03-03 18:55:03 +08:00
parent eaf3f2f48f
commit 267b088242
7 changed files with 42 additions and 19 deletions

View File

@@ -20,3 +20,6 @@ VITE_OPEN_ROUTE_INFO = false
# 锁屏加密密钥
VITE_LOCK_ENCRYPT_KEY = s3cur3k3y4adpro
# 登录页是否显示验证码,设为 false 可关闭(需与后端 LOGIN_CAPTCHA_ENABLE 一致)
VITE_LOGIN_CAPTCHA_ENABLED = false

View File

@@ -7,5 +7,8 @@ VITE_BASE_URL = ./
# API 根地址(后端路由为 /core、/tool、/dice 等,无 /prod 前缀,不要加 /prod
VITE_API_URL = https://dice-api.yuliao666.top
# 登录页是否显示验证码,设为 false 可关闭(需与后端 LOGIN_CAPTCHA_ENABLE 一致)
VITE_LOGIN_CAPTCHA_ENABLED = false
# Delete console
VITE_DROP_CONSOLE = true

View File

@@ -82,12 +82,12 @@ declare namespace Api {
image: string
}
/** 登录参数 */
/** 登录参数(关闭验证码时可不传 code、uuid */
interface LoginParams {
username: string
password: string
code: string
uuid: string
code?: string
uuid?: string
}
/** 登录响应 */

View File

@@ -164,6 +164,8 @@ export interface EnvConfig {
VITE_USE_GZIP?: string
// 是否开启 CDN
VITE_USE_CDN?: string
// 登录页是否启用验证码,设为 false 或 0 关闭
VITE_LOGIN_CAPTCHA_ENABLED?: string
}
// 应用配置

View File

@@ -35,7 +35,7 @@
show-password
/>
</ElFormItem>
<ElFormItem prop="code">
<ElFormItem v-if="captchaEnabled" prop="code">
<ElInput
class="custom-height"
:placeholder="$t('login.placeholder.code')"
@@ -115,6 +115,12 @@
const systemName = AppConfig.systemInfo.name
const formRef = ref<FormInstance>()
/** 是否启用登录验证码(与后端 LOGIN_CAPTCHA_ENABLE 保持一致) */
const captchaEnabled = computed(() => {
const v = import.meta.env.VITE_LOGIN_CAPTCHA_ENABLED
return v !== 'false' && v !== '0'
})
const formData = reactive({
username: '',
password: '',
@@ -123,16 +129,21 @@
rememberPassword: true
})
const rules = computed<FormRules>(() => ({
username: [{ required: true, message: t('login.placeholder.username'), trigger: 'blur' }],
password: [{ required: true, message: t('login.placeholder.password'), trigger: 'blur' }],
code: [{ required: true, message: t('login.placeholder.code'), trigger: 'blur' }]
}))
const rules = computed<FormRules>(() => {
const r: FormRules = {
username: [{ required: true, message: t('login.placeholder.username'), trigger: 'blur' }],
password: [{ required: true, message: t('login.placeholder.password'), trigger: 'blur' }]
}
if (captchaEnabled.value) {
r.code = [{ required: true, message: t('login.placeholder.code'), trigger: 'blur' }]
}
return r
})
const loading = ref(false)
onMounted(() => {
refreshCaptcha()
if (captchaEnabled.value) refreshCaptcha()
})
// 登录
@@ -146,12 +157,11 @@
loading.value = true
// 登录请求
// 登录请求(关闭验证码时不传 code/uuid
const { access_token, refresh_token } = await fetchLogin({
username: formData.username,
password: formData.password,
code: formData.code,
uuid: formData.uuid
...(captchaEnabled.value ? { code: formData.code, uuid: formData.uuid } : {})
})
// 验证token
@@ -178,7 +188,7 @@
console.error('[Login] Unexpected error:', error)
}
} finally {
refreshCaptcha()
if (captchaEnabled.value) refreshCaptcha()
loading.value = false
}
}

View File

@@ -49,9 +49,12 @@ class LoginController extends BaseController
$code = $request->post('code', '');
$uuid = $request->post('uuid', '');
$captcha = new Captcha();
if (!$captcha->checkCaptcha($uuid, $code)) {
return $this->fail('验证码错误');
$captchaEnabled = config('plugin.saiadmin.saithink.captcha.enable', true);
if ($captchaEnabled) {
$captcha = new Captcha();
if (!$captcha->checkCaptcha($uuid, $code)) {
return $this->fail('验证码错误');
}
}
$logic = new SystemUserLogic();
$data = $logic->login($username, $password, $type);

View File

@@ -8,9 +8,11 @@ return [
'access_exp' => 8 * 60 * 60, // 登录token有效期默认8小时
// 验证码存储模式
// 验证码配置
'captcha' => [
// 验证码存储模式 session或者cache
// 是否启用登录验证码。改为 false 即关闭;也可用环境变量 LOGIN_CAPTCHA_ENABLE=0 关闭
'enable' => filter_var(getenv('LOGIN_CAPTCHA_ENABLE') ?: '0', FILTER_VALIDATE_BOOLEAN),
// 验证码存储模式 session 或 cache
'mode' => getenv('CAPTCHA_MODE'),
// 验证码过期时间 (秒)
'expire' => 300,