SystemSetting.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. import React, { useEffect, useState, useRef } from 'react';
  2. import {
  3. Button,
  4. Form,
  5. Row,
  6. Col,
  7. Typography,
  8. Modal,
  9. Banner,
  10. TagInput,
  11. Spin,
  12. Card,
  13. } from '@douyinfe/semi-ui';
  14. const { Text } = Typography;
  15. import {
  16. removeTrailingSlash,
  17. showError,
  18. showSuccess,
  19. verifyJSON,
  20. } from '../helpers/utils';
  21. import { API } from '../helpers/api';
  22. const SystemSetting = () => {
  23. let [inputs, setInputs] = useState({
  24. PasswordLoginEnabled: '',
  25. PasswordRegisterEnabled: '',
  26. EmailVerificationEnabled: '',
  27. GitHubOAuthEnabled: '',
  28. GitHubClientId: '',
  29. GitHubClientSecret: '',
  30. 'oidc.enabled': '',
  31. 'oidc.client_id': '',
  32. 'oidc.client_secret': '',
  33. 'oidc.well_known': '',
  34. 'oidc.authorization_endpoint': '',
  35. 'oidc.token_endpoint': '',
  36. 'oidc.user_info_endpoint': '',
  37. Notice: '',
  38. SMTPServer: '',
  39. SMTPPort: '',
  40. SMTPAccount: '',
  41. SMTPFrom: '',
  42. SMTPToken: '',
  43. ServerAddress: '',
  44. WorkerUrl: '',
  45. WorkerValidKey: '',
  46. EpayId: '',
  47. EpayKey: '',
  48. Price: 7.3,
  49. MinTopUp: 1,
  50. TopupGroupRatio: '',
  51. PayAddress: '',
  52. CustomCallbackAddress: '',
  53. Footer: '',
  54. WeChatAuthEnabled: '',
  55. WeChatServerAddress: '',
  56. WeChatServerToken: '',
  57. WeChatAccountQRCodeImageURL: '',
  58. TurnstileCheckEnabled: '',
  59. TurnstileSiteKey: '',
  60. TurnstileSecretKey: '',
  61. RegisterEnabled: '',
  62. EmailDomainRestrictionEnabled: '',
  63. EmailAliasRestrictionEnabled: '',
  64. SMTPSSLEnabled: '',
  65. EmailDomainWhitelist: [],
  66. // telegram login
  67. TelegramOAuthEnabled: '',
  68. TelegramBotToken: '',
  69. TelegramBotName: '',
  70. LinuxDOOAuthEnabled: '',
  71. LinuxDOClientId: '',
  72. LinuxDOClientSecret: '',
  73. });
  74. const [originInputs, setOriginInputs] = useState({});
  75. const [loading, setLoading] = useState(false);
  76. const [isLoaded, setIsLoaded] = useState(false);
  77. const formApiRef = useRef(null);
  78. const [emailDomainWhitelist, setEmailDomainWhitelist] = useState([]);
  79. const [showPasswordLoginConfirmModal, setShowPasswordLoginConfirmModal] =
  80. useState(false);
  81. const [linuxDOOAuthEnabled, setLinuxDOOAuthEnabled] = useState(false);
  82. const [emailToAdd, setEmailToAdd] = useState('');
  83. const getOptions = async () => {
  84. setLoading(true);
  85. const res = await API.get('/api/option/');
  86. const { success, message, data } = res.data;
  87. if (success) {
  88. let newInputs = {};
  89. data.forEach((item) => {
  90. switch (item.key) {
  91. case 'TopupGroupRatio':
  92. item.value = JSON.stringify(JSON.parse(item.value), null, 2);
  93. break;
  94. case 'EmailDomainWhitelist':
  95. setEmailDomainWhitelist(item.value ? item.value.split(',') : []);
  96. break;
  97. case 'PasswordLoginEnabled':
  98. case 'PasswordRegisterEnabled':
  99. case 'EmailVerificationEnabled':
  100. case 'GitHubOAuthEnabled':
  101. case 'WeChatAuthEnabled':
  102. case 'TelegramOAuthEnabled':
  103. case 'RegisterEnabled':
  104. case 'TurnstileCheckEnabled':
  105. case 'EmailDomainRestrictionEnabled':
  106. case 'EmailAliasRestrictionEnabled':
  107. case 'SMTPSSLEnabled':
  108. case 'LinuxDOOAuthEnabled':
  109. case 'oidc.enabled':
  110. item.value = item.value === 'true';
  111. break;
  112. case 'Price':
  113. case 'MinTopUp':
  114. item.value = parseFloat(item.value);
  115. break;
  116. default:
  117. break;
  118. }
  119. newInputs[item.key] = item.value;
  120. });
  121. setInputs(newInputs);
  122. setOriginInputs(newInputs);
  123. if (formApiRef.current) {
  124. formApiRef.current.setValues(newInputs);
  125. }
  126. setIsLoaded(true);
  127. } else {
  128. showError(message);
  129. }
  130. setLoading(false);
  131. };
  132. useEffect(() => {
  133. getOptions();
  134. }, []);
  135. const updateOptions = async (options) => {
  136. setLoading(true);
  137. try {
  138. // 分离 checkbox 类型的选项和其他选项
  139. const checkboxOptions = options.filter((opt) =>
  140. opt.key.toLowerCase().endsWith('enabled'),
  141. );
  142. const otherOptions = options.filter(
  143. (opt) => !opt.key.toLowerCase().endsWith('enabled'),
  144. );
  145. // 处理 checkbox 类型的选项
  146. for (const opt of checkboxOptions) {
  147. const res = await API.put('/api/option/', {
  148. key: opt.key,
  149. value: opt.value.toString(),
  150. });
  151. if (!res.data.success) {
  152. showError(res.data.message);
  153. return;
  154. }
  155. }
  156. // 处理其他选项
  157. if (otherOptions.length > 0) {
  158. const requestQueue = otherOptions.map((opt) =>
  159. API.put('/api/option/', {
  160. key: opt.key,
  161. value:
  162. typeof opt.value === 'boolean' ? opt.value.toString() : opt.value,
  163. }),
  164. );
  165. const results = await Promise.all(requestQueue);
  166. // 检查所有请求是否成功
  167. const errorResults = results.filter((res) => !res.data.success);
  168. errorResults.forEach((res) => {
  169. showError(res.data.message);
  170. });
  171. }
  172. showSuccess('更新成功');
  173. // 更新本地状态
  174. const newInputs = { ...inputs };
  175. options.forEach((opt) => {
  176. newInputs[opt.key] = opt.value;
  177. });
  178. setInputs(newInputs);
  179. } catch (error) {
  180. showError('更新失败');
  181. }
  182. setLoading(false);
  183. };
  184. const handleFormChange = (values) => {
  185. setInputs(values);
  186. };
  187. const submitServerAddress = async () => {
  188. let ServerAddress = removeTrailingSlash(inputs.ServerAddress);
  189. await updateOptions([{ key: 'ServerAddress', value: ServerAddress }]);
  190. };
  191. const submitWorker = async () => {
  192. let WorkerUrl = removeTrailingSlash(inputs.WorkerUrl);
  193. await updateOptions([
  194. { key: 'WorkerUrl', value: WorkerUrl },
  195. { key: 'WorkerValidKey', value: inputs.WorkerValidKey },
  196. ]);
  197. };
  198. const submitPayAddress = async () => {
  199. if (inputs.ServerAddress === '') {
  200. showError('请先填写服务器地址');
  201. return;
  202. }
  203. if (originInputs['TopupGroupRatio'] !== inputs.TopupGroupRatio) {
  204. if (!verifyJSON(inputs.TopupGroupRatio)) {
  205. showError('充值分组倍率不是合法的 JSON 字符串');
  206. return;
  207. }
  208. }
  209. const options = [
  210. { key: 'PayAddress', value: removeTrailingSlash(inputs.PayAddress) },
  211. ];
  212. if (inputs.EpayId !== '') {
  213. options.push({ key: 'EpayId', value: inputs.EpayId });
  214. }
  215. if (inputs.EpayKey !== undefined && inputs.EpayKey !== '') {
  216. options.push({ key: 'EpayKey', value: inputs.EpayKey });
  217. }
  218. if (inputs.Price !== '') {
  219. options.push({ key: 'Price', value: inputs.Price.toString() });
  220. }
  221. if (inputs.MinTopUp !== '') {
  222. options.push({ key: 'MinTopUp', value: inputs.MinTopUp.toString() });
  223. }
  224. if (inputs.CustomCallbackAddress !== '') {
  225. options.push({
  226. key: 'CustomCallbackAddress',
  227. value: inputs.CustomCallbackAddress,
  228. });
  229. }
  230. if (originInputs['TopupGroupRatio'] !== inputs.TopupGroupRatio) {
  231. options.push({ key: 'TopupGroupRatio', value: inputs.TopupGroupRatio });
  232. }
  233. await updateOptions(options);
  234. };
  235. const submitSMTP = async () => {
  236. const options = [];
  237. if (originInputs['SMTPServer'] !== inputs.SMTPServer) {
  238. options.push({ key: 'SMTPServer', value: inputs.SMTPServer });
  239. }
  240. if (originInputs['SMTPAccount'] !== inputs.SMTPAccount) {
  241. options.push({ key: 'SMTPAccount', value: inputs.SMTPAccount });
  242. }
  243. if (originInputs['SMTPFrom'] !== inputs.SMTPFrom) {
  244. options.push({ key: 'SMTPFrom', value: inputs.SMTPFrom });
  245. }
  246. if (
  247. originInputs['SMTPPort'] !== inputs.SMTPPort &&
  248. inputs.SMTPPort !== ''
  249. ) {
  250. options.push({ key: 'SMTPPort', value: inputs.SMTPPort });
  251. }
  252. if (
  253. originInputs['SMTPToken'] !== inputs.SMTPToken &&
  254. inputs.SMTPToken !== ''
  255. ) {
  256. options.push({ key: 'SMTPToken', value: inputs.SMTPToken });
  257. }
  258. if (options.length > 0) {
  259. await updateOptions(options);
  260. }
  261. };
  262. const submitEmailDomainWhitelist = async () => {
  263. if (Array.isArray(emailDomainWhitelist)) {
  264. await updateOptions([
  265. {
  266. key: 'EmailDomainWhitelist',
  267. value: emailDomainWhitelist.join(','),
  268. },
  269. ]);
  270. } else {
  271. showError('邮箱域名白名单格式不正确');
  272. }
  273. };
  274. const handleAddEmail = () => {
  275. if (emailToAdd && emailToAdd.trim() !== '') {
  276. const domain = emailToAdd.trim();
  277. // 验证域名格式
  278. const domainRegex = /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
  279. if (!domainRegex.test(domain)) {
  280. showError('邮箱域名格式不正确,请输入有效的域名,如 gmail.com');
  281. return;
  282. }
  283. // 检查是否已存在
  284. if (emailDomainWhitelist.includes(domain)) {
  285. showError('该域名已存在于白名单中');
  286. return;
  287. }
  288. setEmailDomainWhitelist([...emailDomainWhitelist, domain]);
  289. setEmailToAdd('');
  290. showSuccess('已添加到白名单');
  291. }
  292. };
  293. const submitWeChat = async () => {
  294. const options = [];
  295. if (originInputs['WeChatServerAddress'] !== inputs.WeChatServerAddress) {
  296. options.push({
  297. key: 'WeChatServerAddress',
  298. value: removeTrailingSlash(inputs.WeChatServerAddress),
  299. });
  300. }
  301. if (
  302. originInputs['WeChatAccountQRCodeImageURL'] !==
  303. inputs.WeChatAccountQRCodeImageURL
  304. ) {
  305. options.push({
  306. key: 'WeChatAccountQRCodeImageURL',
  307. value: inputs.WeChatAccountQRCodeImageURL,
  308. });
  309. }
  310. if (
  311. originInputs['WeChatServerToken'] !== inputs.WeChatServerToken &&
  312. inputs.WeChatServerToken !== ''
  313. ) {
  314. options.push({
  315. key: 'WeChatServerToken',
  316. value: inputs.WeChatServerToken,
  317. });
  318. }
  319. if (options.length > 0) {
  320. await updateOptions(options);
  321. }
  322. };
  323. const submitGitHubOAuth = async () => {
  324. const options = [];
  325. if (originInputs['GitHubClientId'] !== inputs.GitHubClientId) {
  326. options.push({ key: 'GitHubClientId', value: inputs.GitHubClientId });
  327. }
  328. if (
  329. originInputs['GitHubClientSecret'] !== inputs.GitHubClientSecret &&
  330. inputs.GitHubClientSecret !== ''
  331. ) {
  332. options.push({
  333. key: 'GitHubClientSecret',
  334. value: inputs.GitHubClientSecret,
  335. });
  336. }
  337. if (options.length > 0) {
  338. await updateOptions(options);
  339. }
  340. };
  341. const submitOIDCSettings = async () => {
  342. if (inputs['oidc.well_known'] !== '') {
  343. if (
  344. !inputs['oidc.well_known'].startsWith('http://') &&
  345. !inputs['oidc.well_known'].startsWith('https://')
  346. ) {
  347. showError('Well-Known URL 必须以 http:// 或 https:// 开头');
  348. return;
  349. }
  350. try {
  351. const res = await API.get(inputs['oidc.well_known']);
  352. inputs['oidc.authorization_endpoint'] =
  353. res.data['authorization_endpoint'];
  354. inputs['oidc.token_endpoint'] = res.data['token_endpoint'];
  355. inputs['oidc.user_info_endpoint'] = res.data['userinfo_endpoint'];
  356. showSuccess('获取 OIDC 配置成功!');
  357. } catch (err) {
  358. console.error(err);
  359. showError(
  360. '获取 OIDC 配置失败,请检查网络状况和 Well-Known URL 是否正确',
  361. );
  362. return;
  363. }
  364. }
  365. const options = [];
  366. if (originInputs['oidc.well_known'] !== inputs['oidc.well_known']) {
  367. options.push({
  368. key: 'oidc.well_known',
  369. value: inputs['oidc.well_known'],
  370. });
  371. }
  372. if (originInputs['oidc.client_id'] !== inputs['oidc.client_id']) {
  373. options.push({ key: 'oidc.client_id', value: inputs['oidc.client_id'] });
  374. }
  375. if (
  376. originInputs['oidc.client_secret'] !== inputs['oidc.client_secret'] &&
  377. inputs['oidc.client_secret'] !== ''
  378. ) {
  379. options.push({
  380. key: 'oidc.client_secret',
  381. value: inputs['oidc.client_secret'],
  382. });
  383. }
  384. if (
  385. originInputs['oidc.authorization_endpoint'] !==
  386. inputs['oidc.authorization_endpoint']
  387. ) {
  388. options.push({
  389. key: 'oidc.authorization_endpoint',
  390. value: inputs['oidc.authorization_endpoint'],
  391. });
  392. }
  393. if (originInputs['oidc.token_endpoint'] !== inputs['oidc.token_endpoint']) {
  394. options.push({
  395. key: 'oidc.token_endpoint',
  396. value: inputs['oidc.token_endpoint'],
  397. });
  398. }
  399. if (
  400. originInputs['oidc.user_info_endpoint'] !==
  401. inputs['oidc.user_info_endpoint']
  402. ) {
  403. options.push({
  404. key: 'oidc.user_info_endpoint',
  405. value: inputs['oidc.user_info_endpoint'],
  406. });
  407. }
  408. if (options.length > 0) {
  409. await updateOptions(options);
  410. }
  411. };
  412. const submitTelegramSettings = async () => {
  413. const options = [
  414. { key: 'TelegramBotToken', value: inputs.TelegramBotToken },
  415. { key: 'TelegramBotName', value: inputs.TelegramBotName },
  416. ];
  417. await updateOptions(options);
  418. };
  419. const submitTurnstile = async () => {
  420. const options = [];
  421. if (originInputs['TurnstileSiteKey'] !== inputs.TurnstileSiteKey) {
  422. options.push({ key: 'TurnstileSiteKey', value: inputs.TurnstileSiteKey });
  423. }
  424. if (
  425. originInputs['TurnstileSecretKey'] !== inputs.TurnstileSecretKey &&
  426. inputs.TurnstileSecretKey !== ''
  427. ) {
  428. options.push({
  429. key: 'TurnstileSecretKey',
  430. value: inputs.TurnstileSecretKey,
  431. });
  432. }
  433. if (options.length > 0) {
  434. await updateOptions(options);
  435. }
  436. };
  437. const submitLinuxDOOAuth = async () => {
  438. const options = [];
  439. if (originInputs['LinuxDOClientId'] !== inputs.LinuxDOClientId) {
  440. options.push({ key: 'LinuxDOClientId', value: inputs.LinuxDOClientId });
  441. }
  442. if (
  443. originInputs['LinuxDOClientSecret'] !== inputs.LinuxDOClientSecret &&
  444. inputs.LinuxDOClientSecret !== ''
  445. ) {
  446. options.push({
  447. key: 'LinuxDOClientSecret',
  448. value: inputs.LinuxDOClientSecret,
  449. });
  450. }
  451. if (options.length > 0) {
  452. await updateOptions(options);
  453. }
  454. };
  455. const handleCheckboxChange = async (optionKey, event) => {
  456. const value = event.target.checked;
  457. if (optionKey === 'PasswordLoginEnabled' && !value) {
  458. setShowPasswordLoginConfirmModal(true);
  459. } else {
  460. await updateOptions([{ key: optionKey, value }]);
  461. }
  462. if (optionKey === 'LinuxDOOAuthEnabled') {
  463. setLinuxDOOAuthEnabled(value);
  464. }
  465. };
  466. const handlePasswordLoginConfirm = async () => {
  467. await updateOptions([{ key: 'PasswordLoginEnabled', value: false }]);
  468. setShowPasswordLoginConfirmModal(false);
  469. };
  470. return (
  471. <div>
  472. {isLoaded ? (
  473. <Form
  474. initValues={inputs}
  475. onValueChange={handleFormChange}
  476. getFormApi={(api) => (formApiRef.current = api)}
  477. >
  478. {({ formState, values, formApi }) => (
  479. <div
  480. style={{
  481. display: 'flex',
  482. flexDirection: 'column',
  483. gap: '10px',
  484. marginTop: '10px',
  485. }}
  486. >
  487. <Card>
  488. <Form.Section text='通用设置'>
  489. <Form.Input
  490. field='ServerAddress'
  491. label='服务器地址'
  492. placeholder='例如:https://yourdomain.com'
  493. style={{ width: '100%' }}
  494. />
  495. <Button onClick={submitServerAddress}>更新服务器地址</Button>
  496. </Form.Section>
  497. </Card>
  498. <Card>
  499. <Form.Section text='代理设置'>
  500. <Text>
  501. (支持{' '}
  502. <a
  503. href='https://github.com/Calcium-Ion/new-api-worker'
  504. target='_blank'
  505. rel='noreferrer'
  506. >
  507. new-api-worker
  508. </a>
  509. </Text>
  510. <Row
  511. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  512. >
  513. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  514. <Form.Input
  515. field='WorkerUrl'
  516. label='Worker地址'
  517. placeholder='例如:https://workername.yourdomain.workers.dev'
  518. />
  519. </Col>
  520. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  521. <Form.Input
  522. field='WorkerValidKey'
  523. label='Worker密钥'
  524. placeholder='敏感信息不会发送到前端显示'
  525. type='password'
  526. />
  527. </Col>
  528. </Row>
  529. <Button onClick={submitWorker}>更新Worker设置</Button>
  530. </Form.Section>
  531. </Card>
  532. <Card>
  533. <Form.Section text='支付设置'>
  534. <Text>
  535. (当前仅支持易支付接口,默认使用上方服务器地址作为回调地址!)
  536. </Text>
  537. <Row
  538. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  539. >
  540. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  541. <Form.Input
  542. field='PayAddress'
  543. label='支付地址'
  544. placeholder='例如:https://yourdomain.com'
  545. />
  546. </Col>
  547. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  548. <Form.Input
  549. field='EpayId'
  550. label='易支付商户ID'
  551. placeholder='例如:0001'
  552. />
  553. </Col>
  554. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  555. <Form.Input
  556. field='EpayKey'
  557. label='易支付商户密钥'
  558. placeholder='敏感信息不会发送到前端显示'
  559. type='password'
  560. />
  561. </Col>
  562. </Row>
  563. <Row
  564. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  565. style={{ marginTop: 16 }}
  566. >
  567. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  568. <Form.Input
  569. field='CustomCallbackAddress'
  570. label='回调地址'
  571. placeholder='例如:https://yourdomain.com'
  572. />
  573. </Col>
  574. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  575. <Form.InputNumber
  576. field='Price'
  577. precision={2}
  578. label='充值价格(x元/美金)'
  579. placeholder='例如:7,就是7元/美金'
  580. />
  581. </Col>
  582. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  583. <Form.InputNumber
  584. field='MinTopUp'
  585. label='最低充值美元数量'
  586. placeholder='例如:2,就是最低充值2$'
  587. />
  588. </Col>
  589. </Row>
  590. <Form.TextArea
  591. field='TopupGroupRatio'
  592. label='充值分组倍率'
  593. placeholder='为一个 JSON 文本,键为组名称,值为倍率'
  594. autosize
  595. />
  596. <Button onClick={submitPayAddress}>更新支付设置</Button>
  597. </Form.Section>
  598. </Card>
  599. <Card>
  600. <Form.Section text='配置登录注册'>
  601. <Row
  602. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  603. >
  604. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  605. <Form.Checkbox
  606. field='PasswordLoginEnabled'
  607. noLabel
  608. onChange={(e) =>
  609. handleCheckboxChange('PasswordLoginEnabled', e)
  610. }
  611. >
  612. 允许通过密码进行登录
  613. </Form.Checkbox>
  614. <Form.Checkbox
  615. field='PasswordRegisterEnabled'
  616. noLabel
  617. onChange={(e) =>
  618. handleCheckboxChange('PasswordRegisterEnabled', e)
  619. }
  620. >
  621. 允许通过密码进行注册
  622. </Form.Checkbox>
  623. <Form.Checkbox
  624. field='EmailVerificationEnabled'
  625. noLabel
  626. onChange={(e) =>
  627. handleCheckboxChange('EmailVerificationEnabled', e)
  628. }
  629. >
  630. 通过密码注册时需要进行邮箱验证
  631. </Form.Checkbox>
  632. <Form.Checkbox
  633. field='RegisterEnabled'
  634. noLabel
  635. onChange={(e) =>
  636. handleCheckboxChange('RegisterEnabled', e)
  637. }
  638. >
  639. 允许新用户注册
  640. </Form.Checkbox>
  641. <Form.Checkbox
  642. field='TurnstileCheckEnabled'
  643. noLabel
  644. onChange={(e) =>
  645. handleCheckboxChange('TurnstileCheckEnabled', e)
  646. }
  647. >
  648. 启用 Turnstile 用户校验
  649. </Form.Checkbox>
  650. </Col>
  651. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  652. <Form.Checkbox
  653. field='GitHubOAuthEnabled'
  654. noLabel
  655. onChange={(e) =>
  656. handleCheckboxChange('GitHubOAuthEnabled', e)
  657. }
  658. >
  659. 允许通过 GitHub 账户登录 & 注册
  660. </Form.Checkbox>
  661. <Form.Checkbox
  662. field='LinuxDOOAuthEnabled'
  663. noLabel
  664. onChange={(e) =>
  665. handleCheckboxChange('LinuxDOOAuthEnabled', e)
  666. }
  667. >
  668. 允许通过 Linux DO 账户登录 & 注册
  669. </Form.Checkbox>
  670. <Form.Checkbox
  671. field='WeChatAuthEnabled'
  672. noLabel
  673. onChange={(e) =>
  674. handleCheckboxChange('WeChatAuthEnabled', e)
  675. }
  676. >
  677. 允许通过微信登录 & 注册
  678. </Form.Checkbox>
  679. <Form.Checkbox
  680. field='TelegramOAuthEnabled'
  681. noLabel
  682. onChange={(e) =>
  683. handleCheckboxChange('TelegramOAuthEnabled', e)
  684. }
  685. >
  686. 允许通过 Telegram 进行登录
  687. </Form.Checkbox>
  688. <Form.Checkbox
  689. field="['oidc.enabled']"
  690. noLabel
  691. onChange={(e) =>
  692. handleCheckboxChange('oidc.enabled', e)
  693. }
  694. >
  695. 允许通过 OIDC 进行登录
  696. </Form.Checkbox>
  697. </Col>
  698. </Row>
  699. </Form.Section>
  700. </Card>
  701. <Card>
  702. <Form.Section text='配置邮箱域名白名单'>
  703. <Text>用以防止恶意用户利用临时邮箱批量注册</Text>
  704. <Row
  705. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  706. >
  707. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  708. <Form.Checkbox
  709. field='EmailDomainRestrictionEnabled'
  710. noLabel
  711. onChange={(e) =>
  712. handleCheckboxChange(
  713. 'EmailDomainRestrictionEnabled',
  714. e,
  715. )
  716. }
  717. >
  718. 启用邮箱域名白名单
  719. </Form.Checkbox>
  720. </Col>
  721. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  722. <Form.Checkbox
  723. field='EmailAliasRestrictionEnabled'
  724. noLabel
  725. onChange={(e) =>
  726. handleCheckboxChange(
  727. 'EmailAliasRestrictionEnabled',
  728. e,
  729. )
  730. }
  731. >
  732. 启用邮箱别名限制
  733. </Form.Checkbox>
  734. </Col>
  735. </Row>
  736. <TagInput
  737. value={emailDomainWhitelist}
  738. onChange={setEmailDomainWhitelist}
  739. placeholder='输入域名后回车'
  740. style={{ width: '100%', marginTop: 16 }}
  741. />
  742. <Form.Input
  743. placeholder='输入要添加的邮箱域名'
  744. value={emailToAdd}
  745. onChange={(value) => setEmailToAdd(value)}
  746. style={{ marginTop: 16 }}
  747. suffix={
  748. <Button theme="solid" type="primary" onClick={handleAddEmail}>添加</Button>
  749. }
  750. onEnterPress={handleAddEmail}
  751. />
  752. <Button
  753. onClick={submitEmailDomainWhitelist}
  754. style={{ marginTop: 10 }}
  755. >
  756. 保存邮箱域名白名单设置
  757. </Button>
  758. </Form.Section>
  759. </Card>
  760. <Card>
  761. <Form.Section text='配置 SMTP'>
  762. <Text>用以支持系统的邮件发送</Text>
  763. <Row
  764. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  765. >
  766. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  767. <Form.Input field='SMTPServer' label='SMTP 服务器地址' />
  768. </Col>
  769. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  770. <Form.Input field='SMTPPort' label='SMTP 端口' />
  771. </Col>
  772. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  773. <Form.Input field='SMTPAccount' label='SMTP 账户' />
  774. </Col>
  775. </Row>
  776. <Row
  777. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  778. style={{ marginTop: 16 }}
  779. >
  780. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  781. <Form.Input field='SMTPFrom' label='SMTP 发送者邮箱' />
  782. </Col>
  783. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  784. <Form.Input
  785. field='SMTPToken'
  786. label='SMTP 访问凭证'
  787. type='password'
  788. placeholder='敏感信息不会发送到前端显示'
  789. />
  790. </Col>
  791. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  792. <Form.Checkbox
  793. field='SMTPSSLEnabled'
  794. noLabel
  795. onChange={(e) =>
  796. handleCheckboxChange('SMTPSSLEnabled', e)
  797. }
  798. >
  799. 启用SMTP SSL
  800. </Form.Checkbox>
  801. </Col>
  802. </Row>
  803. <Button onClick={submitSMTP}>保存 SMTP 设置</Button>
  804. </Form.Section>
  805. </Card>
  806. <Card>
  807. <Form.Section text='配置 OIDC'>
  808. <Text>
  809. 用以支持通过 OIDC 登录,例如 Okta、Auth0 等兼容 OIDC 协议的
  810. IdP
  811. </Text>
  812. <Banner
  813. type='info'
  814. description={`主页链接填 ${inputs.ServerAddress ? inputs.ServerAddress : '网站地址'},重定向 URL 填 ${inputs.ServerAddress ? inputs.ServerAddress : '网站地址'}/oauth/oidc`}
  815. style={{ marginBottom: 20, marginTop: 16 }}
  816. />
  817. <Text>
  818. 若你的 OIDC Provider 支持 Discovery Endpoint,你可以仅填写
  819. OIDC Well-Known URL,系统会自动获取 OIDC 配置
  820. </Text>
  821. <Row
  822. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  823. >
  824. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  825. <Form.Input
  826. field="['oidc.well_known']"
  827. label='Well-Known URL'
  828. placeholder='请输入 OIDC 的 Well-Known URL'
  829. />
  830. </Col>
  831. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  832. <Form.Input
  833. field="['oidc.client_id']"
  834. label='Client ID'
  835. placeholder='输入 OIDC 的 Client ID'
  836. />
  837. </Col>
  838. </Row>
  839. <Row
  840. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  841. >
  842. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  843. <Form.Input
  844. field="['oidc.client_secret']"
  845. label='Client Secret'
  846. type='password'
  847. placeholder='敏感信息不会发送到前端显示'
  848. />
  849. </Col>
  850. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  851. <Form.Input
  852. field="['oidc.authorization_endpoint']"
  853. label='Authorization Endpoint'
  854. placeholder='输入 OIDC 的 Authorization Endpoint'
  855. />
  856. </Col>
  857. </Row>
  858. <Row
  859. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  860. >
  861. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  862. <Form.Input
  863. field="['oidc.token_endpoint']"
  864. label='Token Endpoint'
  865. placeholder='输入 OIDC 的 Token Endpoint'
  866. />
  867. </Col>
  868. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  869. <Form.Input
  870. field="['oidc.user_info_endpoint']"
  871. label='User Info Endpoint'
  872. placeholder='输入 OIDC 的 Userinfo Endpoint'
  873. />
  874. </Col>
  875. </Row>
  876. <Button onClick={submitOIDCSettings}>保存 OIDC 设置</Button>
  877. </Form.Section>
  878. </Card>
  879. <Card>
  880. <Form.Section text='配置 GitHub OAuth App'>
  881. <Text>用以支持通过 GitHub 进行登录注册</Text>
  882. <Banner
  883. type='info'
  884. description={`Homepage URL 填 ${inputs.ServerAddress ? inputs.ServerAddress : '网站地址'},Authorization callback URL 填 ${inputs.ServerAddress ? inputs.ServerAddress : '网站地址'}/oauth/github`}
  885. style={{ marginBottom: 20, marginTop: 16 }}
  886. />
  887. <Row
  888. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  889. >
  890. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  891. <Form.Input
  892. field='GitHubClientId'
  893. label='GitHub Client ID'
  894. />
  895. </Col>
  896. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  897. <Form.Input
  898. field='GitHubClientSecret'
  899. label='GitHub Client Secret'
  900. type='password'
  901. placeholder='敏感信息不会发送到前端显示'
  902. />
  903. </Col>
  904. </Row>
  905. <Button onClick={submitGitHubOAuth}>
  906. 保存 GitHub OAuth 设置
  907. </Button>
  908. </Form.Section>
  909. </Card>
  910. <Card>
  911. <Form.Section text='配置 Linux DO OAuth'>
  912. <Text>
  913. 用以支持通过 Linux DO 进行登录注册
  914. <a
  915. href='https://connect.linux.do/'
  916. target='_blank'
  917. rel='noreferrer'
  918. style={{
  919. display: 'inline-block',
  920. marginLeft: 4,
  921. marginRight: 4,
  922. }}
  923. >
  924. 点击此处
  925. </a>
  926. 管理你的 LinuxDO OAuth App
  927. </Text>
  928. <Banner
  929. type='info'
  930. description={`回调 URL 填 ${inputs.ServerAddress ? inputs.ServerAddress : '网站地址'}/oauth/linuxdo`}
  931. style={{ marginBottom: 20, marginTop: 16 }}
  932. />
  933. <Row
  934. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  935. >
  936. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  937. <Form.Input
  938. field='LinuxDOClientId'
  939. label='Linux DO Client ID'
  940. placeholder='输入你注册的 LinuxDO OAuth APP 的 ID'
  941. />
  942. </Col>
  943. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  944. <Form.Input
  945. field='LinuxDOClientSecret'
  946. label='Linux DO Client Secret'
  947. type='password'
  948. placeholder='敏感信息不会发送到前端显示'
  949. />
  950. </Col>
  951. </Row>
  952. <Button onClick={submitLinuxDOOAuth}>
  953. 保存 Linux DO OAuth 设置
  954. </Button>
  955. </Form.Section>
  956. </Card>
  957. <Card>
  958. <Form.Section text='配置 WeChat Server'>
  959. <Text>用以支持通过微信进行登录注册</Text>
  960. <Row
  961. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  962. >
  963. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  964. <Form.Input
  965. field='WeChatServerAddress'
  966. label='WeChat Server 服务器地址'
  967. />
  968. </Col>
  969. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  970. <Form.Input
  971. field='WeChatServerToken'
  972. label='WeChat Server 访问凭证'
  973. type='password'
  974. placeholder='敏感信息不会发送到前端显示'
  975. />
  976. </Col>
  977. <Col xs={24} sm={24} md={8} lg={8} xl={8}>
  978. <Form.Input
  979. field='WeChatAccountQRCodeImageURL'
  980. label='微信公众号二维码图片链接'
  981. />
  982. </Col>
  983. </Row>
  984. <Button onClick={submitWeChat}>
  985. 保存 WeChat Server 设置
  986. </Button>
  987. </Form.Section>
  988. </Card>
  989. <Card>
  990. <Form.Section text='配置 Telegram 登录'>
  991. <Text>用以支持通过 Telegram 进行登录注册</Text>
  992. <Row
  993. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  994. >
  995. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  996. <Form.Input
  997. field='TelegramBotToken'
  998. label='Telegram Bot Token'
  999. placeholder='敏感信息不会发送到前端显示'
  1000. type='password'
  1001. />
  1002. </Col>
  1003. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1004. <Form.Input
  1005. field='TelegramBotName'
  1006. label='Telegram Bot 名称'
  1007. />
  1008. </Col>
  1009. </Row>
  1010. <Button onClick={submitTelegramSettings}>
  1011. 保存 Telegram 登录设置
  1012. </Button>
  1013. </Form.Section>
  1014. </Card>
  1015. <Card>
  1016. <Form.Section text='配置 Turnstile'>
  1017. <Text>用以支持用户校验</Text>
  1018. <Row
  1019. gutter={{ xs: 8, sm: 16, md: 24, lg: 24, xl: 24, xxl: 24 }}
  1020. >
  1021. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1022. <Form.Input
  1023. field='TurnstileSiteKey'
  1024. label='Turnstile Site Key'
  1025. />
  1026. </Col>
  1027. <Col xs={24} sm={24} md={12} lg={12} xl={12}>
  1028. <Form.Input
  1029. field='TurnstileSecretKey'
  1030. label='Turnstile Secret Key'
  1031. type='password'
  1032. placeholder='敏感信息不会发送到前端显示'
  1033. />
  1034. </Col>
  1035. </Row>
  1036. <Button onClick={submitTurnstile}>保存 Turnstile 设置</Button>
  1037. </Form.Section>
  1038. </Card>
  1039. <Modal
  1040. title='确认取消密码登录'
  1041. visible={showPasswordLoginConfirmModal}
  1042. onOk={handlePasswordLoginConfirm}
  1043. onCancel={() => {
  1044. setShowPasswordLoginConfirmModal(false);
  1045. formApiRef.current.setValue('PasswordLoginEnabled', true);
  1046. }}
  1047. okText='确认'
  1048. cancelText='取消'
  1049. >
  1050. <p>您确定要取消密码登录功能吗?这可能会影响用户的登录方式。</p>
  1051. </Modal>
  1052. </div>
  1053. )}
  1054. </Form>
  1055. ) : (
  1056. <div
  1057. style={{
  1058. display: 'flex',
  1059. justifyContent: 'center',
  1060. alignItems: 'center',
  1061. height: '100vh',
  1062. }}
  1063. >
  1064. <Spin size='large' />
  1065. </div>
  1066. )}
  1067. </div>
  1068. );
  1069. };
  1070. export default SystemSetting;