Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cf8d4e87
authored
Nov 22, 2025
by
StageDog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 针对 discord 登录配置使用新版设置方案
parent
352801cd
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
36 deletions
+44
-36
common/constants.go
+0
-3
controller/discord.go
+5
-6
controller/misc.go
+2
-2
controller/option.go
+2
-2
model/option.go
+0
-9
setting/system_setting/discord.go
+21
-0
web/src/components/settings/SystemSetting.jsx
+14
-14
No files found.
common/constants.go
View file @
cf8d4e87
...
@@ -44,7 +44,6 @@ var PasswordLoginEnabled = true
...
@@ -44,7 +44,6 @@ var PasswordLoginEnabled = true
var
PasswordRegisterEnabled
=
true
var
PasswordRegisterEnabled
=
true
var
EmailVerificationEnabled
=
false
var
EmailVerificationEnabled
=
false
var
GitHubOAuthEnabled
=
false
var
GitHubOAuthEnabled
=
false
var
DiscordOAuthEnabled
=
false
var
LinuxDOOAuthEnabled
=
false
var
LinuxDOOAuthEnabled
=
false
var
WeChatAuthEnabled
=
false
var
WeChatAuthEnabled
=
false
var
TelegramOAuthEnabled
=
false
var
TelegramOAuthEnabled
=
false
...
@@ -83,8 +82,6 @@ var SMTPToken = ""
...
@@ -83,8 +82,6 @@ var SMTPToken = ""
var
GitHubClientId
=
""
var
GitHubClientId
=
""
var
GitHubClientSecret
=
""
var
GitHubClientSecret
=
""
var
DiscordClientId
=
""
var
DiscordClientSecret
=
""
var
LinuxDOClientId
=
""
var
LinuxDOClientId
=
""
var
LinuxDOClientSecret
=
""
var
LinuxDOClientSecret
=
""
var
LinuxDOMinimumTrustLevel
=
0
var
LinuxDOMinimumTrustLevel
=
0
...
...
controller/discord.go
View file @
cf8d4e87
...
@@ -39,8 +39,8 @@ func getDiscordUserInfoByCode(code string) (*DiscordUser, error) {
...
@@ -39,8 +39,8 @@ func getDiscordUserInfoByCode(code string) (*DiscordUser, error) {
}
}
values
:=
url
.
Values
{}
values
:=
url
.
Values
{}
values
.
Set
(
"client_id"
,
common
.
Discord
ClientId
)
values
.
Set
(
"client_id"
,
system_setting
.
GetDiscordSettings
()
.
ClientId
)
values
.
Set
(
"client_secret"
,
common
.
Discord
ClientSecret
)
values
.
Set
(
"client_secret"
,
system_setting
.
GetDiscordSettings
()
.
ClientSecret
)
values
.
Set
(
"code"
,
code
)
values
.
Set
(
"code"
,
code
)
values
.
Set
(
"grant_type"
,
"authorization_code"
)
values
.
Set
(
"grant_type"
,
"authorization_code"
)
values
.
Set
(
"redirect_uri"
,
fmt
.
Sprintf
(
"%s/oauth/discord"
,
system_setting
.
ServerAddress
))
values
.
Set
(
"redirect_uri"
,
fmt
.
Sprintf
(
"%s/oauth/discord"
,
system_setting
.
ServerAddress
))
...
@@ -114,10 +114,10 @@ func DiscordOAuth(c *gin.Context) {
...
@@ -114,10 +114,10 @@ func DiscordOAuth(c *gin.Context) {
DiscordBind
(
c
)
DiscordBind
(
c
)
return
return
}
}
if
!
common
.
DiscordOAuth
Enabled
{
if
!
system_setting
.
GetDiscordSettings
()
.
Enabled
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"success"
:
false
,
"message"
:
"管理员未开启通过
d
iscord 登录以及注册"
,
"message"
:
"管理员未开启通过
D
iscord 登录以及注册"
,
})
})
return
return
}
}
...
@@ -179,7 +179,7 @@ func DiscordOAuth(c *gin.Context) {
...
@@ -179,7 +179,7 @@ func DiscordOAuth(c *gin.Context) {
}
}
func
DiscordBind
(
c
*
gin
.
Context
)
{
func
DiscordBind
(
c
*
gin
.
Context
)
{
if
!
common
.
DiscordOAuth
Enabled
{
if
!
system_setting
.
GetDiscordSettings
()
.
Enabled
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"success"
:
false
,
"message"
:
"管理员未开启通过 Discord 登录以及注册"
,
"message"
:
"管理员未开启通过 Discord 登录以及注册"
,
...
@@ -204,7 +204,6 @@ func DiscordBind(c *gin.Context) {
...
@@ -204,7 +204,6 @@ func DiscordBind(c *gin.Context) {
}
}
session
:=
sessions
.
Default
(
c
)
session
:=
sessions
.
Default
(
c
)
id
:=
session
.
Get
(
"id"
)
id
:=
session
.
Get
(
"id"
)
// id := c.GetInt("id") // critical bug!
user
.
Id
=
id
.
(
int
)
user
.
Id
=
id
.
(
int
)
err
=
user
.
FillUserById
()
err
=
user
.
FillUserById
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
controller/misc.go
View file @
cf8d4e87
...
@@ -52,8 +52,8 @@ func GetStatus(c *gin.Context) {
...
@@ -52,8 +52,8 @@ func GetStatus(c *gin.Context) {
"email_verification"
:
common
.
EmailVerificationEnabled
,
"email_verification"
:
common
.
EmailVerificationEnabled
,
"github_oauth"
:
common
.
GitHubOAuthEnabled
,
"github_oauth"
:
common
.
GitHubOAuthEnabled
,
"github_client_id"
:
common
.
GitHubClientId
,
"github_client_id"
:
common
.
GitHubClientId
,
"discord_oauth"
:
common
.
DiscordOAuth
Enabled
,
"discord_oauth"
:
system_setting
.
GetDiscordSettings
()
.
Enabled
,
"discord_client_id"
:
common
.
Discord
ClientId
,
"discord_client_id"
:
system_setting
.
GetDiscordSettings
()
.
ClientId
,
"linuxdo_oauth"
:
common
.
LinuxDOOAuthEnabled
,
"linuxdo_oauth"
:
common
.
LinuxDOOAuthEnabled
,
"linuxdo_client_id"
:
common
.
LinuxDOClientId
,
"linuxdo_client_id"
:
common
.
LinuxDOClientId
,
"linuxdo_minimum_trust_level"
:
common
.
LinuxDOMinimumTrustLevel
,
"linuxdo_minimum_trust_level"
:
common
.
LinuxDOMinimumTrustLevel
,
...
...
controller/option.go
View file @
cf8d4e87
...
@@ -71,8 +71,8 @@ func UpdateOption(c *gin.Context) {
...
@@ -71,8 +71,8 @@ func UpdateOption(c *gin.Context) {
})
})
return
return
}
}
case
"
DiscordOAuthE
nabled"
:
case
"
discord.e
nabled"
:
if
option
.
Value
==
"true"
&&
common
.
Discord
ClientId
==
""
{
if
option
.
Value
==
"true"
&&
system_setting
.
GetDiscordSettings
()
.
ClientId
==
""
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"success"
:
false
,
"message"
:
"无法启用 Discord OAuth,请先填入 Discord Client Id 以及 Discord Client Secret!"
,
"message"
:
"无法启用 Discord OAuth,请先填入 Discord Client Id 以及 Discord Client Secret!"
,
...
...
model/option.go
View file @
cf8d4e87
...
@@ -38,7 +38,6 @@ func InitOptionMap() {
...
@@ -38,7 +38,6 @@ func InitOptionMap() {
common
.
OptionMap
[
"PasswordRegisterEnabled"
]
=
strconv
.
FormatBool
(
common
.
PasswordRegisterEnabled
)
common
.
OptionMap
[
"PasswordRegisterEnabled"
]
=
strconv
.
FormatBool
(
common
.
PasswordRegisterEnabled
)
common
.
OptionMap
[
"EmailVerificationEnabled"
]
=
strconv
.
FormatBool
(
common
.
EmailVerificationEnabled
)
common
.
OptionMap
[
"EmailVerificationEnabled"
]
=
strconv
.
FormatBool
(
common
.
EmailVerificationEnabled
)
common
.
OptionMap
[
"GitHubOAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
GitHubOAuthEnabled
)
common
.
OptionMap
[
"GitHubOAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
GitHubOAuthEnabled
)
common
.
OptionMap
[
"DiscordOAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
DiscordOAuthEnabled
)
common
.
OptionMap
[
"LinuxDOOAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
LinuxDOOAuthEnabled
)
common
.
OptionMap
[
"LinuxDOOAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
LinuxDOOAuthEnabled
)
common
.
OptionMap
[
"TelegramOAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
TelegramOAuthEnabled
)
common
.
OptionMap
[
"TelegramOAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
TelegramOAuthEnabled
)
common
.
OptionMap
[
"WeChatAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
WeChatAuthEnabled
)
common
.
OptionMap
[
"WeChatAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
WeChatAuthEnabled
)
...
@@ -96,8 +95,6 @@ func InitOptionMap() {
...
@@ -96,8 +95,6 @@ func InitOptionMap() {
common
.
OptionMap
[
"PayMethods"
]
=
operation_setting
.
PayMethods2JsonString
()
common
.
OptionMap
[
"PayMethods"
]
=
operation_setting
.
PayMethods2JsonString
()
common
.
OptionMap
[
"GitHubClientId"
]
=
""
common
.
OptionMap
[
"GitHubClientId"
]
=
""
common
.
OptionMap
[
"GitHubClientSecret"
]
=
""
common
.
OptionMap
[
"GitHubClientSecret"
]
=
""
common
.
OptionMap
[
"DiscordClientId"
]
=
""
common
.
OptionMap
[
"DiscordClientSecret"
]
=
""
common
.
OptionMap
[
"TelegramBotToken"
]
=
""
common
.
OptionMap
[
"TelegramBotToken"
]
=
""
common
.
OptionMap
[
"TelegramBotName"
]
=
""
common
.
OptionMap
[
"TelegramBotName"
]
=
""
common
.
OptionMap
[
"WeChatServerAddress"
]
=
""
common
.
OptionMap
[
"WeChatServerAddress"
]
=
""
...
@@ -227,8 +224,6 @@ func updateOptionMap(key string, value string) (err error) {
...
@@ -227,8 +224,6 @@ func updateOptionMap(key string, value string) (err error) {
common
.
EmailVerificationEnabled
=
boolValue
common
.
EmailVerificationEnabled
=
boolValue
case
"GitHubOAuthEnabled"
:
case
"GitHubOAuthEnabled"
:
common
.
GitHubOAuthEnabled
=
boolValue
common
.
GitHubOAuthEnabled
=
boolValue
case
"DiscordOAuthEnabled"
:
common
.
DiscordOAuthEnabled
=
boolValue
case
"LinuxDOOAuthEnabled"
:
case
"LinuxDOOAuthEnabled"
:
common
.
LinuxDOOAuthEnabled
=
boolValue
common
.
LinuxDOOAuthEnabled
=
boolValue
case
"WeChatAuthEnabled"
:
case
"WeChatAuthEnabled"
:
...
@@ -365,10 +360,6 @@ func updateOptionMap(key string, value string) (err error) {
...
@@ -365,10 +360,6 @@ func updateOptionMap(key string, value string) (err error) {
common
.
GitHubClientId
=
value
common
.
GitHubClientId
=
value
case
"GitHubClientSecret"
:
case
"GitHubClientSecret"
:
common
.
GitHubClientSecret
=
value
common
.
GitHubClientSecret
=
value
case
"DiscordClientId"
:
common
.
DiscordClientId
=
value
case
"DiscordClientSecret"
:
common
.
DiscordClientSecret
=
value
case
"LinuxDOClientId"
:
case
"LinuxDOClientId"
:
common
.
LinuxDOClientId
=
value
common
.
LinuxDOClientId
=
value
case
"LinuxDOClientSecret"
:
case
"LinuxDOClientSecret"
:
...
...
setting/system_setting/discord.go
0 → 100644
View file @
cf8d4e87
package
system_setting
import
"github.com/QuantumNous/new-api/setting/config"
type
DiscordSettings
struct
{
Enabled
bool
`json:"enabled"`
ClientId
string
`json:"client_id"`
ClientSecret
string
`json:"client_secret"`
}
// 默认配置
var
defaultDiscordSettings
=
DiscordSettings
{}
func
init
()
{
// 注册到全局配置管理器
config
.
GlobalConfig
.
Register
(
"discord"
,
&
defaultDiscordSettings
)
}
func
GetDiscordSettings
()
*
DiscordSettings
{
return
&
defaultDiscordSettings
}
web/src/components/settings/SystemSetting.jsx
View file @
cf8d4e87
...
@@ -52,9 +52,9 @@ const SystemSetting = () => {
...
@@ -52,9 +52,9 @@ const SystemSetting = () => {
GitHubOAuthEnabled
:
''
,
GitHubOAuthEnabled
:
''
,
GitHubClientId
:
''
,
GitHubClientId
:
''
,
GitHubClientSecret
:
''
,
GitHubClientSecret
:
''
,
DiscordOAuthEnabled
:
''
,
'discord.enabled'
:
''
,
DiscordClientId
:
''
,
'discord.client_id'
:
''
,
DiscordClientSecret
:
''
,
'discord.client_secret'
:
''
,
'oidc.enabled'
:
''
,
'oidc.enabled'
:
''
,
'oidc.client_id'
:
''
,
'oidc.client_id'
:
''
,
'oidc.client_secret'
:
''
,
'oidc.client_secret'
:
''
,
...
@@ -182,7 +182,7 @@ const SystemSetting = () => {
...
@@ -182,7 +182,7 @@ const SystemSetting = () => {
case
'EmailAliasRestrictionEnabled'
:
case
'EmailAliasRestrictionEnabled'
:
case
'SMTPSSLEnabled'
:
case
'SMTPSSLEnabled'
:
case
'LinuxDOOAuthEnabled'
:
case
'LinuxDOOAuthEnabled'
:
case
'
DiscordOAuthE
nabled'
:
case
'
discord.e
nabled'
:
case
'oidc.enabled'
:
case
'oidc.enabled'
:
case
'passkey.enabled'
:
case
'passkey.enabled'
:
case
'passkey.allow_insecure_origin'
:
case
'passkey.allow_insecure_origin'
:
...
@@ -480,16 +480,16 @@ const SystemSetting = () => {
...
@@ -480,16 +480,16 @@ const SystemSetting = () => {
const
submitDiscordOAuth
=
async
()
=>
{
const
submitDiscordOAuth
=
async
()
=>
{
const
options
=
[];
const
options
=
[];
if
(
originInputs
[
'
DiscordClientId'
]
!==
inputs
.
DiscordClientId
)
{
if
(
originInputs
[
'
discord.client_id'
]
!==
inputs
[
'discord.client_id'
]
)
{
options
.
push
({
key
:
'
DiscordClientId'
,
value
:
inputs
.
DiscordClientId
});
options
.
push
({
key
:
'
discord.client_id'
,
value
:
inputs
[
'discord.client_id'
]
});
}
}
if
(
if
(
originInputs
[
'
DiscordClientSecret'
]
!==
inputs
.
DiscordClientSecret
&&
originInputs
[
'
discord.client_secret'
]
!==
inputs
[
'discord.client_secret'
]
&&
inputs
.
DiscordClientSecret
!==
''
inputs
[
'discord.client_secret'
]
!==
''
)
{
)
{
options
.
push
({
options
.
push
({
key
:
'
DiscordClientS
ecret'
,
key
:
'
discord.client_s
ecret'
,
value
:
inputs
.
DiscordClientSecret
,
value
:
inputs
[
'discord.client_secret'
]
,
});
});
}
}
...
@@ -1040,10 +1040,10 @@ const SystemSetting = () => {
...
@@ -1040,10 +1040,10 @@ const SystemSetting = () => {
{
t
(
'允许通过 GitHub 账户登录 & 注册'
)
}
{
t
(
'允许通过 GitHub 账户登录 & 注册'
)
}
</
Form
.
Checkbox
>
</
Form
.
Checkbox
>
<
Form
.
Checkbox
<
Form
.
Checkbox
field=
'
DiscordOAuthE
nabled'
field=
'
discord.e
nabled'
noLabel
noLabel
onChange=
{
(
e
)
=>
onChange=
{
(
e
)
=>
handleCheckboxChange
(
'
DiscordOAuthE
nabled'
,
e
)
handleCheckboxChange
(
'
discord.e
nabled'
,
e
)
}
}
>
>
{
t
(
'允许通过 Discord 账户登录 & 注册'
)
}
{
t
(
'允许通过 Discord 账户登录 & 注册'
)
}
...
@@ -1457,13 +1457,13 @@ const SystemSetting = () => {
...
@@ -1457,13 +1457,13 @@ const SystemSetting = () => {
>
>
<
Col
xs=
{
24
}
sm=
{
24
}
md=
{
12
}
lg=
{
12
}
xl=
{
12
}
>
<
Col
xs=
{
24
}
sm=
{
24
}
md=
{
12
}
lg=
{
12
}
xl=
{
12
}
>
<
Form
.
Input
<
Form
.
Input
field=
'DiscordClientId'
field=
"['discord.client_id']"
label=
{
t
(
'Discord Client ID'
)
}
label=
{
t
(
'Discord Client ID'
)
}
/>
/>
</
Col
>
</
Col
>
<
Col
xs=
{
24
}
sm=
{
24
}
md=
{
12
}
lg=
{
12
}
xl=
{
12
}
>
<
Col
xs=
{
24
}
sm=
{
24
}
md=
{
12
}
lg=
{
12
}
xl=
{
12
}
>
<
Form
.
Input
<
Form
.
Input
field=
'DiscordClientSecret'
field=
"['discord.client_secret']"
label=
{
t
(
'Discord Client Secret'
)
}
label=
{
t
(
'Discord Client Secret'
)
}
type=
'password'
type=
'password'
placeholder=
{
t
(
'敏感信息不会发送到前端显示'
)
}
placeholder=
{
t
(
'敏感信息不会发送到前端显示'
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment