feat: now supports custom smtp port

This commit is contained in:
JustSong 2023-05-12 11:44:38 +08:00
parent 9edc54ca69
commit 5c694a1503
9 changed files with 58 additions and 38 deletions

View File

@ -34,6 +34,7 @@ var TurnstileCheckEnabled = false
var RegisterEnabled = true var RegisterEnabled = true
var SMTPServer = "" var SMTPServer = ""
var SMTPPort = 587
var SMTPAccount = "" var SMTPAccount = ""
var SMTPToken = "" var SMTPToken = ""

View File

@ -8,7 +8,7 @@ func SendEmail(subject string, receiver string, content string) error {
m.SetHeader("To", receiver) m.SetHeader("To", receiver)
m.SetHeader("Subject", subject) m.SetHeader("Subject", subject)
m.SetBody("text/html", content) m.SetBody("text/html", content)
d := gomail.NewDialer(SMTPServer, 587, SMTPAccount, SMTPToken) d := gomail.NewDialer(SMTPServer, SMTPPort, SMTPAccount, SMTPToken)
err := d.DialAndSend(m) err := d.DialAndSend(m)
return err return err
} }

View File

@ -33,6 +33,7 @@ func InitOptionMap() {
common.OptionMap["TurnstileCheckEnabled"] = strconv.FormatBool(common.TurnstileCheckEnabled) common.OptionMap["TurnstileCheckEnabled"] = strconv.FormatBool(common.TurnstileCheckEnabled)
common.OptionMap["RegisterEnabled"] = strconv.FormatBool(common.RegisterEnabled) common.OptionMap["RegisterEnabled"] = strconv.FormatBool(common.RegisterEnabled)
common.OptionMap["SMTPServer"] = "" common.OptionMap["SMTPServer"] = ""
common.OptionMap["SMTPPort"] = strconv.Itoa(common.SMTPPort)
common.OptionMap["SMTPAccount"] = "" common.OptionMap["SMTPAccount"] = ""
common.OptionMap["SMTPToken"] = "" common.OptionMap["SMTPToken"] = ""
common.OptionMap["Notice"] = "" common.OptionMap["Notice"] = ""
@ -112,6 +113,9 @@ func updateOptionMap(key string, value string) (err error) {
switch key { switch key {
case "SMTPServer": case "SMTPServer":
common.SMTPServer = value common.SMTPServer = value
case "SMTPPort":
intValue, _ := strconv.Atoi(value)
common.SMTPPort = intValue
case "SMTPAccount": case "SMTPAccount":
common.SMTPAccount = value common.SMTPAccount = value
case "SMTPToken": case "SMTPToken":

View File

@ -12,6 +12,7 @@ const SystemSetting = () => {
GitHubClientSecret: '', GitHubClientSecret: '',
Notice: '', Notice: '',
SMTPServer: '', SMTPServer: '',
SMTPPort: '',
SMTPAccount: '', SMTPAccount: '',
SMTPToken: '', SMTPToken: '',
ServerAddress: '', ServerAddress: '',
@ -128,6 +129,12 @@ const SystemSetting = () => {
if (originInputs['SMTPAccount'] !== inputs.SMTPAccount) { if (originInputs['SMTPAccount'] !== inputs.SMTPAccount) {
await updateOption('SMTPAccount', inputs.SMTPAccount); await updateOption('SMTPAccount', inputs.SMTPAccount);
} }
if (
originInputs['SMTPPort'] !== inputs.SMTPPort &&
inputs.SMTPPort !== ''
) {
await updateOption('SMTPPort', inputs.SMTPPort);
}
if ( if (
originInputs['SMTPToken'] !== inputs.SMTPToken && originInputs['SMTPToken'] !== inputs.SMTPToken &&
inputs.SMTPToken !== '' inputs.SMTPToken !== ''
@ -258,7 +265,7 @@ const SystemSetting = () => {
label='新用户初始配额' label='新用户初始配额'
name='QuotaForNewUser' name='QuotaForNewUser'
onChange={handleInputChange} onChange={handleInputChange}
autoComplete='off' autoComplete='new-password'
value={inputs.QuotaForNewUser} value={inputs.QuotaForNewUser}
type='number' type='number'
min='0' min='0'
@ -268,7 +275,7 @@ const SystemSetting = () => {
label='充值链接' label='充值链接'
name='TopUpLink' name='TopUpLink'
onChange={handleInputChange} onChange={handleInputChange}
autoComplete='off' autoComplete='new-password'
value={inputs.TopUpLink} value={inputs.TopUpLink}
type='link' type='link'
placeholder='例如发卡网站的购买链接' placeholder='例如发卡网站的购买链接'
@ -280,7 +287,7 @@ const SystemSetting = () => {
name='ModelRatio' name='ModelRatio'
onChange={handleInputChange} onChange={handleInputChange}
style={{ minHeight: 250, fontFamily: 'JetBrains Mono, Consolas' }} style={{ minHeight: 250, fontFamily: 'JetBrains Mono, Consolas' }}
autoComplete='off' autoComplete='new-password'
value={inputs.ModelRatio} value={inputs.ModelRatio}
placeholder='为一个 JSON 文本,键为模型名称,值为倍率' placeholder='为一个 JSON 文本,键为模型名称,值为倍率'
/> />
@ -291,20 +298,28 @@ const SystemSetting = () => {
配置 SMTP 配置 SMTP
<Header.Subheader>用以支持系统的邮件发送</Header.Subheader> <Header.Subheader>用以支持系统的邮件发送</Header.Subheader>
</Header> </Header>
<Form.Group widths={3}> <Form.Group widths={4}>
<Form.Input <Form.Input
label='SMTP 服务器地址' label='SMTP 服务器地址'
name='SMTPServer' name='SMTPServer'
onChange={handleInputChange} onChange={handleInputChange}
autoComplete='off' autoComplete='new-password'
value={inputs.SMTPServer} value={inputs.SMTPServer}
placeholder='例如smtp.qq.com' placeholder='例如smtp.qq.com'
/> />
<Form.Input
label='SMTP 端口'
name='SMTPPort'
onChange={handleInputChange}
autoComplete='new-password'
value={inputs.SMTPPort}
placeholder='默认: 587'
/>
<Form.Input <Form.Input
label='SMTP 账户' label='SMTP 账户'
name='SMTPAccount' name='SMTPAccount'
onChange={handleInputChange} onChange={handleInputChange}
autoComplete='off' autoComplete='new-password'
value={inputs.SMTPAccount} value={inputs.SMTPAccount}
placeholder='通常是邮箱地址' placeholder='通常是邮箱地址'
/> />
@ -313,7 +328,7 @@ const SystemSetting = () => {
name='SMTPToken' name='SMTPToken'
onChange={handleInputChange} onChange={handleInputChange}
type='password' type='password'
autoComplete='off' autoComplete='new-password'
value={inputs.SMTPToken} value={inputs.SMTPToken}
placeholder='敏感信息不会发送到前端显示' placeholder='敏感信息不会发送到前端显示'
/> />
@ -340,7 +355,7 @@ const SystemSetting = () => {
label='GitHub Client ID' label='GitHub Client ID'
name='GitHubClientId' name='GitHubClientId'
onChange={handleInputChange} onChange={handleInputChange}
autoComplete='off' autoComplete='new-password'
value={inputs.GitHubClientId} value={inputs.GitHubClientId}
placeholder='输入你注册的 GitHub OAuth APP 的 ID' placeholder='输入你注册的 GitHub OAuth APP 的 ID'
/> />
@ -349,7 +364,7 @@ const SystemSetting = () => {
name='GitHubClientSecret' name='GitHubClientSecret'
onChange={handleInputChange} onChange={handleInputChange}
type='password' type='password'
autoComplete='off' autoComplete='new-password'
value={inputs.GitHubClientSecret} value={inputs.GitHubClientSecret}
placeholder='敏感信息不会发送到前端显示' placeholder='敏感信息不会发送到前端显示'
/> />
@ -377,7 +392,7 @@ const SystemSetting = () => {
name='WeChatServerAddress' name='WeChatServerAddress'
placeholder='例如https://yourdomain.com' placeholder='例如https://yourdomain.com'
onChange={handleInputChange} onChange={handleInputChange}
autoComplete='off' autoComplete='new-password'
value={inputs.WeChatServerAddress} value={inputs.WeChatServerAddress}
/> />
<Form.Input <Form.Input
@ -385,7 +400,7 @@ const SystemSetting = () => {
name='WeChatServerToken' name='WeChatServerToken'
type='password' type='password'
onChange={handleInputChange} onChange={handleInputChange}
autoComplete='off' autoComplete='new-password'
value={inputs.WeChatServerToken} value={inputs.WeChatServerToken}
placeholder='敏感信息不会发送到前端显示' placeholder='敏感信息不会发送到前端显示'
/> />
@ -393,7 +408,7 @@ const SystemSetting = () => {
label='微信公众号二维码图片链接' label='微信公众号二维码图片链接'
name='WeChatAccountQRCodeImageURL' name='WeChatAccountQRCodeImageURL'
onChange={handleInputChange} onChange={handleInputChange}
autoComplete='off' autoComplete='new-password'
value={inputs.WeChatAccountQRCodeImageURL} value={inputs.WeChatAccountQRCodeImageURL}
placeholder='输入一个图片链接' placeholder='输入一个图片链接'
/> />
@ -417,7 +432,7 @@ const SystemSetting = () => {
label='Turnstile Site Key' label='Turnstile Site Key'
name='TurnstileSiteKey' name='TurnstileSiteKey'
onChange={handleInputChange} onChange={handleInputChange}
autoComplete='off' autoComplete='new-password'
value={inputs.TurnstileSiteKey} value={inputs.TurnstileSiteKey}
placeholder='输入你注册的 Turnstile Site Key' placeholder='输入你注册的 Turnstile Site Key'
/> />
@ -426,7 +441,7 @@ const SystemSetting = () => {
name='TurnstileSecretKey' name='TurnstileSecretKey'
onChange={handleInputChange} onChange={handleInputChange}
type='password' type='password'
autoComplete='off' autoComplete='new-password'
value={inputs.TurnstileSecretKey} value={inputs.TurnstileSecretKey}
placeholder='敏感信息不会发送到前端显示' placeholder='敏感信息不会发送到前端显示'
/> />

View File

@ -36,7 +36,7 @@ const AddChannel = () => {
<> <>
<Segment> <Segment>
<Header as='h3'>创建新的渠道</Header> <Header as='h3'>创建新的渠道</Header>
<Form autoComplete='off'> <Form autoComplete='new-password'>
<Form.Field> <Form.Field>
<Form.Select <Form.Select
label='类型' label='类型'
@ -55,7 +55,7 @@ const AddChannel = () => {
placeholder={'请输入自定义渠道的 Base URL例如https://openai.justsong.cn'} placeholder={'请输入自定义渠道的 Base URL例如https://openai.justsong.cn'}
onChange={handleInputChange} onChange={handleInputChange}
value={inputs.base_url} value={inputs.base_url}
autoComplete='off' autoComplete='new-password'
/> />
</Form.Field> </Form.Field>
) )
@ -67,7 +67,7 @@ const AddChannel = () => {
placeholder={'请输入名称'} placeholder={'请输入名称'}
onChange={handleInputChange} onChange={handleInputChange}
value={name} value={name}
autoComplete='off' autoComplete='new-password'
required required
/> />
</Form.Field> </Form.Field>
@ -79,7 +79,7 @@ const AddChannel = () => {
onChange={handleInputChange} onChange={handleInputChange}
value={key} value={key}
// type='password' // type='password'
autoComplete='off' autoComplete='new-password'
required required
/> />
</Form.Field> </Form.Field>

View File

@ -50,7 +50,7 @@ const EditChannel = () => {
<> <>
<Segment loading={loading}> <Segment loading={loading}>
<Header as='h3'>更新渠道信息</Header> <Header as='h3'>更新渠道信息</Header>
<Form autoComplete='off'> <Form autoComplete='new-password'>
<Form.Field> <Form.Field>
<Form.Select <Form.Select
label='类型' label='类型'
@ -69,7 +69,7 @@ const EditChannel = () => {
placeholder={'请输入新的自定义渠道的 Base URL例如https://openai.justsong.cn'} placeholder={'请输入新的自定义渠道的 Base URL例如https://openai.justsong.cn'}
onChange={handleInputChange} onChange={handleInputChange}
value={inputs.base_url} value={inputs.base_url}
autoComplete='off' autoComplete='new-password'
/> />
</Form.Field> </Form.Field>
) )
@ -81,7 +81,7 @@ const EditChannel = () => {
placeholder={'请输入新的名称'} placeholder={'请输入新的名称'}
onChange={handleInputChange} onChange={handleInputChange}
value={inputs.name} value={inputs.name}
autoComplete='off' autoComplete='new-password'
/> />
</Form.Field> </Form.Field>
<Form.Field> <Form.Field>
@ -92,7 +92,7 @@ const EditChannel = () => {
onChange={handleInputChange} onChange={handleInputChange}
value={inputs.key} value={inputs.key}
// type='password' // type='password'
autoComplete='off' autoComplete='new-password'
/> />
</Form.Field> </Form.Field>
<Button onClick={submit}>提交</Button> <Button onClick={submit}>提交</Button>

View File

@ -73,7 +73,7 @@ const EditRedemption = () => {
<> <>
<Segment loading={loading}> <Segment loading={loading}>
<Header as='h3'>{isEdit ? '更新兑换码信息' : '创建新的兑换码'}</Header> <Header as='h3'>{isEdit ? '更新兑换码信息' : '创建新的兑换码'}</Header>
<Form autoComplete='off'> <Form autoComplete='new-password'>
<Form.Field> <Form.Field>
<Form.Input <Form.Input
label='名称' label='名称'
@ -81,7 +81,7 @@ const EditRedemption = () => {
placeholder={'请输入名称'} placeholder={'请输入名称'}
onChange={handleInputChange} onChange={handleInputChange}
value={name} value={name}
autoComplete='off' autoComplete='new-password'
required={!isEdit} required={!isEdit}
/> />
</Form.Field> </Form.Field>
@ -92,7 +92,7 @@ const EditRedemption = () => {
placeholder={'请输入单个兑换码中包含的额度'} placeholder={'请输入单个兑换码中包含的额度'}
onChange={handleInputChange} onChange={handleInputChange}
value={quota} value={quota}
autoComplete='off' autoComplete='new-password'
type='number' type='number'
/> />
</Form.Field> </Form.Field>
@ -105,7 +105,7 @@ const EditRedemption = () => {
placeholder={'请输入生成数量'} placeholder={'请输入生成数量'}
onChange={handleInputChange} onChange={handleInputChange}
value={count} value={count}
autoComplete='off' autoComplete='new-password'
type='number' type='number'
/> />
</Form.Field> </Form.Field>

View File

@ -95,7 +95,7 @@ const EditToken = () => {
<> <>
<Segment loading={loading}> <Segment loading={loading}>
<Header as='h3'>{isEdit ? '更新令牌信息' : '创建新的令牌'}</Header> <Header as='h3'>{isEdit ? '更新令牌信息' : '创建新的令牌'}</Header>
<Form autoComplete='off'> <Form autoComplete='new-password'>
<Form.Field> <Form.Field>
<Form.Input <Form.Input
label='名称' label='名称'
@ -103,7 +103,7 @@ const EditToken = () => {
placeholder={'请输入名称'} placeholder={'请输入名称'}
onChange={handleInputChange} onChange={handleInputChange}
value={name} value={name}
autoComplete='off' autoComplete='new-password'
required={!isEdit} required={!isEdit}
/> />
</Form.Field> </Form.Field>
@ -116,7 +116,7 @@ const EditToken = () => {
placeholder={'请输入额度'} placeholder={'请输入额度'}
onChange={handleInputChange} onChange={handleInputChange}
value={remain_quota} value={remain_quota}
autoComplete='off' autoComplete='new-password'
type='number' type='number'
disabled={unlimited_quota} disabled={unlimited_quota}
/> />
@ -133,7 +133,7 @@ const EditToken = () => {
placeholder={'请输入过期时间,格式为 yyyy-MM-dd HH:mm:ss-1 表示无限制'} placeholder={'请输入过期时间,格式为 yyyy-MM-dd HH:mm:ss-1 表示无限制'}
onChange={handleInputChange} onChange={handleInputChange}
value={expired_time} value={expired_time}
autoComplete='off' autoComplete='new-password'
type='datetime-local' type='datetime-local'
/> />
</Form.Field> </Form.Field>

View File

@ -60,7 +60,7 @@ const EditUser = () => {
<> <>
<Segment loading={loading}> <Segment loading={loading}>
<Header as='h3'>更新用户信息</Header> <Header as='h3'>更新用户信息</Header>
<Form autoComplete='off'> <Form autoComplete='new-password'>
<Form.Field> <Form.Field>
<Form.Input <Form.Input
label='用户名' label='用户名'
@ -68,7 +68,7 @@ const EditUser = () => {
placeholder={'请输入新的用户名'} placeholder={'请输入新的用户名'}
onChange={handleInputChange} onChange={handleInputChange}
value={username} value={username}
autoComplete='off' autoComplete='new-password'
/> />
</Form.Field> </Form.Field>
<Form.Field> <Form.Field>
@ -79,7 +79,7 @@ const EditUser = () => {
placeholder={'请输入新的密码'} placeholder={'请输入新的密码'}
onChange={handleInputChange} onChange={handleInputChange}
value={password} value={password}
autoComplete='off' autoComplete='new-password'
/> />
</Form.Field> </Form.Field>
<Form.Field> <Form.Field>
@ -89,7 +89,7 @@ const EditUser = () => {
placeholder={'请输入新的显示名称'} placeholder={'请输入新的显示名称'}
onChange={handleInputChange} onChange={handleInputChange}
value={display_name} value={display_name}
autoComplete='off' autoComplete='new-password'
/> />
</Form.Field> </Form.Field>
<Form.Field> <Form.Field>
@ -97,7 +97,7 @@ const EditUser = () => {
label='已绑定的 GitHub 账户' label='已绑定的 GitHub 账户'
name='github_id' name='github_id'
value={github_id} value={github_id}
autoComplete='off' autoComplete='new-password'
placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改' placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改'
readOnly readOnly
/> />
@ -107,7 +107,7 @@ const EditUser = () => {
label='已绑定的微信账户' label='已绑定的微信账户'
name='wechat_id' name='wechat_id'
value={wechat_id} value={wechat_id}
autoComplete='off' autoComplete='new-password'
placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改' placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改'
readOnly readOnly
/> />
@ -117,7 +117,7 @@ const EditUser = () => {
label='已绑定的邮箱账户' label='已绑定的邮箱账户'
name='email' name='email'
value={email} value={email}
autoComplete='off' autoComplete='new-password'
placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改' placeholder='此项只读,需要用户通过个人设置页面的相关绑定按钮进行绑定,不可直接修改'
readOnly readOnly
/> />