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
Hide 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
var
PasswordRegisterEnabled
=
true
var
EmailVerificationEnabled
=
false
var
GitHubOAuthEnabled
=
false
var
DiscordOAuthEnabled
=
false
var
LinuxDOOAuthEnabled
=
false
var
WeChatAuthEnabled
=
false
var
TelegramOAuthEnabled
=
false
...
...
@@ -83,8 +82,6 @@ var SMTPToken = ""
var
GitHubClientId
=
""
var
GitHubClientSecret
=
""
var
DiscordClientId
=
""
var
DiscordClientSecret
=
""
var
LinuxDOClientId
=
""
var
LinuxDOClientSecret
=
""
var
LinuxDOMinimumTrustLevel
=
0
...
...
controller/discord.go
View file @
cf8d4e87
...
...
@@ -39,8 +39,8 @@ func getDiscordUserInfoByCode(code string) (*DiscordUser, error) {
}
values
:=
url
.
Values
{}
values
.
Set
(
"client_id"
,
common
.
Discord
ClientId
)
values
.
Set
(
"client_secret"
,
common
.
Discord
ClientSecret
)
values
.
Set
(
"client_id"
,
system_setting
.
GetDiscordSettings
()
.
ClientId
)
values
.
Set
(
"client_secret"
,
system_setting
.
GetDiscordSettings
()
.
ClientSecret
)
values
.
Set
(
"code"
,
code
)
values
.
Set
(
"grant_type"
,
"authorization_code"
)
values
.
Set
(
"redirect_uri"
,
fmt
.
Sprintf
(
"%s/oauth/discord"
,
system_setting
.
ServerAddress
))
...
...
@@ -114,10 +114,10 @@ func DiscordOAuth(c *gin.Context) {
DiscordBind
(
c
)
return
}
if
!
common
.
DiscordOAuth
Enabled
{
if
!
system_setting
.
GetDiscordSettings
()
.
Enabled
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
"管理员未开启通过
d
iscord 登录以及注册"
,
"message"
:
"管理员未开启通过
D
iscord 登录以及注册"
,
})
return
}
...
...
@@ -179,7 +179,7 @@ func DiscordOAuth(c *gin.Context) {
}
func
DiscordBind
(
c
*
gin
.
Context
)
{
if
!
common
.
DiscordOAuth
Enabled
{
if
!
system_setting
.
GetDiscordSettings
()
.
Enabled
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
"管理员未开启通过 Discord 登录以及注册"
,
...
...
@@ -204,7 +204,6 @@ func DiscordBind(c *gin.Context) {
}
session
:=
sessions
.
Default
(
c
)
id
:=
session
.
Get
(
"id"
)
// id := c.GetInt("id") // critical bug!
user
.
Id
=
id
.
(
int
)
err
=
user
.
FillUserById
()
if
err
!=
nil
{
...
...
controller/misc.go
View file @
cf8d4e87
...
...
@@ -52,8 +52,8 @@ func GetStatus(c *gin.Context) {
"email_verification"
:
common
.
EmailVerificationEnabled
,
"github_oauth"
:
common
.
GitHubOAuthEnabled
,
"github_client_id"
:
common
.
GitHubClientId
,
"discord_oauth"
:
common
.
DiscordOAuth
Enabled
,
"discord_client_id"
:
common
.
Discord
ClientId
,
"discord_oauth"
:
system_setting
.
GetDiscordSettings
()
.
Enabled
,
"discord_client_id"
:
system_setting
.
GetDiscordSettings
()
.
ClientId
,
"linuxdo_oauth"
:
common
.
LinuxDOOAuthEnabled
,
"linuxdo_client_id"
:
common
.
LinuxDOClientId
,
"linuxdo_minimum_trust_level"
:
common
.
LinuxDOMinimumTrustLevel
,
...
...
controller/option.go
View file @
cf8d4e87
...
...
@@ -71,8 +71,8 @@ func UpdateOption(c *gin.Context) {
})
return
}
case
"
DiscordOAuthE
nabled"
:
if
option
.
Value
==
"true"
&&
common
.
Discord
ClientId
==
""
{
case
"
discord.e
nabled"
:
if
option
.
Value
==
"true"
&&
system_setting
.
GetDiscordSettings
()
.
ClientId
==
""
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
"无法启用 Discord OAuth,请先填入 Discord Client Id 以及 Discord Client Secret!"
,
...
...
model/option.go
View file @
cf8d4e87
...
...
@@ -38,7 +38,6 @@ func InitOptionMap() {
common
.
OptionMap
[
"PasswordRegisterEnabled"
]
=
strconv
.
FormatBool
(
common
.
PasswordRegisterEnabled
)
common
.
OptionMap
[
"EmailVerificationEnabled"
]
=
strconv
.
FormatBool
(
common
.
EmailVerificationEnabled
)
common
.
OptionMap
[
"GitHubOAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
GitHubOAuthEnabled
)
common
.
OptionMap
[
"DiscordOAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
DiscordOAuthEnabled
)
common
.
OptionMap
[
"LinuxDOOAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
LinuxDOOAuthEnabled
)
common
.
OptionMap
[
"TelegramOAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
TelegramOAuthEnabled
)
common
.
OptionMap
[
"WeChatAuthEnabled"
]
=
strconv
.
FormatBool
(
common
.
WeChatAuthEnabled
)
...
...
@@ -96,8 +95,6 @@ func InitOptionMap() {
common
.
OptionMap
[
"PayMethods"
]
=
operation_setting
.
PayMethods2JsonString
()
common
.
OptionMap
[
"GitHubClientId"
]
=
""
common
.
OptionMap
[
"GitHubClientSecret"
]
=
""
common
.
OptionMap
[
"DiscordClientId"
]
=
""
common
.
OptionMap
[
"DiscordClientSecret"
]
=
""
common
.
OptionMap
[
"TelegramBotToken"
]
=
""
common
.
OptionMap
[
"TelegramBotName"
]
=
""
common
.
OptionMap
[
"WeChatServerAddress"
]
=
""
...
...
@@ -227,8 +224,6 @@ func updateOptionMap(key string, value string) (err error) {
common
.
EmailVerificationEnabled
=
boolValue
case
"GitHubOAuthEnabled"
:
common
.
GitHubOAuthEnabled
=
boolValue
case
"DiscordOAuthEnabled"
:
common
.
DiscordOAuthEnabled
=
boolValue
case
"LinuxDOOAuthEnabled"
:
common
.
LinuxDOOAuthEnabled
=
boolValue
case
"WeChatAuthEnabled"
:
...
...
@@ -365,10 +360,6 @@ func updateOptionMap(key string, value string) (err error) {
common
.
GitHubClientId
=
value
case
"GitHubClientSecret"
:
common
.
GitHubClientSecret
=
value
case
"DiscordClientId"
:
common
.
DiscordClientId
=
value
case
"DiscordClientSecret"
:
common
.
DiscordClientSecret
=
value
case
"LinuxDOClientId"
:
common
.
LinuxDOClientId
=
value
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 = () => {
GitHubOAuthEnabled
:
''
,
GitHubClientId
:
''
,
GitHubClientSecret
:
''
,
DiscordOAuthEnabled
:
''
,
DiscordClientId
:
''
,
DiscordClientSecret
:
''
,
'discord.enabled'
:
''
,
'discord.client_id'
:
''
,
'discord.client_secret'
:
''
,
'oidc.enabled'
:
''
,
'oidc.client_id'
:
''
,
'oidc.client_secret'
:
''
,
...
...
@@ -182,7 +182,7 @@ const SystemSetting = () => {
case
'EmailAliasRestrictionEnabled'
:
case
'SMTPSSLEnabled'
:
case
'LinuxDOOAuthEnabled'
:
case
'
DiscordOAuthE
nabled'
:
case
'
discord.e
nabled'
:
case
'oidc.enabled'
:
case
'passkey.enabled'
:
case
'passkey.allow_insecure_origin'
:
...
...
@@ -480,16 +480,16 @@ const SystemSetting = () => {
const
submitDiscordOAuth
=
async
()
=>
{
const
options
=
[];
if
(
originInputs
[
'
DiscordClientId'
]
!==
inputs
.
DiscordClientId
)
{
options
.
push
({
key
:
'
DiscordClientId'
,
value
:
inputs
.
DiscordClientId
});
if
(
originInputs
[
'
discord.client_id'
]
!==
inputs
[
'discord.client_id'
]
)
{
options
.
push
({
key
:
'
discord.client_id'
,
value
:
inputs
[
'discord.client_id'
]
});
}
if
(
originInputs
[
'
DiscordClientSecret'
]
!==
inputs
.
DiscordClientSecret
&&
inputs
.
DiscordClientSecret
!==
''
originInputs
[
'
discord.client_secret'
]
!==
inputs
[
'discord.client_secret'
]
&&
inputs
[
'discord.client_secret'
]
!==
''
)
{
options
.
push
({
key
:
'
DiscordClientS
ecret'
,
value
:
inputs
.
DiscordClientSecret
,
key
:
'
discord.client_s
ecret'
,
value
:
inputs
[
'discord.client_secret'
]
,
});
}
...
...
@@ -1040,10 +1040,10 @@ const SystemSetting = () => {
{
t
(
'允许通过 GitHub 账户登录 & 注册'
)
}
</
Form
.
Checkbox
>
<
Form
.
Checkbox
field=
'
DiscordOAuthE
nabled'
field=
'
discord.e
nabled'
noLabel
onChange=
{
(
e
)
=>
handleCheckboxChange
(
'
DiscordOAuthE
nabled'
,
e
)
handleCheckboxChange
(
'
discord.e
nabled'
,
e
)
}
>
{
t
(
'允许通过 Discord 账户登录 & 注册'
)
}
...
...
@@ -1457,13 +1457,13 @@ const SystemSetting = () => {
>
<
Col
xs=
{
24
}
sm=
{
24
}
md=
{
12
}
lg=
{
12
}
xl=
{
12
}
>
<
Form
.
Input
field=
'DiscordClientId'
field=
"['discord.client_id']"
label=
{
t
(
'Discord Client ID'
)
}
/>
</
Col
>
<
Col
xs=
{
24
}
sm=
{
24
}
md=
{
12
}
lg=
{
12
}
xl=
{
12
}
>
<
Form
.
Input
field=
'DiscordClientSecret'
field=
"['discord.client_secret']"
label=
{
t
(
'Discord Client Secret'
)
}
type=
'password'
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