SystemSetting.js 35 KB

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