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
368b060a
authored
Jul 15, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'main' of github.com:songquanpeng/one-api
parents
cd124373
caace6a2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
5 deletions
+30
-5
router/api-router.go
+4
-3
web/src/components/LoginForm.js
+26
-2
No files found.
router/api-router.go
View file @
368b060a
package
router
import
(
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
"one-api/controller"
"one-api/middleware"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
)
func
SetApiRouter
(
router
*
gin
.
Engine
)
{
...
...
@@ -27,7 +28,7 @@ func SetApiRouter(router *gin.Engine) {
userRoute
:=
apiRouter
.
Group
(
"/user"
)
{
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
.
GET
(
"/logout"
,
controller
.
Logout
)
selfRoute
:=
userRoute
.
Group
(
"/"
)
...
...
web/src/components/LoginForm.js
View file @
368b060a
...
...
@@ -12,7 +12,8 @@ import {
}
from
'semantic-ui-react'
;
import
{
Link
,
useNavigate
,
useSearchParams
}
from
'react-router-dom'
;
import
{
UserContext
}
from
'../context/User'
;
import
{
API
,
getLogo
,
showError
,
showSuccess
}
from
'../helpers'
;
import
{
API
,
getLogo
,
showError
,
showSuccess
,
showInfo
}
from
'../helpers'
;
import
Turnstile
from
'react-turnstile'
;
const
LoginForm
=
()
=>
{
const
[
inputs
,
setInputs
]
=
useState
({
...
...
@@ -24,6 +25,9 @@ const LoginForm = () => {
const
[
submitted
,
setSubmitted
]
=
useState
(
false
);
const
{
username
,
password
}
=
inputs
;
const
[
userState
,
userDispatch
]
=
useContext
(
UserContext
);
const
[
turnstileEnabled
,
setTurnstileEnabled
]
=
useState
(
false
);
const
[
turnstileSiteKey
,
setTurnstileSiteKey
]
=
useState
(
''
);
const
[
turnstileToken
,
setTurnstileToken
]
=
useState
(
''
);
let
navigate
=
useNavigate
();
const
[
status
,
setStatus
]
=
useState
({});
...
...
@@ -37,6 +41,11 @@ const LoginForm = () => {
if
(
status
)
{
status
=
JSON
.
parse
(
status
);
setStatus
(
status
);
if
(
status
.
turnstile_check
)
{
setTurnstileEnabled
(
true
);
setTurnstileSiteKey
(
status
.
turnstile_site_key
);
}
}
},
[]);
...
...
@@ -76,7 +85,12 @@ const LoginForm = () => {
async
function
handleSubmit
(
e
)
{
setSubmitted
(
true
);
if
(
username
&&
password
)
{
const
res
=
await
API
.
post
(
'/api/user/login'
,
{
if
(
turnstileEnabled
&&
turnstileToken
===
''
)
{
showInfo
(
'请稍后几秒重试,Turnstile 正在检查用户环境!'
);
return
;
}
const
res
=
await
API
.
post
(
`/api/user/login?turnstile=
${
turnstileToken
}
`
,
{
username
,
password
,
});
...
...
@@ -119,6 +133,16 @@ const LoginForm = () => {
value
=
{
password
}
onChange
=
{
handleChange
}
/
>
{
turnstileEnabled
?
(
<
Turnstile
sitekey
=
{
turnstileSiteKey
}
onVerify
=
{(
token
)
=>
{
setTurnstileToken
(
token
);
}}
/
>
)
:
(
<><
/
>
)}
<
Button
color
=
""
fluid
size
=
"large"
onClick
=
{
handleSubmit
}
>
登录
<
/Button
>
...
...
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