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
f0ba2fec
authored
Nov 06, 2023
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
登录支持人机验证
parent
37eff14e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
7 deletions
+34
-7
controller/misc.go
+0
-3
router/api-router.go
+1
-1
web/package.json
+1
-1
web/src/components/LoginForm.js
+28
-2
web/src/components/SystemSetting.js
+4
-0
No files found.
controller/misc.go
View file @
f0ba2fec
...
@@ -27,9 +27,6 @@ func GetStatus(c *gin.Context) {
...
@@ -27,9 +27,6 @@ func GetStatus(c *gin.Context) {
"wechat_qrcode"
:
common
.
WeChatAccountQRCodeImageURL
,
"wechat_qrcode"
:
common
.
WeChatAccountQRCodeImageURL
,
"wechat_login"
:
common
.
WeChatAuthEnabled
,
"wechat_login"
:
common
.
WeChatAuthEnabled
,
"server_address"
:
common
.
ServerAddress
,
"server_address"
:
common
.
ServerAddress
,
"pay_address"
:
common
.
PayAddress
,
"epay_id"
:
common
.
EpayId
,
"epay_key"
:
common
.
EpayKey
,
"price"
:
common
.
Price
,
"price"
:
common
.
Price
,
"turnstile_check"
:
common
.
TurnstileCheckEnabled
,
"turnstile_check"
:
common
.
TurnstileCheckEnabled
,
"turnstile_site_key"
:
common
.
TurnstileSiteKey
,
"turnstile_site_key"
:
common
.
TurnstileSiteKey
,
...
...
router/api-router.go
View file @
f0ba2fec
...
@@ -30,7 +30,7 @@ func SetApiRouter(router *gin.Engine) {
...
@@ -30,7 +30,7 @@ func SetApiRouter(router *gin.Engine) {
userRoute
:=
apiRouter
.
Group
(
"/user"
)
userRoute
:=
apiRouter
.
Group
(
"/user"
)
{
{
userRoute
.
POST
(
"/register"
,
middleware
.
CriticalRateLimit
(),
middleware
.
TurnstileCheck
(),
controller
.
Register
)
userRoute
.
POST
(
"/register"
,
middleware
.
CriticalRateLimit
(),
middleware
.
TurnstileCheck
(),
controller
.
Register
)
userRoute
.
POST
(
"/login"
,
middleware
.
CriticalRateLimit
(),
controller
.
Login
)
userRoute
.
POST
(
"/login"
,
middleware
.
CriticalRateLimit
(),
middleware
.
TurnstileCheck
(),
controller
.
Login
)
//userRoute.POST("/tokenlog", middleware.CriticalRateLimit(), controller.TokenLog)
//userRoute.POST("/tokenlog", middleware.CriticalRateLimit(), controller.TokenLog)
userRoute
.
GET
(
"/logout"
,
controller
.
Logout
)
userRoute
.
GET
(
"/logout"
,
controller
.
Logout
)
userRoute
.
GET
(
"/epay/notify"
,
controller
.
EpayNotify
)
userRoute
.
GET
(
"/epay/notify"
,
controller
.
EpayNotify
)
...
...
web/package.json
View file @
f0ba2fec
...
@@ -49,5 +49,5 @@
...
@@ -49,5 +49,5 @@
"singleQuote"
:
true
,
"singleQuote"
:
true
,
"jsxSingleQuote"
:
true
"jsxSingleQuote"
:
true
},
},
"proxy"
:
"http
s://nekoapi.com
"
"proxy"
:
"http
://localhost:3000
"
}
}
web/src/components/LoginForm.js
View file @
f0ba2fec
...
@@ -2,8 +2,9 @@ import React, { useContext, useEffect, useState } from 'react';
...
@@ -2,8 +2,9 @@ import React, { useContext, useEffect, useState } from 'react';
import
{
Button
,
Divider
,
Form
,
Grid
,
Header
,
Image
,
Message
,
Modal
,
Segment
}
from
'semantic-ui-react'
;
import
{
Button
,
Divider
,
Form
,
Grid
,
Header
,
Image
,
Message
,
Modal
,
Segment
}
from
'semantic-ui-react'
;
import
{
Link
,
useNavigate
,
useSearchParams
}
from
'react-router-dom'
;
import
{
Link
,
useNavigate
,
useSearchParams
}
from
'react-router-dom'
;
import
{
UserContext
}
from
'../context/User'
;
import
{
UserContext
}
from
'../context/User'
;
import
{
API
,
getLogo
,
showError
,
showSuccess
,
showWarning
}
from
'../helpers'
;
import
{
API
,
getLogo
,
showError
,
showInfo
,
showSuccess
,
showWarning
}
from
'../helpers'
;
import
{
onGitHubOAuthClicked
}
from
'./utils'
;
import
{
onGitHubOAuthClicked
}
from
'./utils'
;
import
Turnstile
from
"react-turnstile"
;
const
LoginForm
=
()
=>
{
const
LoginForm
=
()
=>
{
const
[
inputs
,
setInputs
]
=
useState
({
const
[
inputs
,
setInputs
]
=
useState
({
...
@@ -15,6 +16,9 @@ const LoginForm = () => {
...
@@ -15,6 +16,9 @@ const LoginForm = () => {
const
[
submitted
,
setSubmitted
]
=
useState
(
false
);
const
[
submitted
,
setSubmitted
]
=
useState
(
false
);
const
{
username
,
password
}
=
inputs
;
const
{
username
,
password
}
=
inputs
;
const
[
userState
,
userDispatch
]
=
useContext
(
UserContext
);
const
[
userState
,
userDispatch
]
=
useContext
(
UserContext
);
const
[
turnstileEnabled
,
setTurnstileEnabled
]
=
useState
(
false
);
const
[
turnstileSiteKey
,
setTurnstileSiteKey
]
=
useState
(
''
);
const
[
turnstileToken
,
setTurnstileToken
]
=
useState
(
''
);
let
navigate
=
useNavigate
();
let
navigate
=
useNavigate
();
const
[
status
,
setStatus
]
=
useState
({});
const
[
status
,
setStatus
]
=
useState
({});
const
logo
=
getLogo
();
const
logo
=
getLogo
();
...
@@ -27,6 +31,10 @@ const LoginForm = () => {
...
@@ -27,6 +31,10 @@ const LoginForm = () => {
if
(
status
)
{
if
(
status
)
{
status
=
JSON
.
parse
(
status
);
status
=
JSON
.
parse
(
status
);
setStatus
(
status
);
setStatus
(
status
);
if
(
status
.
turnstile_check
)
{
setTurnstileEnabled
(
true
);
setTurnstileSiteKey
(
status
.
turnstile_site_key
);
}
}
}
},
[]);
},
[]);
...
@@ -37,6 +45,10 @@ const LoginForm = () => {
...
@@ -37,6 +45,10 @@ const LoginForm = () => {
};
};
const
onSubmitWeChatVerificationCode
=
async
()
=>
{
const
onSubmitWeChatVerificationCode
=
async
()
=>
{
if
(
turnstileEnabled
&&
turnstileToken
===
''
)
{
showInfo
(
'请稍后几秒重试,Turnstile 正在检查用户环境!'
);
return
;
}
const
res
=
await
API
.
get
(
const
res
=
await
API
.
get
(
`/api/oauth/wechat?code=
${
inputs
.
wechat_verification_code
}
`
`/api/oauth/wechat?code=
${
inputs
.
wechat_verification_code
}
`
);
);
...
@@ -58,9 +70,13 @@ const LoginForm = () => {
...
@@ -58,9 +70,13 @@ const LoginForm = () => {
}
}
async
function
handleSubmit
(
e
)
{
async
function
handleSubmit
(
e
)
{
if
(
turnstileEnabled
&&
turnstileToken
===
''
)
{
showInfo
(
'请稍后几秒重试,Turnstile 正在检查用户环境!'
);
return
;
}
setSubmitted
(
true
);
setSubmitted
(
true
);
if
(
username
&&
password
)
{
if
(
username
&&
password
)
{
const
res
=
await
API
.
post
(
`/api/user/login`
,
{
const
res
=
await
API
.
post
(
`/api/user/login
?turnstile=
${
turnstileToken
}
`
,
{
username
,
username
,
password
password
});
});
...
@@ -109,6 +125,16 @@ const LoginForm = () => {
...
@@ -109,6 +125,16 @@ const LoginForm = () => {
value
=
{
password
}
value
=
{
password
}
onChange
=
{
handleChange
}
onChange
=
{
handleChange
}
/
>
/
>
{
turnstileEnabled
?
(
<
Turnstile
sitekey
=
{
turnstileSiteKey
}
onVerify
=
{(
token
)
=>
{
setTurnstileToken
(
token
);
}}
/
>
)
:
(
<><
/
>
)}
<
Button
color
=
'green'
fluid
size
=
'large'
onClick
=
{
handleSubmit
}
>
<
Button
color
=
'green'
fluid
size
=
'large'
onClick
=
{
handleSubmit
}
>
登录
登录
<
/Button
>
<
/Button
>
...
...
web/src/components/SystemSetting.js
View file @
f0ba2fec
...
@@ -155,8 +155,12 @@ const SystemSetting = () => {
...
@@ -155,8 +155,12 @@ const SystemSetting = () => {
}
}
let
PayAddress
=
removeTrailingSlash
(
inputs
.
PayAddress
);
let
PayAddress
=
removeTrailingSlash
(
inputs
.
PayAddress
);
await
updateOption
(
'PayAddress'
,
PayAddress
);
await
updateOption
(
'PayAddress'
,
PayAddress
);
if
(
inputs
.
EpayId
!==
''
)
{
await
updateOption
(
'EpayId'
,
inputs
.
EpayId
);
await
updateOption
(
'EpayId'
,
inputs
.
EpayId
);
}
if
(
inputs
.
EpayKey
!==
''
)
{
await
updateOption
(
'EpayKey'
,
inputs
.
EpayKey
);
await
updateOption
(
'EpayKey'
,
inputs
.
EpayKey
);
}
await
updateOption
(
'Price'
,
""
+
inputs
.
Price
);
await
updateOption
(
'Price'
,
""
+
inputs
.
Price
);
};
};
...
...
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