From 5c694a1503153d2fa04b0701900f8af3252f1e04 Mon Sep 17 00:00:00 2001 From: JustSong Date: Fri, 12 May 2023 11:44:38 +0800 Subject: [PATCH] feat: now supports custom smtp port --- common/constants.go | 1 + common/email.go | 2 +- model/option.go | 4 ++ web/src/components/SystemSetting.js | 43 +++++++++++++++------- web/src/pages/Channel/AddChannel.js | 8 ++-- web/src/pages/Channel/EditChannel.js | 8 ++-- web/src/pages/Redemption/EditRedemption.js | 8 ++-- web/src/pages/Token/EditToken.js | 8 ++-- web/src/pages/User/EditUser.js | 14 +++---- 9 files changed, 58 insertions(+), 38 deletions(-) diff --git a/common/constants.go b/common/constants.go index e99e9a05..6f3e770c 100644 --- a/common/constants.go +++ b/common/constants.go @@ -34,6 +34,7 @@ var TurnstileCheckEnabled = false var RegisterEnabled = true var SMTPServer = "" +var SMTPPort = 587 var SMTPAccount = "" var SMTPToken = "" diff --git a/common/email.go b/common/email.go index 8e293be7..1f0ad7ec 100644 --- a/common/email.go +++ b/common/email.go @@ -8,7 +8,7 @@ func SendEmail(subject string, receiver string, content string) error { m.SetHeader("To", receiver) m.SetHeader("Subject", subject) m.SetBody("text/html", content) - d := gomail.NewDialer(SMTPServer, 587, SMTPAccount, SMTPToken) + d := gomail.NewDialer(SMTPServer, SMTPPort, SMTPAccount, SMTPToken) err := d.DialAndSend(m) return err } diff --git a/model/option.go b/model/option.go index 45a56ba9..1d25c268 100644 --- a/model/option.go +++ b/model/option.go @@ -33,6 +33,7 @@ func InitOptionMap() { common.OptionMap["TurnstileCheckEnabled"] = strconv.FormatBool(common.TurnstileCheckEnabled) common.OptionMap["RegisterEnabled"] = strconv.FormatBool(common.RegisterEnabled) common.OptionMap["SMTPServer"] = "" + common.OptionMap["SMTPPort"] = strconv.Itoa(common.SMTPPort) common.OptionMap["SMTPAccount"] = "" common.OptionMap["SMTPToken"] = "" common.OptionMap["Notice"] = "" @@ -112,6 +113,9 @@ func updateOptionMap(key string, value string) (err error) { switch key { case "SMTPServer": common.SMTPServer = value + case "SMTPPort": + intValue, _ := strconv.Atoi(value) + common.SMTPPort = intValue case "SMTPAccount": common.SMTPAccount = value case "SMTPToken": diff --git a/web/src/components/SystemSetting.js b/web/src/components/SystemSetting.js index 303faaf7..eb3193c4 100644 --- a/web/src/components/SystemSetting.js +++ b/web/src/components/SystemSetting.js @@ -12,6 +12,7 @@ const SystemSetting = () => { GitHubClientSecret: '', Notice: '', SMTPServer: '', + SMTPPort: '', SMTPAccount: '', SMTPToken: '', ServerAddress: '', @@ -128,6 +129,12 @@ const SystemSetting = () => { if (originInputs['SMTPAccount'] !== inputs.SMTPAccount) { await updateOption('SMTPAccount', inputs.SMTPAccount); } + if ( + originInputs['SMTPPort'] !== inputs.SMTPPort && + inputs.SMTPPort !== '' + ) { + await updateOption('SMTPPort', inputs.SMTPPort); + } if ( originInputs['SMTPToken'] !== inputs.SMTPToken && inputs.SMTPToken !== '' @@ -258,7 +265,7 @@ const SystemSetting = () => { label='新用户初始配额' name='QuotaForNewUser' onChange={handleInputChange} - autoComplete='off' + autoComplete='new-password' value={inputs.QuotaForNewUser} type='number' min='0' @@ -268,7 +275,7 @@ const SystemSetting = () => { label='充值链接' name='TopUpLink' onChange={handleInputChange} - autoComplete='off' + autoComplete='new-password' value={inputs.TopUpLink} type='link' placeholder='例如发卡网站的购买链接' @@ -280,7 +287,7 @@ const SystemSetting = () => { name='ModelRatio' onChange={handleInputChange} style={{ minHeight: 250, fontFamily: 'JetBrains Mono, Consolas' }} - autoComplete='off' + autoComplete='new-password' value={inputs.ModelRatio} placeholder='为一个 JSON 文本,键为模型名称,值为倍率' /> @@ -291,20 +298,28 @@ const SystemSetting = () => { 配置 SMTP 用以支持系统的邮件发送 - + + @@ -313,7 +328,7 @@ const SystemSetting = () => { name='SMTPToken' onChange={handleInputChange} type='password' - autoComplete='off' + autoComplete='new-password' value={inputs.SMTPToken} placeholder='敏感信息不会发送到前端显示' /> @@ -340,7 +355,7 @@ const SystemSetting = () => { label='GitHub Client ID' name='GitHubClientId' onChange={handleInputChange} - autoComplete='off' + autoComplete='new-password' value={inputs.GitHubClientId} placeholder='输入你注册的 GitHub OAuth APP 的 ID' /> @@ -349,7 +364,7 @@ const SystemSetting = () => { name='GitHubClientSecret' onChange={handleInputChange} type='password' - autoComplete='off' + autoComplete='new-password' value={inputs.GitHubClientSecret} placeholder='敏感信息不会发送到前端显示' /> @@ -377,7 +392,7 @@ const SystemSetting = () => { name='WeChatServerAddress' placeholder='例如:https://yourdomain.com' onChange={handleInputChange} - autoComplete='off' + autoComplete='new-password' value={inputs.WeChatServerAddress} /> { name='WeChatServerToken' type='password' onChange={handleInputChange} - autoComplete='off' + autoComplete='new-password' value={inputs.WeChatServerToken} placeholder='敏感信息不会发送到前端显示' /> @@ -393,7 +408,7 @@ const SystemSetting = () => { label='微信公众号二维码图片链接' name='WeChatAccountQRCodeImageURL' onChange={handleInputChange} - autoComplete='off' + autoComplete='new-password' value={inputs.WeChatAccountQRCodeImageURL} placeholder='输入一个图片链接' /> @@ -417,7 +432,7 @@ const SystemSetting = () => { label='Turnstile Site Key' name='TurnstileSiteKey' onChange={handleInputChange} - autoComplete='off' + autoComplete='new-password' value={inputs.TurnstileSiteKey} placeholder='输入你注册的 Turnstile Site Key' /> @@ -426,7 +441,7 @@ const SystemSetting = () => { name='TurnstileSecretKey' onChange={handleInputChange} type='password' - autoComplete='off' + autoComplete='new-password' value={inputs.TurnstileSecretKey} placeholder='敏感信息不会发送到前端显示' /> diff --git a/web/src/pages/Channel/AddChannel.js b/web/src/pages/Channel/AddChannel.js index f958e33c..57c16eba 100644 --- a/web/src/pages/Channel/AddChannel.js +++ b/web/src/pages/Channel/AddChannel.js @@ -36,7 +36,7 @@ const AddChannel = () => { <>
创建新的渠道
-
+ { placeholder={'请输入自定义渠道的 Base URL,例如:https://openai.justsong.cn'} onChange={handleInputChange} value={inputs.base_url} - autoComplete='off' + autoComplete='new-password' /> ) @@ -67,7 +67,7 @@ const AddChannel = () => { placeholder={'请输入名称'} onChange={handleInputChange} value={name} - autoComplete='off' + autoComplete='new-password' required /> @@ -79,7 +79,7 @@ const AddChannel = () => { onChange={handleInputChange} value={key} // type='password' - autoComplete='off' + autoComplete='new-password' required /> diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index 4964efb4..7758323f 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -50,7 +50,7 @@ const EditChannel = () => { <>
更新渠道信息
- + { placeholder={'请输入新的自定义渠道的 Base URL,例如:https://openai.justsong.cn'} onChange={handleInputChange} value={inputs.base_url} - autoComplete='off' + autoComplete='new-password' /> ) @@ -81,7 +81,7 @@ const EditChannel = () => { placeholder={'请输入新的名称'} onChange={handleInputChange} value={inputs.name} - autoComplete='off' + autoComplete='new-password' /> @@ -92,7 +92,7 @@ const EditChannel = () => { onChange={handleInputChange} value={inputs.key} // type='password' - autoComplete='off' + autoComplete='new-password' /> diff --git a/web/src/pages/Redemption/EditRedemption.js b/web/src/pages/Redemption/EditRedemption.js index de6d4b2c..687864ba 100644 --- a/web/src/pages/Redemption/EditRedemption.js +++ b/web/src/pages/Redemption/EditRedemption.js @@ -73,7 +73,7 @@ const EditRedemption = () => { <>
{isEdit ? '更新兑换码信息' : '创建新的兑换码'}
- + { placeholder={'请输入名称'} onChange={handleInputChange} value={name} - autoComplete='off' + autoComplete='new-password' required={!isEdit} /> @@ -92,7 +92,7 @@ const EditRedemption = () => { placeholder={'请输入单个兑换码中包含的额度'} onChange={handleInputChange} value={quota} - autoComplete='off' + autoComplete='new-password' type='number' /> @@ -105,7 +105,7 @@ const EditRedemption = () => { placeholder={'请输入生成数量'} onChange={handleInputChange} value={count} - autoComplete='off' + autoComplete='new-password' type='number' /> diff --git a/web/src/pages/Token/EditToken.js b/web/src/pages/Token/EditToken.js index 220a4711..bba7f5e9 100644 --- a/web/src/pages/Token/EditToken.js +++ b/web/src/pages/Token/EditToken.js @@ -95,7 +95,7 @@ const EditToken = () => { <>
{isEdit ? '更新令牌信息' : '创建新的令牌'}
- + { placeholder={'请输入名称'} onChange={handleInputChange} value={name} - autoComplete='off' + autoComplete='new-password' required={!isEdit} /> @@ -116,7 +116,7 @@ const EditToken = () => { placeholder={'请输入额度'} onChange={handleInputChange} value={remain_quota} - autoComplete='off' + autoComplete='new-password' type='number' disabled={unlimited_quota} /> @@ -133,7 +133,7 @@ const EditToken = () => { placeholder={'请输入过期时间,格式为 yyyy-MM-dd HH:mm:ss,-1 表示无限制'} onChange={handleInputChange} value={expired_time} - autoComplete='off' + autoComplete='new-password' type='datetime-local' /> diff --git a/web/src/pages/User/EditUser.js b/web/src/pages/User/EditUser.js index b3364213..a8d4e7cf 100644 --- a/web/src/pages/User/EditUser.js +++ b/web/src/pages/User/EditUser.js @@ -60,7 +60,7 @@ const EditUser = () => { <>
更新用户信息
- + { placeholder={'请输入新的用户名'} onChange={handleInputChange} value={username} - autoComplete='off' + autoComplete='new-password' /> @@ -79,7 +79,7 @@ const EditUser = () => { placeholder={'请输入新的密码'} onChange={handleInputChange} value={password} - autoComplete='off' + autoComplete='new-password' /> @@ -89,7 +89,7 @@ const EditUser = () => { placeholder={'请输入新的显示名称'} onChange={handleInputChange} value={display_name} - autoComplete='off' + autoComplete='new-password' /> @@ -97,7 +97,7 @@ const EditUser = () => { label='已绑定的 GitHub 账户' name='github_id' value={github_id} - autoComplete='off' + autoComplete='new-password' placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改' readOnly /> @@ -107,7 +107,7 @@ const EditUser = () => { label='已绑定的微信账户' name='wechat_id' value={wechat_id} - autoComplete='off' + autoComplete='new-password' placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改' readOnly /> @@ -117,7 +117,7 @@ const EditUser = () => { label='已绑定的邮箱账户' name='email' value={email} - autoComplete='off' + autoComplete='new-password' placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改' readOnly />