Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var LinuxDOOAuthEnabled = false
var WeChatAuthEnabled = false
var TelegramOAuthEnabled = false
var TurnstileCheckEnabled = false
var RegisterPageWithCaptchaEnabled = false
var RegisterEnabled = true

var EmailDomainRestrictionEnabled = false // 是否启用邮箱域名限制
Expand Down
1 change: 1 addition & 0 deletions controller/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func GetStatus(c *gin.Context) {
"wechat_login": common.WeChatAuthEnabled,
"server_address": system_setting.ServerAddress,
"turnstile_check": common.TurnstileCheckEnabled,
"register_page_with_captcha": common.RegisterPageWithCaptchaEnabled,
"turnstile_site_key": common.TurnstileSiteKey,
"docs_link": operation_setting.GetGeneralSetting().DocsLink,
"quota_per_unit": common.QuotaPerUnit,
Expand Down
9 changes: 9 additions & 0 deletions controller/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ func UpdateOption(c *gin.Context) {
"message": "无法启用 Turnstile 校验,请先填入 Turnstile 校验相关配置信息!",
})

return
}
case "RegisterPageWithCaptchaEnabled":
if option.Value == "true" && common.TurnstileSiteKey == "" {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "无法启用注册人机验证,请先填入 Turnstile 校验相关配置信息!",
})

return
}
case "TelegramOAuthEnabled":
Expand Down
9 changes: 8 additions & 1 deletion middleware/turnstile-check.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ type turnstileCheckResponse struct {

func TurnstileCheck() gin.HandlerFunc {
return func(c *gin.Context) {
if common.TurnstileCheckEnabled {
enabled := common.TurnstileCheckEnabled
if !enabled && common.RegisterPageWithCaptchaEnabled {
path := c.Request.URL.Path
if path == "/api/verification" || path == "/api/user/register" {
enabled = true
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
if enabled {
session := sessions.Default(c)
turnstileChecked := session.Get("turnstile")
if turnstileChecked != nil {
Expand Down
3 changes: 3 additions & 0 deletions model/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func InitOptionMap() {
common.OptionMap["TelegramOAuthEnabled"] = strconv.FormatBool(common.TelegramOAuthEnabled)
common.OptionMap["WeChatAuthEnabled"] = strconv.FormatBool(common.WeChatAuthEnabled)
common.OptionMap["TurnstileCheckEnabled"] = strconv.FormatBool(common.TurnstileCheckEnabled)
common.OptionMap["RegisterPageWithCaptchaEnabled"] = strconv.FormatBool(common.RegisterPageWithCaptchaEnabled)
common.OptionMap["RegisterEnabled"] = strconv.FormatBool(common.RegisterEnabled)
common.OptionMap["AutomaticDisableChannelEnabled"] = strconv.FormatBool(common.AutomaticDisableChannelEnabled)
common.OptionMap["AutomaticEnableChannelEnabled"] = strconv.FormatBool(common.AutomaticEnableChannelEnabled)
Expand Down Expand Up @@ -296,6 +297,8 @@ func updateOptionMap(key string, value string) (err error) {
common.TelegramOAuthEnabled = boolValue
case "TurnstileCheckEnabled":
common.TurnstileCheckEnabled = boolValue
case "RegisterPageWithCaptchaEnabled":
common.RegisterPageWithCaptchaEnabled = boolValue
case "RegisterEnabled":
common.RegisterEnabled = boolValue
case "EmailDomainRestrictionEnabled":
Expand Down
11 changes: 11 additions & 0 deletions web/classic/src/components/settings/SystemSetting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const SystemSetting = () => {
WeChatServerToken: '',
WeChatAccountQRCodeImageURL: '',
TurnstileCheckEnabled: '',
RegisterPageWithCaptchaEnabled: '',
TurnstileSiteKey: '',
TurnstileSecretKey: '',
RegisterEnabled: '',
Expand Down Expand Up @@ -181,6 +182,7 @@ const SystemSetting = () => {
case 'TelegramOAuthEnabled':
case 'RegisterEnabled':
case 'TurnstileCheckEnabled':
case 'RegisterPageWithCaptchaEnabled':
case 'EmailDomainRestrictionEnabled':
case 'EmailAliasRestrictionEnabled':
case 'SMTPSSLEnabled':
Expand Down Expand Up @@ -1070,6 +1072,15 @@ const SystemSetting = () => {
>
{t('允许 Turnstile 用户校验')}
</Form.Checkbox>
<Form.Checkbox
field='RegisterPageWithCaptchaEnabled'
noLabel
onChange={(e) =>
handleCheckboxChange('RegisterPageWithCaptchaEnabled', e)
}
>
{t('注册及发送邮箱验证码时需要 Turnstile 校验')}
</Form.Checkbox>
</Col>
<Col xs={24} sm={24} md={12} lg={12} xl={12}>
<Form.Checkbox
Expand Down
1 change: 1 addition & 0 deletions web/classic/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@
"允许 speed 透传": "Allow speed Pass-through",
"允许 stream_options.include_obfuscation 透传": "Allow stream_options.include_obfuscation Pass-through",
"允许 Turnstile 用户校验": "Allow Turnstile user verification",
"注册及发送邮箱验证码时需要 Turnstile 校验": "Require Turnstile verification for registration and sending email verification codes",
"允许不安全的 Origin(HTTP)": "Allow insecure Origin (HTTP)",
"允许回调(会泄露服务器 IP 地址)": "Allow callback (will leak server IP address)",
"允许在 Stripe 支付中输入促销码": "Allow entering promotion codes during Stripe checkout",
Expand Down
1 change: 1 addition & 0 deletions web/classic/src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@
"允许 speed 透传": "Autoriser la transmission de speed",
"允许 stream_options.include_obfuscation 透传": "Autoriser la transmission de stream_options.include_obfuscation",
"允许 Turnstile 用户校验": "Autoriser la vérification des utilisateurs Turnstile",
"注册及发送邮箱验证码时需要 Turnstile 校验": "Exiger la vérification Turnstile pour l'inscription et l'envoi de codes de vérification par e-mail",
"允许不安全的 Origin(HTTP)": "Autoriser une origine non sécurisée (HTTP)",
"允许回调(会泄露服务器 IP 地址)": "Autoriser le rappel (divulguera l'adresse IP du serveur)",
"允许在 Stripe 支付中输入促销码": "Autoriser la saisie de codes promotionnels lors du paiement Stripe",
Expand Down
1 change: 1 addition & 0 deletions web/classic/src/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@
"允许 speed 透传": "speed パススルーを許可",
"允许 stream_options.include_obfuscation 透传": "stream_options.include_obfuscationパススルーを許可",
"允许 Turnstile 用户校验": "Turnstileによるユーザー検証を許可する",
"注册及发送邮箱验证码时需要 Turnstile 校验": "ユーザー登録およびメール検証コード送信時に Turnstile 検証を必須にします",
"允许不安全的 Origin(HTTP)": "安全でないオリジン(HTTP)を許可する",
"允许回调(会泄露服务器 IP 地址)": "コールバックを許可する(サーバーIPアドレスが漏洩します)",
"允许在 Stripe 支付中输入促销码": "Stripe決済でのプロモーションコード入力を許可する",
Expand Down
1 change: 1 addition & 0 deletions web/classic/src/i18n/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@
"允许 speed 透传": "Разрешить передачу speed",
"允许 stream_options.include_obfuscation 透传": "Разрешить передачу stream_options.include_obfuscation",
"允许 Turnstile 用户校验": "Разрешить проверку пользователей Turnstile",
"注册及发送邮箱验证码时需要 Turnstile 校验": "Требовать проверку Turnstile при регистрации и отправке кода подтверждения",
"允许不安全的 Origin(HTTP)": "Разрешить небезопасные Origin (HTTP)",
"允许回调(会泄露服务器 IP 地址)": "Разрешить обратные вызовы (может раскрыть IP-адрес сервера)",
"允许在 Stripe 支付中输入促销码": "Разрешить ввод промокодов при оплате через Stripe",
Expand Down
1 change: 1 addition & 0 deletions web/classic/src/i18n/locales/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@
"允许 speed 透传": "Cho phép truyền speed",
"允许 stream_options.include_obfuscation 透传": "Cho phép truyền stream_options.include_obfuscation",
"允许 Turnstile 用户校验": "Cho phép xác minh người dùng Turnstile",
"注册及发送邮箱验证码时需要 Turnstile 校验": "Yêu cầu xác minh Turnstile khi đăng ký và gửi mã xác minh email",
"允许不安全的 Origin(HTTP)": "Cho phép Origin không an toàn (HTTP)",
"允许回调(会泄露服务器 IP 地址)": "Cho phép gọi lại (sẽ làm lộ địa chỉ IP máy chủ)",
"允许在 Stripe 支付中输入促销码": "Cho phép nhập mã khuyến mãi khi thanh toán Stripe",
Expand Down
1 change: 1 addition & 0 deletions web/classic/src/i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@
"允许 speed 透传": "允许 speed 透传",
"允许 stream_options.include_obfuscation 透传": "允许 stream_options.include_obfuscation 透传",
"允许 Turnstile 用户校验": "允许 Turnstile 用户校验",
"注册及发送邮箱验证码时需要 Turnstile 校验": "注册及发送邮箱验证码时需要 Turnstile 校验",
"允许不安全的 Origin(HTTP)": "允许不安全的 Origin(HTTP)",
"允许回调(会泄露服务器 IP 地址)": "允许回调(会泄露服务器 IP 地址)",
"允许在 Stripe 支付中输入促销码": "允许在 Stripe 支付中输入促销码",
Expand Down
1 change: 1 addition & 0 deletions web/classic/src/i18n/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@
"允许 speed 透传": "允許 speed 透傳",
"允许 stream_options.include_obfuscation 透传": "",
"允许 Turnstile 用户校验": "允許 Turnstile 使用者校驗",
"注册及发送邮箱验证码时需要 Turnstile 校验": "註冊及發送電子郵件驗證碼時需要 Turnstile 校驗",
"允许不安全的 Origin(HTTP)": "允許不安全的 Origin(HTTP)",
"允许回调(会泄露服务器 IP 地址)": "允許回調(會洩露伺服器 IP 位址)",
"允许在 Stripe 支付中输入促销码": "允許在 Stripe 支付中輸入促銷碼",
Expand Down
1 change: 1 addition & 0 deletions web/classic/src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
"允许 safety_identifier 透传": "允许 safety_identifier 透传",
"允许 service_tier 透传": "允许 service_tier 透传",
"允许 Turnstile 用户校验": "允许 Turnstile 用户校验",
"注册及发送邮箱验证码时需要 Turnstile 校验": "注册及发送邮箱验证码时需要 Turnstile 校验",
"允许不安全的 Origin(HTTP)": "允许不安全的 Origin(HTTP)",
"允许回调(会泄露服务器 IP 地址)": "允许回调(会泄露服务器 IP 地址)",
"允许在 Stripe 支付中输入促销码": "允许在 Stripe 支付中输入促销码",
Expand Down
8 changes: 4 additions & 4 deletions web/default/src/features/auth/hooks/use-turnstile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import { useStatus } from '@/hooks/use-status'
/**
* Hook for managing Turnstile verification
*/
export function useTurnstile() {
export function useTurnstile(options?: { forceEnable?: boolean }) {
const { status } = useStatus()
const [turnstileToken, setTurnstileToken] = useState('')

const isTurnstileEnabled = !!(
status?.turnstile_check && status?.turnstile_site_key
)
const isTurnstileEnabled =
options?.forceEnable ||
!!(status?.turnstile_check && status?.turnstile_site_key)
const turnstileSiteKey = status?.turnstile_site_key || ''

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,19 @@ export function SignUpForm({
const legalConsentErrorMessage = t('Please agree to the legal terms first')

const { status } = useStatus()
const signupTurnstileRequired = useMemo(() => {
return !!(
(status?.turnstile_check || status?.register_page_with_captcha) &&
status?.turnstile_site_key
)
}, [status])
const {
isTurnstileEnabled,
turnstileSiteKey,
turnstileToken,
setTurnstileToken,
validateTurnstile,
} = useTurnstile()
} = useTurnstile({ forceEnable: signupTurnstileRequired })
const { redirectToLogin, handleLoginSuccess } = useAuthRedirect()
const {
isSending: isSendingCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { useUpdateOption } from '../hooks/use-update-option'

const botProtectionSchema = z.object({
TurnstileCheckEnabled: z.boolean(),
RegisterPageWithCaptchaEnabled: z.boolean(),
TurnstileSiteKey: z.string().optional(),
TurnstileSecretKey: z.string().optional(),
})
Expand Down Expand Up @@ -112,6 +113,29 @@ export function BotProtectionSection({
)}
/>

<FormField
control={form.control}
name='RegisterPageWithCaptchaEnabled'
render={({ field }) => (
<SettingsSwitchItem>
<SettingsSwitchContent>
<FormLabel>{t('Require CAPTCHA for Registration')}</FormLabel>
<FormDescription>
{t(
'Require Cloudflare Turnstile verification specifically for registration and sending email verification codes'
)}
</FormDescription>
</SettingsSwitchContent>
<FormControl>
<Switch
checked={field.value}
onCheckedChange={field.onChange}
/>
</FormControl>
</SettingsSwitchItem>
)}
/>

<FormField
control={form.control}
name='TurnstileSiteKey'
Expand Down
1 change: 1 addition & 0 deletions web/default/src/features/system-settings/auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const defaultAuthSettings: AuthSettings = {
WeChatServerToken: '',
WeChatAccountQRCodeImageURL: '',
TurnstileCheckEnabled: false,
RegisterPageWithCaptchaEnabled: false,
TurnstileSiteKey: '',
TurnstileSecretKey: '',
'passkey.enabled': false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const AUTH_SECTIONS = [
<BotProtectionSection
defaultValues={{
TurnstileCheckEnabled: settings.TurnstileCheckEnabled,
RegisterPageWithCaptchaEnabled: settings.RegisterPageWithCaptchaEnabled,
TurnstileSiteKey: settings.TurnstileSiteKey,
TurnstileSecretKey: settings.TurnstileSecretKey,
}}
Expand Down
1 change: 1 addition & 0 deletions web/default/src/features/system-settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export type AuthSettings = {
WeChatServerToken: string
WeChatAccountQRCodeImageURL: string
TurnstileCheckEnabled: boolean
RegisterPageWithCaptchaEnabled: boolean
TurnstileSiteKey: string
TurnstileSecretKey: string
'passkey.enabled': boolean
Expand Down
2 changes: 2 additions & 0 deletions web/default/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3634,6 +3634,8 @@
"requests served": "requests served",
"Requests will be forwarded to this worker. Trailing slashes are removed automatically.": "Requests will be forwarded to this worker. Trailing slashes are removed automatically.",
"Requests:": "Requests:",
"Require CAPTCHA for Registration": "Require CAPTCHA for Registration",
"Require Cloudflare Turnstile verification specifically for registration and sending email verification codes": "Require Cloudflare Turnstile verification specifically for registration and sending email verification codes",
"Require email verification for new accounts": "Require email verification for new accounts",
"Require job success before follow-up actions": "Require job success before follow-up actions",
"Require login to view models": "Require login to view models",
Expand Down
2 changes: 2 additions & 0 deletions web/default/src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3634,6 +3634,8 @@
"requests served": "requêtes traitées",
"Requests will be forwarded to this worker. Trailing slashes are removed automatically.": "Les requêtes seront transmises à ce worker. Les barres obliques finales sont automatiquement supprimées.",
"Requests:": "Requêtes :",
"Require CAPTCHA for Registration": "Exiger un CAPTCHA pour l'inscription",
"Require Cloudflare Turnstile verification specifically for registration and sending email verification codes": "Exiger la vérification Cloudflare Turnstile spécifiquement pour l'inscription et l'envoi de codes de vérification par e-mail",
"Require email verification for new accounts": "Exiger la vérification de l'e-mail pour les nouveaux comptes",
"Require job success before follow-up actions": "Exiger le succès de la tâche avant les actions de suivi",
"Require login to view models": "Exiger la connexion pour voir les modèles",
Expand Down
2 changes: 2 additions & 0 deletions web/default/src/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -3634,6 +3634,8 @@
"requests served": "処理されたリクエスト",
"Requests will be forwarded to this worker. Trailing slashes are removed automatically.": "リクエストはこのワーカーに転送されます。末尾のスラッシュは自動的に削除されます。",
"Requests:": "リクエスト:",
"Require CAPTCHA for Registration": "新規登録時にCAPTCHAを必須にする",
"Require Cloudflare Turnstile verification specifically for registration and sending email verification codes": "ユーザー登録およびメール検証コード送信時に Cloudflare Turnstile 検証を必须にします",
"Require email verification for new accounts": "新しいアカウントにメール認証を要求する",
"Require job success before follow-up actions": "フォローアップ アクション前にジョブの成功を要求",
"Require login to view models": "モデルを表示するにはログインを要求する",
Expand Down
2 changes: 2 additions & 0 deletions web/default/src/i18n/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -3634,6 +3634,8 @@
"requests served": "обслуженных запросов",
"Requests will be forwarded to this worker. Trailing slashes are removed automatically.": "Запросы будут перенаправлены этому воркеру. Конечные слеши удаляются автоматически.",
"Requests:": "Запросы:",
"Require CAPTCHA for Registration": "Требовать CAPTCHA при регистрации",
"Require Cloudflare Turnstile verification specifically for registration and sending email verification codes": "Требовать проверку Cloudflare Turnstile специально для регистрации и отправки кодов подтверждения по электронной почте",
"Require email verification for new accounts": "Требовать подтверждение электронной почты для новых учетных записей",
"Require job success before follow-up actions": "Требовать успеха задания перед последующими действиями",
"Require login to view models": "Требовать вход для просмотра моделей",
Expand Down
2 changes: 2 additions & 0 deletions web/default/src/i18n/locales/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3634,6 +3634,8 @@
"requests served": "yêu cầu đã phục vụ",
"Requests will be forwarded to this worker. Trailing slashes are removed automatically.": "Các yêu cầu sẽ được chuyển tiếp đến worker này. Dấu gạch chéo ở cuối được tự động loại bỏ.",
"Requests:": "Yêu cầu:",
"Require CAPTCHA for Registration": "Yêu cầu CAPTCHA khi đăng ký",
"Require Cloudflare Turnstile verification specifically for registration and sending email verification codes": "Yêu cầu xác minh Cloudflare Turnstile cụ thể cho việc đăng ký và gửi mã xác minh email",
"Require email verification for new accounts": "Yêu cầu xác minh email cho tài khoản mới",
"Require job success before follow-up actions": "Yêu cầu công việc thành công trước các hành động tiếp theo",
"Require login to view models": "Yêu cầu đăng nhập để xem các mô hình",
Expand Down
2 changes: 2 additions & 0 deletions web/default/src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -3634,6 +3634,8 @@
"requests served": "服务请求数",
"Requests will be forwarded to this worker. Trailing slashes are removed automatically.": "请求将被转发到此 Worker。末尾的斜杠会自动移除。",
"Requests:": "请求:",
"Require CAPTCHA for Registration": "注册时启用人机验证",
"Require Cloudflare Turnstile verification specifically for registration and sending email verification codes": "仅在注册和发送邮箱验证码时要求进行 Cloudflare Turnstile 验证",
"Require email verification for new accounts": "要求新账户验证邮箱",
"Require job success before follow-up actions": "在后续操作前要求任务成功",
"Require login to view models": "要求登录才能查看模型",
Expand Down