Add Telegram bot token and name

This commit is contained in:
Ehco1996 2024-03-01 20:39:28 +08:00
parent feb40db2bc
commit 140e843d93
5 changed files with 81 additions and 20 deletions

View File

@ -82,6 +82,9 @@ var WeChatAccountQRCodeImageURL = ""
var TurnstileSiteKey = "" var TurnstileSiteKey = ""
var TurnstileSecretKey = "" var TurnstileSecretKey = ""
var TelegramBotToken = ""
var TelegramBotName = ""
var QuotaForNewUser = 0 var QuotaForNewUser = 0
var QuotaForInviter = 0 var QuotaForInviter = 0
var QuotaForInvitee = 0 var QuotaForInvitee = 0

View File

@ -12,7 +12,7 @@ services:
- ./data:/data - ./data:/data
- ./logs:/app/logs - ./logs:/app/logs
environment: environment:
- SQL_DSN=root:123456@tcp(host.docker.internal:3306)/new-api # 修改此行,或注释掉以使用 SQLite 作为数据库 # - SQL_DSN=root:123456@tcp(host.docker.internal:3306)/new-api # 修改此行,或注释掉以使用 SQLite 作为数据库
- REDIS_CONN_STRING=redis://redis - REDIS_CONN_STRING=redis://redis
- SESSION_SECRET=random_string # 修改为随机字符串 - SESSION_SECRET=random_string # 修改为随机字符串
- TZ=Asia/Shanghai - TZ=Asia/Shanghai

17
makefile Normal file
View File

@ -0,0 +1,17 @@
FRONTEND_DIR = ./web
BACKEND_DIR = .
.PHONY: all start-frontend start-backend
all: start-frontend start-backend
# 启动前端开发服务器
start-frontend:
@echo "Starting frontend dev server..."
@cd $(FRONTEND_DIR) && npm start &
# 启动后端开发服务器
start-backend:
@echo "Starting backend dev server..."
@cd $(BACKEND_DIR) && go run main.go &

View File

@ -215,6 +215,10 @@ func updateOptionMap(key string, value string) (err error) {
common.WeChatServerToken = value common.WeChatServerToken = value
case "WeChatAccountQRCodeImageURL": case "WeChatAccountQRCodeImageURL":
common.WeChatAccountQRCodeImageURL = value common.WeChatAccountQRCodeImageURL = value
case "TelegramBotToken":
common.TelegramBotToken = value
case "TelegramBotName":
common.TelegramBotName = value
case "TurnstileSiteKey": case "TurnstileSiteKey":
common.TurnstileSiteKey = value common.TurnstileSiteKey = value
case "TurnstileSecretKey": case "TurnstileSecretKey":

View File

@ -1,6 +1,6 @@
import React, {useEffect, useState} from 'react'; import React, { useEffect, useState } from 'react';
import {Button, Divider, Form, Grid, Header, Modal, Message} from 'semantic-ui-react'; import { Button, Divider, Form, Grid, Header, Modal, Message } from 'semantic-ui-react';
import {API, removeTrailingSlash, showError, verifyJSON} from '../helpers'; import { API, removeTrailingSlash, showError, verifyJSON } from '../helpers';
const SystemSetting = () => { const SystemSetting = () => {
let [inputs, setInputs] = useState({ let [inputs, setInputs] = useState({
@ -32,7 +32,11 @@ const SystemSetting = () => {
TurnstileSecretKey: '', TurnstileSecretKey: '',
RegisterEnabled: '', RegisterEnabled: '',
EmailDomainRestrictionEnabled: '', EmailDomainRestrictionEnabled: '',
EmailDomainWhitelist: '' EmailDomainWhitelist: '',
// telegram login
TelegramLoginEnabled: '',
TelegramBotToken: '',
TelegramBotName: '',
}); });
const [originInputs, setOriginInputs] = useState({}); const [originInputs, setOriginInputs] = useState({});
let [loading, setLoading] = useState(false); let [loading, setLoading] = useState(false);
@ -42,7 +46,7 @@ const SystemSetting = () => {
const getOptions = async () => { const getOptions = async () => {
const res = await API.get('/api/option/'); const res = await API.get('/api/option/');
const {success, message, data} = res.data; const { success, message, data } = res.data;
if (success) { if (success) {
let newInputs = {}; let newInputs = {};
data.forEach((item) => { data.forEach((item) => {
@ -58,7 +62,7 @@ const SystemSetting = () => {
setOriginInputs(newInputs); setOriginInputs(newInputs);
setEmailDomainWhitelist(newInputs.EmailDomainWhitelist.split(',').map((item) => { setEmailDomainWhitelist(newInputs.EmailDomainWhitelist.split(',').map((item) => {
return {key: item, text: item, value: item}; return { key: item, text: item, value: item };
})); }));
} else { } else {
showError(message); showError(message);
@ -77,6 +81,7 @@ const SystemSetting = () => {
case 'EmailVerificationEnabled': case 'EmailVerificationEnabled':
case 'GitHubOAuthEnabled': case 'GitHubOAuthEnabled':
case 'WeChatAuthEnabled': case 'WeChatAuthEnabled':
case 'TelegramLoginEnabled':
case 'TurnstileCheckEnabled': case 'TurnstileCheckEnabled':
case 'EmailDomainRestrictionEnabled': case 'EmailDomainRestrictionEnabled':
case 'RegisterEnabled': case 'RegisterEnabled':
@ -89,7 +94,7 @@ const SystemSetting = () => {
key, key,
value value
}); });
const {success, message} = res.data; const { success, message } = res.data;
if (success) { if (success) {
if (key === 'EmailDomainWhitelist') { if (key === 'EmailDomainWhitelist') {
value = value.split(','); value = value.split(',');
@ -106,7 +111,7 @@ const SystemSetting = () => {
setLoading(false); setLoading(false);
}; };
const handleInputChange = async (e, {name, value}) => { const handleInputChange = async (e, { name, value }) => {
if (name === 'PasswordLoginEnabled' && inputs[name] === 'true') { if (name === 'PasswordLoginEnabled' && inputs[name] === 'true') {
// block disabling password login // block disabling password login
setShowPasswordWarningModal(true); setShowPasswordWarningModal(true);
@ -130,7 +135,7 @@ const SystemSetting = () => {
name === 'EmailDomainWhitelist' || name === 'EmailDomainWhitelist' ||
name === 'TopupGroupRatio' name === 'TopupGroupRatio'
) { ) {
setInputs((inputs) => ({...inputs, [name]: value})); setInputs((inputs) => ({ ...inputs, [name]: value }));
} else { } else {
await updateOption(name, value); await updateOption(name, value);
} }
@ -234,6 +239,12 @@ const SystemSetting = () => {
} }
}; };
const submitTelegramSettings = async () => {
await updateOption('TelegramLoginEnabled', inputs.TelegramLoginEnabled);
await updateOption('TelegramBotToken', inputs.TelegramBotToken);
await updateOption('TelegramBotName', inputs.TelegramBotName);
};
const submitTurnstile = async () => { const submitTurnstile = async () => {
if (originInputs['TurnstileSiteKey'] !== inputs.TurnstileSiteKey) { if (originInputs['TurnstileSiteKey'] !== inputs.TurnstileSiteKey) {
await updateOption('TurnstileSiteKey', inputs.TurnstileSiteKey); await updateOption('TurnstileSiteKey', inputs.TurnstileSiteKey);
@ -279,7 +290,7 @@ const SystemSetting = () => {
<Form.Button onClick={submitServerAddress}> <Form.Button onClick={submitServerAddress}>
更新服务器地址 更新服务器地址
</Form.Button> </Form.Button>
<Divider/> <Divider />
<Header as='h3'>支付设置当前仅支持易支付接口使用上方服务器地址作为回调地址</Header> <Header as='h3'>支付设置当前仅支持易支付接口使用上方服务器地址作为回调地址</Header>
<Form.Group widths='equal'> <Form.Group widths='equal'>
<Form.Input <Form.Input
@ -318,7 +329,7 @@ const SystemSetting = () => {
label='充值分组倍率' label='充值分组倍率'
name='TopupGroupRatio' name='TopupGroupRatio'
onChange={handleInputChange} onChange={handleInputChange}
style={{minHeight: 250, fontFamily: 'JetBrains Mono, Consolas'}} style={{ minHeight: 250, fontFamily: 'JetBrains Mono, Consolas' }}
autoComplete='new-password' autoComplete='new-password'
value={inputs.TopupGroupRatio} value={inputs.TopupGroupRatio}
placeholder='为一个 JSON 文本,键为组名称,值为倍率' placeholder='为一个 JSON 文本,键为组名称,值为倍率'
@ -327,7 +338,7 @@ const SystemSetting = () => {
<Form.Button onClick={submitPayAddress}> <Form.Button onClick={submitPayAddress}>
更新支付设置 更新支付设置
</Form.Button> </Form.Button>
<Divider/> <Divider />
<Header as='h3'>配置登录注册</Header> <Header as='h3'>配置登录注册</Header>
<Form.Group inline> <Form.Group inline>
<Form.Checkbox <Form.Checkbox
@ -342,7 +353,7 @@ const SystemSetting = () => {
open={showPasswordWarningModal} open={showPasswordWarningModal}
onClose={() => setShowPasswordWarningModal(false)} onClose={() => setShowPasswordWarningModal(false)}
size={'tiny'} size={'tiny'}
style={{maxWidth: '450px'}} style={{ maxWidth: '450px' }}
> >
<Modal.Header>警告</Modal.Header> <Modal.Header>警告</Modal.Header>
<Modal.Content> <Modal.Content>
@ -401,7 +412,33 @@ const SystemSetting = () => {
onChange={handleInputChange} onChange={handleInputChange}
/> />
</Form.Group> </Form.Group>
<Divider/> <Divider />
<Header as='h3'>配置 Telegram 登录</Header>
<Form.Group inline>
<Form.Checkbox
checked={inputs.TelegramLoginEnabled === 'true'}
label='允许通过 Telegram 进行登录'
name='TelegramLoginEnabled'
onChange={handleInputChange}
/>
<Form.Input
label='Telegram Bot Token'
name='TelegramBotToken'
value={inputs.TelegramBotToken}
placeholder='输入你的 Telegram Bot Token'
onChange={handleInputChange}
/>
<Form.Input
label='Telegram Bot 名称'
name='TelegramBotName'
value={inputs.TelegramBotName}
placeholder='输入你的 Telegram Bot 名称'
onChange={handleInputChange}
/>
</Form.Group>
<Form.Button onClick={submitTelegramSettings}>
保存 Telegram 登录设置
</Form.Button>
<Header as='h3'> <Header as='h3'>
配置邮箱域名白名单 配置邮箱域名白名单
<Header.Subheader>用以防止恶意用户利用临时邮箱批量注册</Header.Subheader> <Header.Subheader>用以防止恶意用户利用临时邮箱批量注册</Header.Subheader>
@ -443,13 +480,13 @@ const SystemSetting = () => {
autoComplete='new-password' autoComplete='new-password'
placeholder='输入新的允许的邮箱域名' placeholder='输入新的允许的邮箱域名'
value={restrictedDomainInput} value={restrictedDomainInput}
onChange={(e, {value}) => { onChange={(e, { value }) => {
setRestrictedDomainInput(value); setRestrictedDomainInput(value);
}} }}
/> />
</Form.Group> </Form.Group>
<Form.Button onClick={submitEmailDomainWhitelist}>保存邮箱域名白名单设置</Form.Button> <Form.Button onClick={submitEmailDomainWhitelist}>保存邮箱域名白名单设置</Form.Button>
<Divider/> <Divider />
<Header as='h3'> <Header as='h3'>
配置 SMTP 配置 SMTP
<Header.Subheader>用以支持系统的邮件发送</Header.Subheader> <Header.Subheader>用以支持系统的邮件发送</Header.Subheader>
@ -500,7 +537,7 @@ const SystemSetting = () => {
/> />
</Form.Group> </Form.Group>
<Form.Button onClick={submitSMTP}>保存 SMTP 设置</Form.Button> <Form.Button onClick={submitSMTP}>保存 SMTP 设置</Form.Button>
<Divider/> <Divider />
<Header as='h3'> <Header as='h3'>
配置 GitHub OAuth App 配置 GitHub OAuth App
<Header.Subheader> <Header.Subheader>
@ -538,7 +575,7 @@ const SystemSetting = () => {
<Form.Button onClick={submitGitHubOAuth}> <Form.Button onClick={submitGitHubOAuth}>
保存 GitHub OAuth 设置 保存 GitHub OAuth 设置
</Form.Button> </Form.Button>
<Divider/> <Divider />
<Header as='h3'> <Header as='h3'>
配置 WeChat Server 配置 WeChat Server
<Header.Subheader> <Header.Subheader>
@ -582,7 +619,7 @@ const SystemSetting = () => {
<Form.Button onClick={submitWeChat}> <Form.Button onClick={submitWeChat}>
保存 WeChat Server 设置 保存 WeChat Server 设置
</Form.Button> </Form.Button>
<Divider/> <Divider />
<Header as='h3'> <Header as='h3'>
配置 Turnstile 配置 Turnstile
<Header.Subheader> <Header.Subheader>