|
|
@@ -1,6 +1,6 @@
|
|
|
-import React, {useEffect, useState} from 'react';
|
|
|
-import {Button, Divider, Form, Grid, Header, Modal, Message} from 'semantic-ui-react';
|
|
|
-import {API, removeTrailingSlash, showError, verifyJSON} from '../helpers';
|
|
|
+import React, { useEffect, useState } from 'react';
|
|
|
+import { Button, Divider, Form, Grid, Header, Modal, Message } from 'semantic-ui-react';
|
|
|
+import { API, removeTrailingSlash, showError, verifyJSON } from '../helpers';
|
|
|
|
|
|
const SystemSetting = () => {
|
|
|
let [inputs, setInputs] = useState({
|
|
|
@@ -34,7 +34,11 @@ const SystemSetting = () => {
|
|
|
TurnstileSecretKey: '',
|
|
|
RegisterEnabled: '',
|
|
|
EmailDomainRestrictionEnabled: '',
|
|
|
- EmailDomainWhitelist: ''
|
|
|
+ EmailDomainWhitelist: '',
|
|
|
+ // telegram login
|
|
|
+ TelegramOAuthEnabled: '',
|
|
|
+ TelegramBotToken: '',
|
|
|
+ TelegramBotName: '',
|
|
|
});
|
|
|
const [originInputs, setOriginInputs] = useState({});
|
|
|
let [loading, setLoading] = useState(false);
|
|
|
@@ -44,7 +48,7 @@ const SystemSetting = () => {
|
|
|
|
|
|
const getOptions = async () => {
|
|
|
const res = await API.get('/api/option/');
|
|
|
- const {success, message, data} = res.data;
|
|
|
+ const { success, message, data } = res.data;
|
|
|
if (success) {
|
|
|
let newInputs = {};
|
|
|
data.forEach((item) => {
|
|
|
@@ -60,7 +64,7 @@ const SystemSetting = () => {
|
|
|
setOriginInputs(newInputs);
|
|
|
|
|
|
setEmailDomainWhitelist(newInputs.EmailDomainWhitelist.split(',').map((item) => {
|
|
|
- return {key: item, text: item, value: item};
|
|
|
+ return { key: item, text: item, value: item };
|
|
|
}));
|
|
|
} else {
|
|
|
showError(message);
|
|
|
@@ -79,6 +83,7 @@ const SystemSetting = () => {
|
|
|
case 'EmailVerificationEnabled':
|
|
|
case 'GitHubOAuthEnabled':
|
|
|
case 'WeChatAuthEnabled':
|
|
|
+ case 'TelegramOAuthEnabled':
|
|
|
case 'TurnstileCheckEnabled':
|
|
|
case 'EmailDomainRestrictionEnabled':
|
|
|
case 'RegisterEnabled':
|
|
|
@@ -91,7 +96,7 @@ const SystemSetting = () => {
|
|
|
key,
|
|
|
value
|
|
|
});
|
|
|
- const {success, message} = res.data;
|
|
|
+ const { success, message } = res.data;
|
|
|
if (success) {
|
|
|
if (key === 'EmailDomainWhitelist') {
|
|
|
value = value.split(',');
|
|
|
@@ -108,7 +113,7 @@ const SystemSetting = () => {
|
|
|
setLoading(false);
|
|
|
};
|
|
|
|
|
|
- const handleInputChange = async (e, {name, value}) => {
|
|
|
+ const handleInputChange = async (e, { name, value }) => {
|
|
|
if (name === 'PasswordLoginEnabled' && inputs[name] === 'true') {
|
|
|
// block disabling password login
|
|
|
setShowPasswordWarningModal(true);
|
|
|
@@ -130,9 +135,11 @@ const SystemSetting = () => {
|
|
|
name === 'TurnstileSiteKey' ||
|
|
|
name === 'TurnstileSecretKey' ||
|
|
|
name === 'EmailDomainWhitelist' ||
|
|
|
- name === 'TopupGroupRatio'
|
|
|
+ name === 'TopupGroupRatio' ||
|
|
|
+ name === 'TelegramBotToken' ||
|
|
|
+ name === 'TelegramBotName'
|
|
|
) {
|
|
|
- setInputs((inputs) => ({...inputs, [name]: value}));
|
|
|
+ setInputs((inputs) => ({ ...inputs, [name]: value }));
|
|
|
} else {
|
|
|
await updateOption(name, value);
|
|
|
}
|
|
|
@@ -236,6 +243,12 @@ const SystemSetting = () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ const submitTelegramSettings = async () => {
|
|
|
+ await updateOption('TelegramOAuthEnabled', inputs.TelegramOAuthEnabled);
|
|
|
+ await updateOption('TelegramBotToken', inputs.TelegramBotToken);
|
|
|
+ await updateOption('TelegramBotName', inputs.TelegramBotName);
|
|
|
+ };
|
|
|
+
|
|
|
const submitTurnstile = async () => {
|
|
|
if (originInputs['TurnstileSiteKey'] !== inputs.TurnstileSiteKey) {
|
|
|
await updateOption('TurnstileSiteKey', inputs.TurnstileSiteKey);
|
|
|
@@ -337,7 +350,7 @@ const SystemSetting = () => {
|
|
|
label='充值分组倍率'
|
|
|
name='TopupGroupRatio'
|
|
|
onChange={handleInputChange}
|
|
|
- style={{minHeight: 250, fontFamily: 'JetBrains Mono, Consolas'}}
|
|
|
+ style={{ minHeight: 250, fontFamily: 'JetBrains Mono, Consolas' }}
|
|
|
autoComplete='new-password'
|
|
|
value={inputs.TopupGroupRatio}
|
|
|
placeholder='为一个 JSON 文本,键为组名称,值为倍率'
|
|
|
@@ -346,7 +359,7 @@ const SystemSetting = () => {
|
|
|
<Form.Button onClick={submitPayAddress}>
|
|
|
更新支付设置
|
|
|
</Form.Button>
|
|
|
- <Divider/>
|
|
|
+ <Divider />
|
|
|
<Header as='h3'>配置登录注册</Header>
|
|
|
<Form.Group inline>
|
|
|
<Form.Checkbox
|
|
|
@@ -361,7 +374,7 @@ const SystemSetting = () => {
|
|
|
open={showPasswordWarningModal}
|
|
|
onClose={() => setShowPasswordWarningModal(false)}
|
|
|
size={'tiny'}
|
|
|
- style={{maxWidth: '450px'}}
|
|
|
+ style={{ maxWidth: '450px' }}
|
|
|
>
|
|
|
<Modal.Header>警告</Modal.Header>
|
|
|
<Modal.Content>
|
|
|
@@ -405,6 +418,12 @@ const SystemSetting = () => {
|
|
|
name='WeChatAuthEnabled'
|
|
|
onChange={handleInputChange}
|
|
|
/>
|
|
|
+ <Form.Checkbox
|
|
|
+ checked={inputs.TelegramOAuthEnabled === 'true'}
|
|
|
+ label='允许通过 Telegram 进行登录'
|
|
|
+ name='TelegramOAuthEnabled'
|
|
|
+ onChange={handleInputChange}
|
|
|
+ />
|
|
|
</Form.Group>
|
|
|
<Form.Group inline>
|
|
|
<Form.Checkbox
|
|
|
@@ -420,7 +439,7 @@ const SystemSetting = () => {
|
|
|
onChange={handleInputChange}
|
|
|
/>
|
|
|
</Form.Group>
|
|
|
- <Divider/>
|
|
|
+ <Divider />
|
|
|
<Header as='h3'>
|
|
|
配置邮箱域名白名单
|
|
|
<Header.Subheader>用以防止恶意用户利用临时邮箱批量注册</Header.Subheader>
|
|
|
@@ -462,13 +481,13 @@ const SystemSetting = () => {
|
|
|
autoComplete='new-password'
|
|
|
placeholder='输入新的允许的邮箱域名'
|
|
|
value={restrictedDomainInput}
|
|
|
- onChange={(e, {value}) => {
|
|
|
+ onChange={(e, { value }) => {
|
|
|
setRestrictedDomainInput(value);
|
|
|
}}
|
|
|
/>
|
|
|
</Form.Group>
|
|
|
<Form.Button onClick={submitEmailDomainWhitelist}>保存邮箱域名白名单设置</Form.Button>
|
|
|
- <Divider/>
|
|
|
+ <Divider />
|
|
|
<Header as='h3'>
|
|
|
配置 SMTP
|
|
|
<Header.Subheader>用以支持系统的邮件发送</Header.Subheader>
|
|
|
@@ -519,7 +538,7 @@ const SystemSetting = () => {
|
|
|
/>
|
|
|
</Form.Group>
|
|
|
<Form.Button onClick={submitSMTP}>保存 SMTP 设置</Form.Button>
|
|
|
- <Divider/>
|
|
|
+ <Divider />
|
|
|
<Header as='h3'>
|
|
|
配置 GitHub OAuth App
|
|
|
<Header.Subheader>
|
|
|
@@ -557,7 +576,7 @@ const SystemSetting = () => {
|
|
|
<Form.Button onClick={submitGitHubOAuth}>
|
|
|
保存 GitHub OAuth 设置
|
|
|
</Form.Button>
|
|
|
- <Divider/>
|
|
|
+ <Divider />
|
|
|
<Header as='h3'>
|
|
|
配置 WeChat Server
|
|
|
<Header.Subheader>
|
|
|
@@ -601,7 +620,28 @@ const SystemSetting = () => {
|
|
|
<Form.Button onClick={submitWeChat}>
|
|
|
保存 WeChat Server 设置
|
|
|
</Form.Button>
|
|
|
- <Divider/>
|
|
|
+ <Divider />
|
|
|
+ <Header as='h3'>配置 Telegram 登录</Header>
|
|
|
+ <Form.Group inline>
|
|
|
+ <Form.Input
|
|
|
+ label='Telegram Bot Token'
|
|
|
+ name='TelegramBotToken'
|
|
|
+ onChange={handleInputChange}
|
|
|
+ value={inputs.TelegramBotToken}
|
|
|
+ placeholder='输入你的 Telegram Bot Token'
|
|
|
+ />
|
|
|
+ <Form.Input
|
|
|
+ label='Telegram Bot 名称'
|
|
|
+ name='TelegramBotName'
|
|
|
+ onChange={handleInputChange}
|
|
|
+ value={inputs.TelegramBotName}
|
|
|
+ placeholder='输入你的 Telegram Bot 名称'
|
|
|
+ />
|
|
|
+ </Form.Group>
|
|
|
+ <Form.Button onClick={submitTelegramSettings}>
|
|
|
+ 保存 Telegram 登录设置
|
|
|
+ </Form.Button>
|
|
|
+ <Divider />
|
|
|
<Header as='h3'>
|
|
|
配置 Turnstile
|
|
|
<Header.Subheader>
|