-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
[WIP] Added Captcha settings for self-hosters #22757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,9 @@ | ||||||||||
| import React from 'react'; | ||||||||||
| import TopLevelGroup from '../../TopLevelGroup'; | ||||||||||
| import useSettingGroup from '../../../hooks/useSettingGroup'; | ||||||||||
| import {Separator, SettingGroupContent, TextArea, Toggle, withErrorBoundary} from '@tryghost/admin-x-design-system'; | ||||||||||
| import {Separator, SettingGroupContent, TextArea, TextField, Toggle, withErrorBoundary} from '@tryghost/admin-x-design-system'; | ||||||||||
| import {getSettingValue, getSettingValues} from '@tryghost/admin-x-framework/api/settings'; | ||||||||||
| import {useGlobalData} from '../../providers/GlobalDataProvider'; | ||||||||||
|
|
||||||||||
| const SpamFilters: React.FC<{ keywords: string[] }> = ({keywords}) => { | ||||||||||
| const { | ||||||||||
|
|
@@ -21,16 +22,29 @@ const SpamFilters: React.FC<{ keywords: string[] }> = ({keywords}) => { | |||||||||
| } | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| const {config} = useGlobalData(); | ||||||||||
|
|
||||||||||
| const [initialBlockedEmailDomainsJSON] = getSettingValues(localSettings, ['blocked_email_domains']) as string[]; | ||||||||||
| const initialBlockedEmailDomains = JSON.parse(initialBlockedEmailDomainsJSON || '[]') as string[]; | ||||||||||
| const [blockedEmailDomains, setBlockedEmailDomains] = React.useState(initialBlockedEmailDomains.join('\n')); | ||||||||||
|
|
||||||||||
| const [captchaEnabled] = getSettingValues(localSettings, ['captcha_enabled']) as boolean[]; | ||||||||||
| const [captchaSitekey, captchaSecret] = getSettingValues(localSettings, ['captcha_sitekey', 'captcha_secret']) as string[]; | ||||||||||
| const handleToggleChange = (key: string, e: React.ChangeEvent<HTMLInputElement>) => { | ||||||||||
| updateSetting(key, e.target.checked); | ||||||||||
| handleEditingChange(true); | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const handleSitekeyChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||||||||||
| updateSetting('captcha_sitekey', e.target.value); | ||||||||||
| handleEditingChange(true); | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const handleSecretChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||||||||||
| updateSetting('captcha_secret', e.target.value); | ||||||||||
| handleEditingChange(true); | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const labs = JSON.parse(getSettingValue<string>(localSettings, 'labs') || '{}'); | ||||||||||
|
|
||||||||||
| const updateBlockedEmailDomainsSetting = (e: React.ChangeEvent<HTMLTextAreaElement>) => { | ||||||||||
|
|
@@ -95,11 +109,31 @@ const SpamFilters: React.FC<{ keywords: string[] }> = ({keywords}) => { | |||||||||
| gap='gap-0' | ||||||||||
| hint={captchaHint} | ||||||||||
| label='Enable strict signup security' | ||||||||||
| labelClasses='block text-sm font-medium tracking-normal text-grey-900 w-full mt-[-10px]' | ||||||||||
| labelClasses='block text-sm font-medium tracking-normal text-grey-900 dark:text-grey-500 w-full mt-[-10px]' | ||||||||||
| onChange={(e) => { | ||||||||||
| handleToggleChange('captcha_enabled', e); | ||||||||||
| }} | ||||||||||
| /> | ||||||||||
| {/* Sitekey / secret are only modifiable in self-hoster setups */} | ||||||||||
| {config?.hostSettings?.captcha || (<> | ||||||||||
| <SettingGroupContent> | ||||||||||
| <TextField | ||||||||||
| hint="TODO Change: Unique identifier for your site" | ||||||||||
| maxLength={36} // UUIDv4 format | ||||||||||
| placeholder="hCaptcha sitekey" | ||||||||||
| title="hCaptcha sitekey" | ||||||||||
| value={captchaSitekey} | ||||||||||
| onChange={handleSitekeyChange} | ||||||||||
| /> | ||||||||||
| <TextField | ||||||||||
| hint="TODO Change:Private secret key used to verify hCaptcha responses" | ||||||||||
| maxLength={100} | ||||||||||
|
Comment on lines
+129
to
+130
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typo in hint text and update the placeholder There's a missing space after the colon in "TODO Change:Private", and the hint text needs to be updated. Consider providing clear instructions on how to obtain the secret key from hCaptcha. - hint="TODO Change:Private secret key used to verify hCaptcha responses"
+ hint="TODO Change: Private secret key used to verify hCaptcha responses"📝 Committable suggestion
Suggested change
|
||||||||||
| placeholder="hCaptcha secret" | ||||||||||
| title="hCaptcha secret" | ||||||||||
| value={captchaSecret} | ||||||||||
| onChange={handleSecretChange} /> | ||||||||||
| </SettingGroupContent> | ||||||||||
| </>)} | ||||||||||
| </>)} | ||||||||||
| </SettingGroupContent> | ||||||||||
| </TopLevelGroup> | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| const {addSetting, combineTransactionalMigrations} = require('../../utils'); | ||
|
|
||
| module.exports = combineTransactionalMigrations([ | ||
| addSetting({ | ||
| key: 'captcha_sitekey', | ||
| value: null, | ||
| type: 'string', | ||
| group: 'members' | ||
| }), | ||
| addSetting({ | ||
| key: 'captcha_secret', | ||
| value: null, | ||
| type: 'string', | ||
| group: 'members' | ||
| }) | ||
| ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update placeholder TODO hint text
The "TODO Change" in the hint text indicates that the copy needs to be updated before the PR is finalized. Consider providing a more descriptive hint that explains what a site key is and how to obtain it from hCaptcha.